Skip to main content
gamedev.net
🔒 Locked

Resizing window

Started by DrunkenBrit Oct 5, 2006 at 3:34 AM 1 replies 600+ views
Original Post
DrunkenBrit
DrunkenBrit
Hey, im having trouble trying to get a simple quad to resize when i resize the window, ive got it working but it works when afaik it shouldn't work... glViewport(0, 0, width, height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0, width, 0, height ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); The code above doesnt work... BUT this does... glViewport(0, 0, width, height); gluOrtho2D( 0, width, 0, height ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); Im sure im ment to select the GL_PROJECTION matrix stack before calling gluOrtho2D? Explanations please? Thanks:)
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
haegarr
haegarr
AFAIK gluOrtho2D invokes directly glOrtho, and glOrtho assembles a projection matrix and multiplies it with the top of the _current_ matrix stack. So yes, you have to activate GL_PROJECTION before calling gluOrtho2D to use it correctly.

OpenGL uses the projection and viewport roughly this way: A length in world space is normalized by dividing by the projection plane's size. That normalized space is then scaled to the viewport size for actually rendering pixels. Obviously, if both sizes are altered so that the quotient isn't changed, then the world length is rendered onto the same screen length. E.g. for a viewport width of p pixels and a projection plane width of w, a horizontal world space length l gets
l' := l / w * p

So, your 1st code snippet works well, although not in the sense you've expected! If you want the behaviour of fitting, you have to adapt the viewport to the window size but let the projection fixed. Then w remains the same but p increases (decreases) letting l' increase (decrease) proportionally.


EDIT: One normally set the viewport and orthographic projection you did for getting a pixelwise rendering. That is, one length unit in world is mapped to one pixel on screen. This obviously _requires_ the behaviour that resizing the window doesn't change the quad's rendered size.
V-man
V-man
It will work if yo supply constant values

gluOrtho2D( 0, 500, 0, 500 );

What explanation? It's just math. Look at the red book or some online giude how vertices are transformed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.