[SDL] Changing the Screen Size at Runtime

Michael Wyrzykowski wyrzy at juno.com
Wed Jan 12 08:31:21 PST 2005

On Tue, 2005-01-11 at 19:11 +0000, Michael Wyrzykowski wrote:
> > > The SDL_VIDEORESIZE event doesn't do anything by itself. SDL does not
> > > take any action when it sees that event or when it generates that event.
> > > The event is there to tell you that the window has changed size. Your
> > > code is responsible for actually changing the displayable size of the
> > > window. What does your code do to handle the event? It should be calling
> > > SDL_SetVideoMode() to make the SDL surface match the new window size,
> > > and then (on Windows) reloading all your textures and probably
> > > recreating your OpenGL context. 
> > >
> > > If your code is not handling the SDL_VIDEORESIZE event then your        > > program is not doing the right things when the window changes size. 
> > >
> > > 		Bob Pendleton
> > I am handling the SDL_VIDEORESIZE event like:
> > ------
> > if(event.type == SDL_VIDEORESIZE)
> > {
> >     int width = event.resize.w;
> >     int height = event.resize.h;
> >     float scale_width = float(width)/800; //game logic set for
> >     float scale_height = float(height)/600;// 800x600 resolution
> > 
> >     glViewport( 0, 0, width, height);
> >     glMatrixMode(GL_PROJECTION);
> >     glLoadIdentity();
> >     glOrtho( 0, width, height, 0, -1, 1);
> >     glMatrixMode(GL_MODELVIEW);
> >     glLoadIdentity();
> >     glScalef( scale_width, scale_height, 1.0f );
> > }

> Yeah, you really are supposed to call SDL_SetVideoMode to make the SDL
> view of the window match the windowing systems view of the window.    > What happens when you make the window larger than the original window?
> 		Bob Pendleton
When I make the window larger my using the mouse, the call to glScalef() simply scales everything that it draws so that whatever size the window is, then images will be scaled appropriately to fit. Nothing is cut off. For example, the size of my background image is 800x600 (also the default size to the window). If the user changes the window size with the mouse to 400x600, then glScalef() will be called to scale all images by 0.5 on the x-axis, 1.0 on the y-axis, and 1.0 on the z-axis.

When resizing the window with the mouse, I do not need to reload in any textures, and everything displays properly. However, I wanted to be able to specify the sizes the user could choose, so the graphics do not looked distorted from changing a 800x600 window to something like 600x800 (making all graphics look taller and less wide).

I'm thinking that the proper thing to do would be to actually call SetVideoMode again to request the correct resolution. It may be that I am developing a laptop that I did not notice any difference (an LCD display  scales images because it only has one true resolution).

Speed up your surfing with Juno SpeedBand.
Now includes pop-up blocker!
Only $14.95/month -visit http://www.juno.com/surf to sign up today!

More information about the SDL mailing list