# glOrtho far and near flipped?

This topic is 4405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I always assumed that 0.0f would be nearest in z-order when using glOrtho(0, width, height, 0, -1, 1); However in order to draw anything on top, a z value of 1.0 has to be passed. Switching those ortho values in my program gives me the opposite effect, where 0.0 is nearest in z-order and 1.0 is farthest. This was the solution to a bitmap problem I had, but my question is. Am I missing something? Here's the code I use to setup projections.
bool RendererOGL::SetProjection(DWORD flag, DWORD width, DWORD height, float fov)
{
glMatrixMode(GL_PROJECTION);

if(!width || !height){
width = deviceParam.wndWidth;
height = deviceParam.wndHeight;
}

if(flag == PROJ_PERSPECTIVE)
gluPerspective(fov, (GLfloat)width/(GLfloat)height, 0.1f, 1000.0f);
else if(flag == PROJ_ORTHO)
glOrtho(0, width, height, 0, 1, -1); // changed
//		gluOrtho2D(0, width, height, 0);
else return false;

glMatrixMode(GL_MODELVIEW);
return true;
}



##### Share on other sites
Your problem is not the near and far plane, it is your top bottom.

glOrtho( left, right, bottom, top, znear, zfar );

So your code shoud be

glOrtho(0, width, 0, height, -1, 1); // changed

##### Share on other sites
The problem with that is that as it is right now (0, 0) is the top left corner, if I flip those two values then all my verts would have to be negative in their y values in order to be shown, or I would have to do a translate afterwards.

##### Share on other sites
The zNear and zFar parameters specify how many units from the "camera" the near and far clip planes are, respectively. So with a zNear of -1.0 and a zFar of 1.0, the near plane is one unit behind the "camera" and the far plane is one unit in front of the "camera." In the default OpenGL coordinate system (in which the positive z-axis comes out of the screen) one unit behind the "camera" corresponds to a z-value of 1.0 (since positive z points out of the screen but the "camera" is looking into the screen, ie: down the negative z-axis) whereas one unit in front of the "camera" corresponds to a z-value of -1.0.

##### Share on other sites
Yeah, I understand that.
I just don't see why glOrtho doesn't do a vertical translation as opposed to a rotation along the x axis. Because of this, my Y UV coords have to be negative as it flips the camera in the opposite direction.

##### Share on other sites
Quote:
 Original post by PumpkinPiemanThe problem with that is that as it is right now (0, 0) is the top left corner, if I flip those two values then all my verts would have to be negative in their y values in order to be shown, or I would have to do a translate afterwards.

I'm not sure this is true, I believe you vertices would still be good, although your texture might show upside down. I know glSDL used an inverted orthographic projection like you do so that it flips the image (instead of doing it on the Surface directly).

Cheers,

##### Share on other sites
Hmm, I'm not sure I understand what the problem is. Your original post talked about the near and far planes and vertex positions, but now you're talking about the bottom and top planes and texture coordinates? Could you clarify what exactly is wrong?

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 14
• ### Forum Statistics

• Total Topics
632155
• Total Posts
3004477

×