Jump to content
  • Advertisement
Sign in to follow this  
Silvo

OpenGL Simple OpenGL Setup Sequence Oddity

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

G'day! I am wondering why this works:
	glEnable(GL_TEXTURE_2D);
	glClearColor(0, 0, 0, 1);
	glMatrixMode(GL_PROJECTION);
	glOrtho(0, 100, 100, 0, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
But this doesn't:
	glEnable(GL_TEXTURE_2D);
	glMatrixMode(GL_PROJECTION);
	glMatrixMode(GL_MODELVIEW);
	glClearColor(0, 0, 0, 1);
	glOrtho(0, 100, 100, 0, -1, 1);
	glLoadIdentity();
I am drawing white boxes, and using the latter causes them to not appear. Why is this so?

Share this post


Link to post
Share on other sites
Advertisement
In the first example, the projection matrix is set to an orthographic projection with range [0, 100] on X and Y axis, and the modelview matrix is the identity matrix.

The second example leaves the projection matrix untouched, and sets the modelview matrix to the same orthographic projection matrix as above but then immediately resets it to the identity matrix.

All matrix operations modifies the active matrix stack. So in the second example, the orthographic projection matrix ends up in the modelview matrix stack.

Share this post


Link to post
Share on other sites
Ohhhhhhhh.....

Thank you so much. I get it now. I had a strange misconception that by calling glMatrixMode() I was doing something like "enabling" the matrix... So, by calling glMatrixMode(), I am setting which matrix I will affecting when I use functions like glOrtho() and glLoadIdentity(), right?

Thanks for that!

Share this post


Link to post
Share on other sites
Yes, OpenGL is designed as a state machine.

You set modes and those modes stay set until they are changed.

Like if you bind a texture, that texture will stay bound until another texture is bound or textures are disabled. It is the same with Matrices, you set the mode, do your stuff, and set another mode.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!