Skip to main content
gamedev.net
🔒 Locked

Resize Scene Function, stretching?

Started by justinwalsh May 5, 2004 at 11:35 AM 2 replies 600+ views
Original Post
justinwalsh
justinwalsh
OK, i have done this in the past by accident. I am primarily interested in drawing to the screen in ortho mode. I have done this. One time i made an application, lost the source, that when you resized the window, everything was stretched to fit the new window size, it didnt mess anything up. As of now, when i resize my windows they mess up the location of everything. make since? I was looking for a way to get the resize effect that my old app had, just no clue how i actually did it, very new to OpenGL. TIA
urayami
urayami
I'm fairly new to OpenGL as well, but as far as I know, you simply have to change the viewport and adjust your projection matrices to resize the window properly. The viewport tells OpenGL how to convert the unitless (-10.0, 2.5, -16.0) etc. into pixel coordinates and it also has the pixel-defined boundaries as well. Example:
glViewport (0.0f, 0.0f, 800, 600) ;
That would set the lower left corner of your viewport to (0, 0) and the viewport would have a width of 800 pixels and a height of 600 pixels. If your window was resized to 820, 610, you would call some resize function such as this:

void Resize (int width, int height)
{
glViewport (0, 0, (GLsizei) width, (GLsizei) height) ;
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity () ;
gluPerspective (...) ;
glMatrixMode (GL_MODELVIEW) ;
}

That function would properly resize the scene for a perspective view when the user resized the window. For orthographic projection, you just want to replace the gluPerspective call with a glOrtho or gluOrtho2D call. You call glMatrixMode with GL_PROJECTION to tell OpenGL that you're going to mess with the projection matrix stack to setup the projection - perspective, ortho, etc. Since the view is changing, the projection matrices need to be adjusted as well to accomodate the new view. After you have setup your projection, you call glMatrixMode with GL_MODELVIEW so that you're working with the modelview matrix stack and can then do subsequent transformations (translations, rotations, etc.). Hope this helps!

~Urayami

[edited by - urayami on May 5, 2004 2:56:10 PM]
~Urayami
Venerable Vampire
Venerable Vampire
What he said. Set the viewport to 0,0 and the width,height of the window. Then use ortho (you said ortho right?) to 0,1,0,1,-1,1 for a range of possible values of 0 to 1 on the x and y axis and the z doesn''t matter for 2d ortho. When drawing place objects between 0 and 1 and they will stretch perfectly no matter what the size is.

Life would be so much easier if we could just get the source code.
--------------------------------------------------------Life would be so much easier if we could just get the source code.
justinwalsh
justinwalsh
I feel dumb, now.

I went back and looked at my code, well the reason it wasn''t working was because i wass passing the window creation size to my function, not the actual window size.

Thanks for the help.

Topic Locked

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

Sign in to reply to this topic.