PDA

View Full Version : Trouble with glOrtho ...



V66ras
08-30-2002, 09:39 AM
hi!

I constantly fail to create orthogonal
projection where i could reference all
screen points with integer numbers...

was this clear enough ...
more specific :
a example code that produces a error...



/.../
glViewport(0,0,W,H); glMatrixModeGL_PROJECTION);
glLoadIdentity();
glOrtho(0,W,H,0,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/.../
glClearColor(0.0f,0.5f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
/.../
glColor3ub(0,0,255);
glBegin(GL_LINES);
for(int i=0;i<W;i++) {
glVertex2i(i,0);
glVertex2i(i,H-1); }
glEnd();
/.../


well. Now should the entire screen be blue,
but it is NOT. (green line in middle of screen)

How to get that working ?
Is it even possible in oGL? (ie. is oGL precise enough)

Jambolo
08-30-2002, 11:41 AM
According to the Red Book...

If you use glOrtho( 0, w, 0, h, -1, 1 ) then the center of the pixel (i,j) is at (i +.5, j+.5). If you want to use integer coordinates, you should do glTranslatef(.375, .375, 0. ) immediately after the glLoadIdentity().
The reason for .375 and not .5 is that some functions don't operate on pixel centers, and .375 is a compromise to keep the coordinates consistent.