strattonbrazil
11-22-2011, 07:24 PM
I don't know why glOrtho is giving me so much trouble. I'm assuming this is something really simple I'm missing like a typo or something. I have a 3D world position I'm projecting onto the screen with gluProject. I get reasonable values (ex. (354,423,0.9)).
I noticed though that I can't get this to render using the zNear and zFar I'd expect for glOrtho.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width(), 0, height(),0,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
With 0 to 1, I don't see anything rendered, which I don't understand. I figured since all my z-values range from 0 to 1 from gluProject, I should set glOrtho to the same range. -1 to 1 and -1 to 0 both work as ranges to get my points onto the screen, but I'm just confused why glOrtho with a zNear and zFar of 0 to 1 won't work if all my z values are around 0.9. I've double checked and depth testing is disabled.
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex3f(screen.x()-ICON_OFFSET, screen.y()-ICON_OFFSET, screen.z());
glTexCoord2f(1, 0);
glVertex3f(screen.x()+ICON_OFFSET, screen.y()-ICON_OFFSET, screen.z());
glTexCoord2f(1, 1);
glVertex3f(screen.x()+ICON_OFFSET, screen.y()+ICON_OFFSET, screen.z());
glTexCoord2f(0, 1);
glVertex3f(screen.x()-ICON_OFFSET, screen.y()+ICON_OFFSET, screen.z());
}
glEnd();
I noticed though that I can't get this to render using the zNear and zFar I'd expect for glOrtho.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width(), 0, height(),0,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
With 0 to 1, I don't see anything rendered, which I don't understand. I figured since all my z-values range from 0 to 1 from gluProject, I should set glOrtho to the same range. -1 to 1 and -1 to 0 both work as ranges to get my points onto the screen, but I'm just confused why glOrtho with a zNear and zFar of 0 to 1 won't work if all my z values are around 0.9. I've double checked and depth testing is disabled.
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex3f(screen.x()-ICON_OFFSET, screen.y()-ICON_OFFSET, screen.z());
glTexCoord2f(1, 0);
glVertex3f(screen.x()+ICON_OFFSET, screen.y()-ICON_OFFSET, screen.z());
glTexCoord2f(1, 1);
glVertex3f(screen.x()+ICON_OFFSET, screen.y()+ICON_OFFSET, screen.z());
glTexCoord2f(0, 1);
glVertex3f(screen.x()-ICON_OFFSET, screen.y()+ICON_OFFSET, screen.z());
}
glEnd();