## drawing objects in openGL, plane question.

xDexx
Unregistered

Post: #1
i have this code:
Code:
glVertex3i(-x, -x, 0);
glVertex3i( x, -x, 0);
glVertex3i(x,x, 0);
glVertex3i(-x,x, 0);
glEnd();

my window is set to a size of 640,480. if i set x = 10 the whole screen will be white. why does it only 20 pixels accross? i have heard that with opengl that i do not work with resolutions or something. whats the deal with this? thanks!
Unregistered

Post: #2
You're specifying the position of a quad in 3d space. What it looks like depends on where the camera is in that space; it starts off at 0,0,0 looking down some axis I can't presently recall, but you can move it. Read the first couple of chapters of the OpenGL Redbook - you can find an old version at http://www.gamedev.net/reference/list.asp?categoryid=31 somewhere at the bottom.
Mars_999
Unregistered

Post: #3
First off. reason why its 20 is -10 to +10 on the number line is a total of 20. Reason why you probably have white on the screen, without looking at code, is you are in Perspective mode and not Ortho mode. Perspective is going to take small values. If you setup a screen lets say 1024x768 and make a quad of 3x3 the screen is going to have a very large quad, not the whole screen but a good portion of it. Now if you use Ortho a 3x3 is pretty small. Ortho is going to map screen coordinates to the size of your quad. e.g. a quad of 128x128 is 128x128 on a screen of 1024x768. Perspective is what you're referring to when OpenGL doesn't use screen coordinates and makes objects smaller as they move away from you accordingly where as Ortho is not going to take into account for distance. HTH
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
scale is entirely independent of projection, though pixel-perfect is a common ortho projection.

The default projection (if you haven't changed it) is ortho, -1 to 1 on each axis (so the coordinates of the window corners are -1,-1 -1,1 1,1 and 1,-1 and changing z will have no visible effect).
xDexx
Unregistered

Post: #5
i have been using the template for GLUT that was posted on one of the other threads. here it is:
Code:
#include <GLUT/glut.h>

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

int main(int argc, char* argv[])
{
int window;

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);

window = glutCreateWindow("Test");
glutSetWindow(window);

glOrtho(-10, 10, -10, 10, -10, 10);

glClearColor(0, 0, 0, 1);

glutDisplayFunc(display);

glutMainLoop();
return 0;
}
i did change some of the code to try and get 640x480, it doesnt seem to work, any ideas?
Code:
int window;

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(640,480);

window = glutCreateWindow("Test");

glutSetWindow(window);

glOrtho(0, 640, 480, 0, 0, 0);
Mars_999
Unregistered

Post: #6
ah you have your near and far planes set to zero both. That isnt' going to do you much good. try -1.0 and 1.0, or just use gluOrtho2D()
xDexx
Unregistered

Post: #7
oh hel ya! it works! thanks!
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
You always want GLUT_DOUBLE rather than GLUT_SINGLE, that way you avoid flickering, and it's certainly no penalty for doing so.