user1796942
user1796942

Reputation: 3528

How to write resize function in opengl given that glMatrixMode is deprecated?

How to write resize function in opengl given that glMatrixMode is deprecated?

In my old resize function I use glMatrixMode(GL_PROJECTION) and glMatrixMode(GL_MODELVIEW), but now that the fixed pipeline is replaced, I am not sure how the resize function should look like?

Upvotes: 0

Views: 488

Answers (1)

datenwolf
datenwolf

Reputation: 162327

In my old resize function I use glMatrixMode(GL_PROJECTION) and glMatrixMode(GL_MODELVIEW)

You should never have done that in the first place.

now that the fixed pipeline is replaced, I am not sure how the resize function should look like?

Just like it should be with the fixed function pipeline: Set some variables reflecting the new window size and trigger a redraw. Don't call any OpenGL functions at all in event handlers!

In the display function, given the size of the window you determine the extents of the viewport and derive your projection matrix from that. Fixed function OpenGL provided you functions glOrtho and glFrustum (on which GLU built it's gluOrtho2D and gluPerspective). Now, instead of messing with matrix state, you build your desired matrices in a matrix variable you manage (and you can keep around, without having it to rebuild it from scratch every new display iteration). That matrix variable you pass to OpenGL with glUniformMatrix.

Upvotes: 2

Related Questions