# clipping plane glOrtho

## Recommended Posts

Why is the planet still drawn in this example? (planet is drawn in last block of code, glOrtho is called near the beginning.):
void FPSDemo::drawSpace()
{
mRotation+= mDeltaTime / 2000;

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glOrtho(0.0f, mWidth, mHeight, 0.0f, 1.0f, 0.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mStarsTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glColor3f(1.0f,1.0f,1.0f);
glTexCoord2f(1.0f, 0.0f);    glVertex3f(mWidth,0.0f,0.0f);
glTexCoord2f(0.0f, 0.0f);    glVertex3f(0.0f,0.0f,0.0f);
glTexCoord2f(0.0f, 1.0f);    glVertex3f(0.0f,mHeight,0.0f);
glTexCoord2f(1.0f, 1.0f);    glVertex3f(mWidth,mHeight,0.0f);
glEnd();

glPopMatrix();

glMatrixMode(GL_MODELVIEW);

glPushMatrix();
glTranslatef(0.0,0.0,-5.0);
glRotatef(90,0.0, 1.0, 0.0);
glRotatef(mRotation*39,0.0, 1.0, 0.0);
glRotatef(90,1.0, 0.0, 0.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mPlanetTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}


The clipping planes are from 1.0 to 0.0 in glOrtho. The planet is drawn at 5.0, that's 4.0 past the near clipping plane. (Or taking the radius into account the near side of the planet ranges from 4.0 to 3.0 past the near clipping plane.) Right? And why is the planet warped to whatever aspect ratio my window is using? Why isn't it a sphere?

##### Share on other sites
Lord_Evil    680
What values do mWidth and mHeight contain?

If they contain the same value you'll render the planet to a square region and would be distorted if that region is mapped to a non-square render target.

Note that the projection matrix is applied to objects in eye space (i.e. relative to the "camera"), so if your planet is located at (0,0,5) and your camera is located at (0,0,4) the distance to the camera is 1.0.

##### Share on other sites
Camera is at 0,0,0. Nevermind glOrtho, I don't know what I was talking about. All I'm worried about now is the warped planet. mWidth is 1024 and mHeight is 768. I don't see why the planet is egg shaped.

##### Share on other sites
Oh in gluPerspective I was doing mWidth/mHeight but that was integer division. Duh, sorry.

Hey that's straight from the guichan fps demo. They're doing integer division. Their planet is all egg shaped because of the aspect ratio, you just can't tell because their planet is mostly off screen.