# Changing the Screen Size at Runtime

**URL:** <https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732>\
**Category:** SDL Development\
**Created:** [January 11, 2005, 4:54am UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732 "2005-01-11T04:54:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Wyrzykowski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@Michael\_Wyrzykowski](https://discourse.libsdl.org/u/Michael_Wyrzykowski)\
**Post date:** [January 11, 2005, 4:54am UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/1 "2005-01-11T04:54:11Z")

</div>

Hello,

I am using SDL w/ OpenGL for rendering, and I was wondering if there is any way to change the resolution by code without needing to re-load in all currently loaded textures?

## I have tried pushing my own event onto the event queue like:----- SDL\_Event custom\_event; custom\_event.resize.h = new\_height; //\<–the height to set the window at custom\_event.resize.w = new\_width; //\<–the width to set the window at custom\_event.type = SDL\_VIDEORESIZE; custom\_event.resize.type = SDL\_VIDEORESIZE; if(-1==SDL\_PushEvent(&custom\_event)) printf(“SDL\_PushEvent Error: %s”, SDL\_GetError);

but I receive no error message so I assume the event was pushed properly.

When I resize the window with the mouse pointer by dragging the edges of the window, the screen is resized properly when I look for an SDL\_VIDEORESIZE event. However, when I go to retreive the SDL\_VIDEORESIZE after running the above code, the window does not change dimensions. I want people who will play the game to be able to pick standard resolutions (1024x768, 800x600, 640x480,…), so I don’t really want to rely on them resizing the screen with the mouse pointer.

I realize that I can call SDL\_SetVideoMode again, but then I also need to re-load in all my textures or I end up with a black screen. This is what I’m doing now, but it takes a few seconds to load in all the currently loaded images, set the color keys… which I would like avoid if possible.

Does anyone know if I am allowed to trigger a SDL\_VIDEORESIZE event by pushing it onto the event queue? Thank you for any help and/or suggestions you can give 🙂

Btw, I’m running on a Windows box.

* * *

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

---

<div class="post-metadata">

**Author:** ![Drake\_Wilson](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@Drake\_Wilson](https://discourse.libsdl.org/u/Drake_Wilson)\
**Post date:** [January 11, 2005, 5:17am UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/2 "2005-01-11T05:17:38Z")

</div>

Quoth Michael Wyrzykowski , on 2005-01-11 04:54:11 +0000:

> Hello,
> 
> I am using SDL w/ OpenGL for rendering, and I was wondering if there is any way to change the resolution by code without needing to re-load in all currently loaded textures?

Short answer: not reliably.

Previous threads about this include:  
[http://twomix.devolution.com/pipermail/sdl/2004-September/064870.html](http://twomix.devolution.com/pipermail/sdl/2004-September/064870.html)  
[http://twomix.devolution.com/pipermail/sdl/2004-November/065847.html](http://twomix.devolution.com/pipermail/sdl/2004-November/065847.html)

—\> Drake Wilson  
-------------- next part --------------  
A non-text attachment was scrubbed…  
Name: not available  
Type: application/pgp-signature  
Size: 189 bytes  
Desc: Digital signature  
URL: [http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050111/45595d9c/attachment.pgp](http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050111/45595d9c/attachment.pgp)

---

<div class="post-metadata">

**Author:** ![Michael\_Wyrzykowski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@Michael\_Wyrzykowski](https://discourse.libsdl.org/u/Michael_Wyrzykowski)\
**Post date:** [January 11, 2005, 1:29pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/3 "2005-01-11T13:29:15Z")

</div>

> Short answer: not reliably.
> 
> Previous threads about this include:  
> [http://twomix.devolution.com/pipermail/sdl/2004-September/064870.html](http://twomix.devolution.com/pipermail/sdl/2004-September/064870.html)  
> [http://twomix.devolution.com/pipermail/sdl/2004-November/065847.html](http://twomix.devolution.com/pipermail/sdl/2004-November/065847.html)

I looked over the threads, but I still had one question. Maybe its not exactly changing the resolution, but more like “changing the window size”. I can do this by using the mouse to resize the window, but I was wondering if I could manually push an event to accomplish the same thing. There is no need to reload the textures when I just change the window size with the mouse, and I was wondering if anyone knew how to specify this with code, as pushing an event of type SDL\_VIDEORESIZE did not change the window size.\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Speed up your surfing with Juno SpeedBand.  
Now includes pop-up blocker!  
Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!

---

<div class="post-metadata">

**Author:** ![Bob\_Pendleton](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@Bob\_Pendleton](https://discourse.libsdl.org/u/Bob_Pendleton)\
**Post date:** [January 11, 2005, 3:04pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/4 "2005-01-11T15:04:06Z")

</div>

> > Short answer: not reliably.
> > 
> > Previous threads about this include:  
> > [http://twomix.devolution.com/pipermail/sdl/2004-September/064870.html](http://twomix.devolution.com/pipermail/sdl/2004-September/064870.html)  
> > [http://twomix.devolution.com/pipermail/sdl/2004-November/065847.html](http://twomix.devolution.com/pipermail/sdl/2004-November/065847.html)
> 
> I looked over the threads, but I still had one question. Maybe its not exactly changing the resolution, but more like “changing the window size”. I can do this by using the mouse to resize the window, but I was wondering if I could manually push an event to accomplish the same thing. There is no need to reload the textures when I just change the window size with the mouse, and I was wondering if anyone knew how to specify this with code, as pushing an event of type SDL\_VIDEORESIZE did not change the window size.

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 PendletonOn Tue, 2005-01-11 at 13:29 +0000, Michael Wyrzykowski wrote:

```

> * * *
> 
> Speed up your surfing with Juno SpeedBand.  
> Now includes pop-up blocker!  
> Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Michael\_Wyrzykowski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@Michael\_Wyrzykowski](https://discourse.libsdl.org/u/Michael_Wyrzykowski)\
**Post date:** [January 11, 2005, 7:11pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/5 "2005-01-11T19:11:43Z")

</div>

> 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 );

```

## }

The above code works correctly when the mouse resizes the window without the need to call SDL\_SetVideoMode() again. The result is basically the 800x600 screen is being projected over a larger or smaller area of pixels.

However, now that I am thinking of it, resizing the window is probably a windows-specfic item - or am I wrong? Does anyone know of a way to simulate the mouse resizing the window with SDL? I would assume that this is a windows specific item that SDL passes to the OS.

* * *

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

---

<div class="post-metadata">

**Author:** ![Bob\_Pendleton](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@Bob\_Pendleton](https://discourse.libsdl.org/u/Bob_Pendleton)\
**Post date:** [January 12, 2005, 4:32am UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/6 "2005-01-12T04:32:32Z")

</div>

> > 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 PendletonOn Tue, 2005-01-11 at 19:11 +0000, Michael Wyrzykowski wrote:

```

> * * *
> 
> The above code works correctly when the mouse resizes the window without the need to call SDL\_SetVideoMode() again. The result is basically the 800x600 screen is being projected over a larger or smaller area of pixels.
> 
> However, now that I am thinking of it, resizing the window is probably a windows-specfic item - or am I wrong? Does anyone know of a way to simulate the mouse resizing the window with SDL? I would assume that this is a windows specific item that SDL passes to the OS.
> 
> * * *
> 
> Speed up your surfing with Juno SpeedBand.  
> Now includes pop-up blocker!  
> Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Michael\_Wyrzykowski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@Michael\_Wyrzykowski](https://discourse.libsdl.org/u/Michael_Wyrzykowski)\
**Post date:** [January 12, 2005, 4:31pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/7 "2005-01-12T16:31:21Z")

</div>

> > > 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).On Tue, 2005-01-11 at 19:11 +0000, Michael Wyrzykowski wrote:

* * *

Speed up your surfing with Juno SpeedBand.  
Now includes pop-up blocker!  
Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!

---

<div class="post-metadata">

**Author:** ![Samuel\_E\_Bray](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/8491ac/32.png) [@Samuel\_E\_Bray](https://discourse.libsdl.org/u/Samuel_E_Bray)\
**Post date:** [January 12, 2005, 10:25pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/8 "2005-01-12T22:25:30Z")

</div>

Here’s how I usually do it.

First setup SetGLWindow()

void SetGLWindow(int width, int height)  
{  
GLfloat ratio;

if(height == 0)  
height = 1;

ratio = (GLfloat)width/(GLfloat)height;

glViewport(0, 0, (GLint)width, (GLint)height);

glMatrixMode(GL\_PROJECTION);  
glLoadIdentity();

gluPerspective(45.0f, ratio, 0.1f, 100.0f);

glMatrixMode(GL\_MODELVIEW);  
glLoadIdentity();

}

Then I wait for a resize event in my main loop

while(!done)  
{  
while(SDL\_PollEvent(&event))  
{  
switch(event.type)  
{  
case SDL\_ACTIVEEVENT:  
if(event.active.gain == 0)  
isActive = FALSE;  
else  
isActive = TRUE;  
break;  
case SDL\_VIDEORESIZE:  
if((surface = SDL\_SetVideoMode(event.resize.w,  
event.resize.h,  
SCREEN\_BPP,  
videoFlags)) == NULL)  
{  
fprintf(stderr,“Unable to grab surface after resize event:  
%s\n”,SDL\_GetError());  
Quit(1);  
}  
SetGLWindow(event.resize.w, event.resize.h);  
break;  
case SDL\_KEYDOWN:  
HandleKeyDown(&event.key.keysym);  
break;  
case SDL\_QUIT:  
done = TRUE;  
break;  
default:  
break;  
}  
}  
if(isActive)  
DrawScreen();  
}

\*\*\*\* – Below is the full example program. More examples can be found on

> **[NeHe Productions - Everything OpenGL](http://nehe.gamedev.net)**
>
> OpenGL Tutorials, Demos, Games and More...

/\*\*\*\*\* Begin Code Paste \*\*\*\*\*/

/\* build with:

- gcc -ggdb -Wall -L/usr/X11R6/lib -lGL -lGLU `sdl-config --cflags --libs`  
sdl-gl-18.c -o sdl-gl-18  
\*/

#include \<stdio.h\>  
#include \<stdlib.h\>  
#include \<GL/gl.h\>  
#include \<GL/glu.h\>  
#include \<SDL/SDL.h\>

#define SCREEN\_WIDTH 640  
#define SCREEN\_HEIGHT 480  
#define SCREEN\_BPP 32

#define TRUE 1  
#define FALSE 0

SDL\_Surface \*surface;

int light = FALSE;

GLdouble part1, part2;  
GLdouble p1 = 0;  
GLdouble p2 = 1;

GLfloat xRot, yRot, ySpeed, xSpeed;  
GLfloat z = -5.0f;

GLfloat ambientLight = {0.5f, 0.5f, 0.5f, 1.0f };  
GLfloat diffusedLight = {1.0f, 1.0f, 1.0f, 1.0f};  
GLfloat lightPosition = {0.0f, 0.0f, 2.0f, 1.0f};

GLUquadricObj \*quadric;  
GLuint object = 0;

GLuint filter;  
GLuint texture[3];

void Quit(int returnCode)  
{  
gluDeleteQuadric(quadric);  
glDeleteTextures(3, texture);

SDL\_Quit();

if(returnCode != 42)  
exit(returnCode);  
}

int LoadTextures()  
{  
int status = FALSE;

SDL\_Surface \*textureImage;

if((textureImage=SDL\_LoadBMP(“q\_tex.bmp”)))  
{  
status = TRUE;

```
  glGenTextures(3, texture);

  glBindTexture(GL_TEXTURE_2D, texture[0]);
  glTexImage2D(GL_TEXTURE_2D,
      0,
      3,
      textureImage->w,
      textureImage->h,
      0,
      GL_BGR,
      GL_UNSIGNED_BYTE,
      textureImage->pixels);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  glBindTexture(GL_TEXTURE_2D, texture[1]);
  glTexImage2D(GL_TEXTURE_2D,
      0,
      3,
      textureImage->w,
      textureImage->h,
      0,
      GL_BGR,
      GL_UNSIGNED_BYTE,
      textureImage->pixels);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  glBindTexture(GL_TEXTURE_2D, texture[2]);
  gluBuild2DMipmaps(GL_TEXTURE_2D,
        3,
        textureImage->w,
        textureImage->h,
        GL_BGR,
        GL_UNSIGNED_BYTE,
        textureImage->pixels);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 

```

GL\_LINEAR\_MIPMAP\_NEAREST);  
glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_LINEAR);

```
  SDL_FreeSurface(textureImage);
}

```

return status;  
}

int InitGL(void)  
{  
if(!LoadTextures())  
return FALSE;

glEnable(GL\_TEXTURE\_2D);  
glShadeModel(GL\_SMOOTH);  
glClearColor(0.0, 0.0, 0.0, 0.0);  
glClearDepth(1.0);  
glEnable(GL\_DEPTH\_TEST);  
glDepthFunc(GL\_LEQUAL);  
glHint(GL\_PERSPECTIVE\_CORRECTION\_HINT, GL\_NICEST);

glLightfv(GL\_LIGHT0, GL\_AMBIENT, ambientLight);  
glLightfv(GL\_LIGHT0, GL\_DIFFUSE, diffusedLight);  
glLightfv(GL\_LIGHT0, GL\_POSITION, lightPosition);  
glEnable(GL\_LIGHT0);

quadric = gluNewQuadric();  
gluQuadricNormals(quadric, GLU\_SMOOTH);  
gluQuadricTexture(quadric, GL\_TRUE);

return TRUE;  
}

void SetGLWindow(int width, int height)  
{  
GLfloat ratio;

if(height == 0)  
height = 1;

ratio = (GLfloat)width/(GLfloat)height;

glViewport(0, 0, (GLint)width, (GLint)height);

glMatrixMode(GL\_PROJECTION);  
glLoadIdentity();

gluPerspective(45.0f, ratio, 0.1f, 100.0f);

glMatrixMode(GL\_MODELVIEW);  
glLoadIdentity();

}

void HandleKeyDown(SDL\_keysym \*keysym)  
{  
switch(keysym-\>sym)  
{  
case SDLK\_ESCAPE:  
case SDLK\_q:  
Quit(0);  
break;  
case SDLK\_F1:  
SDL\_WM\_ToggleFullScreen(surface);  
break;  
case SDLK\_f:  
filter = (++filter)%3;  
break;  
case SDLK\_l:  
light = !light;  
if(!light)  
glDisable(GL\_LIGHTING);  
else  
glEnable(GL\_LIGHTING);  
break;  
case SDLK\_SPACE:  
object = (++object)%6;  
break;  
case SDLK\_PAGEUP:  
if(keysym-\>mod & KMOD\_SHIFT)  
z -= 0.08;  
else  
z -= 0.02;  
break;  
case SDLK\_PAGEDOWN:  
if(keysym-\>mod & KMOD\_SHIFT)  
z += 0.08;  
else  
z += 0.02;  
break;  
case SDLK\_UP:  
if(keysym-\>mod & KMOD\_SHIFT)  
xSpeed -= 0.04;  
else  
xSpeed -= 0.01;  
break;  
case SDLK\_DOWN:  
if(keysym-\>mod & KMOD\_SHIFT)  
xSpeed += 0.04;  
else  
xSpeed += 0.01;  
break;  
case SDLK\_RIGHT:  
if(keysym-\>mod & KMOD\_SHIFT)  
ySpeed += 0.04;  
else  
ySpeed += 0.01;  
break;  
case SDLK\_LEFT:  
if(keysym-\>mod & KMOD\_SHIFT)  
ySpeed -= 0.04;  
else  
ySpeed -= 0.01;  
break;  
default:  
break;  
}  
}

void DrawCube(void)  
{  
glBegin (GL\_QUADS);  
{  
/\* draw cube \*/

```
/* each face drawn counter clockwise 
 * beginining from the bottom left corner */

/* front face */
glNormal3f( 0.0, 0.0, 1.0);

glTexCoord2f(1.0, 0.0);
glVertex3f(-1.0, -1.0, 1.0);

glTexCoord2f(0.0, 0.0);
glVertex3f(1.0, -1.0, 1.0);

glTexCoord2f(0.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);

glTexCoord2f(1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);

/* right face */
glNormal3f(1.0, 0.0, 0.0);

glTexCoord2f(1.0, 0.0);
glVertex3f(1.0, -1.0, 1.0);

glTexCoord2f(0.0, 0.0);
glVertex3f(1.0, -1.0, -1.0);

glTexCoord2f(0.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);

glTexCoord2f(1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0);

/* back face */
glNormal3f(0.0, 0.0, -1.0);

glTexCoord2f(1.0, 0.0);
glVertex3f(1.0, -1.0, -1.0);

glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0, -1.0, -1.0);

glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0, 1.0, -1.0);

glTexCoord2f(1.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);

/* left face */
glNormal3f(1.0, 0.0, 0.0);

glTexCoord2f(1.0, 0.0);
glVertex3f(-1.0, -1.0, -1.0);

glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0, -1.0, 1.0);

glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);

glTexCoord2f(1.0, 1.0);
glVertex3f(-1.0, 1.0, -1.0);

/* top face */
glNormal3f(0.0, 1.0, 0.0);

glTexCoord2f(1.0, 0.0);
glVertex3f(-1.0, 1.0, 1.0);

glTexCoord2f(0.0, 0.0);
glVertex3f(1.0, 1.0, 1.0);

glTexCoord2f(0.0, 1.0);
glVertex3f(1.0, 1.0, -1.0);

glTexCoord2f(1.0, 1.0);
glVertex3f(-1.0, 1.0, -1.0);

/* bottom face */
glNormal3f(0.0, -1.0, 0.0);

glTexCoord2f(1.0, 0.0);
glVertex3f(-1.0, -1.0, -1.0);

glTexCoord2f(0.0, 0.0);
glVertex3f(1.0, -1.0, -1.0);

glTexCoord2f(0.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);

glTexCoord2f(1.0, 1.0);
glVertex3f(-1.0, -1.0, 1.0);

```

}  
glEnd();  
}

void DrawScreen(void)  
{  
static GLint timeA, timeB, frames = 0;  
static GLfloat fps, seconds = 0.0;

glClear(GL\_COLOR\_BUFFER\_BIT | GL\_DEPTH\_BUFFER\_BIT);

glLoadIdentity();

glTranslatef(0.0, 0.0, z);

glRotatef(xRot, 1.0, 0.0, 0.0);  
glRotatef(yRot, 0.0, 1.0, 0.0);

glBindTexture(GL\_TEXTURE\_2D, texture[filter]);

switch(object)  
{  
case 0:  
glTranslatef(0.0, 0.0, 1.0);  
gluDisk(quadric, 0.5, 1.0, 32, 32);  
glTranslatef(0.0, 0.0, -1.5f);  
gluCylinder(quadric, 1.0, 1.0, 3.0, 32, 32);  
break;  
case 1:  
gluDisk(quadric, 0.5, 1.5, 32, 32);  
break;  
case 2:  
DrawCube();  
break;  
case 3:  
gluSphere(quadric, 1.3f, 32, 32);  
break;  
case 4:  
/\* draw a cone \*/  
glTranslatef(0.0, 0.0, -1.5);  
gluCylinder(quadric, 1.0, 0.0, 3.0, 32, 32);  
break;  
case 5:  
part1 += p1;  
part2 += p2;  
if(part1 \> 359)  
{  
part1 = 0;  
p1 = 0;  
p2 = 1;  
part2 = 0;  
}  
if(part2 \> 359)  
{  
p1 = 1;  
p2 = 0;  
}  
gluPartialDisk(quadric, 0.5, 1.5, 32, 32, part1, part2-part1);  
break;  
}

SDL\_GL\_SwapBuffers();

frames++;  
timeB = SDL\_GetTicks();  
if(timeB - timeA \>= 5000)  
{  
seconds = (timeB - timeA) / 1000.0;  
fps = frames / seconds;  
fprintf(stdout, “%d frames in %g seconds = %g fps.\n”, frames, seconds,  
fps);  
timeA = timeB;  
frames = 0;  
}

xRot += xSpeed;  
yRot += ySpeed;

}

int main(int argc, char \*\*argv)  
{

int videoFlags;  
int done = FALSE;

SDL\_Event event;

int isActive = TRUE;

if(SDL\_Init(SDL\_INIT\_VIDEO) \< 0)  
{  
fprintf(stderr,“Unable to init video: %s\n”, SDL\_GetError());  
Quit(1);  
}

videoFlags =  
SDL\_OPENGL |  
SDL\_GL\_DOUBLEBUFFER |  
SDL\_HWPALETTE |  
SDL\_RESIZABLE |  
SDL\_HWSURFACE |  
SDL\_HWACCEL;

SDL\_GL\_SetAttribute(SDL\_GL\_DOUBLEBUFFER, 1);

if((surface = SDL\_SetVideoMode(SCREEN\_WIDTH, SCREEN\_HEIGHT, SCREEN\_BPP,  
videoFlags)) == NULL)  
{  
fprintf(stderr,“Unable to grab surface: %s\n”,SDL\_GetError());  
Quit(1);  
}

if((SDL\_EnableKeyRepeat(100, SDL\_DEFAULT\_REPEAT\_INTERVAL)) \> 0)  
{  
fprintf(stderr,“Unable to setup keyboad repeat: %s\n”,SDL\_GetError());  
Quit(1);  
}

if(!InitGL())  
{  
fprintf(stderr,“Unable to init OpenGL: %s\n”, SDL\_GetError());  
}

SetGLWindow(SCREEN\_WIDTH, SCREEN\_HEIGHT);

while(!done)  
{  
while(SDL\_PollEvent(&event))  
{  
switch(event.type)  
{  
case SDL\_ACTIVEEVENT:  
if(event.active.gain == 0)  
isActive = FALSE;  
else  
isActive = TRUE;  
break;  
case SDL\_VIDEORESIZE:  
if((surface = SDL\_SetVideoMode(event.resize.w,  
event.resize.h,  
SCREEN\_BPP,  
videoFlags)) == NULL)  
{  
fprintf(stderr,“Unable to grab surface after resize event:  
%s\n”,SDL\_GetError());  
Quit(1);  
}  
SetGLWindow(event.resize.w, event.resize.h);  
break;  
case SDL\_KEYDOWN:  
HandleKeyDown(&event.key.keysym);  
break;  
case SDL\_QUIT:  
done = TRUE;  
break;  
default:  
break;  
}  
}  
if(isActive)  
DrawScreen();  
}

Quit(42);  
return 0;  
}On Wednesday 12 January 2005 08:31 am, Michael Wyrzykowski wrote:

> 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 [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

–  
They that can give up essential liberty to obtain a little temporary safety  
deserve neither liberty nor safety. --Benjamin Franklin

---

<div class="post-metadata">

**Author:** ![Bob\_Pendleton](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@Bob\_Pendleton](https://discourse.libsdl.org/u/Bob_Pendleton)\
**Post date:** [January 13, 2005, 3:15am UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/9 "2005-01-13T03:15:03Z")

</div>

> > > > 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).

Very interesting. I would not have expected it to work that way. Are you  
using using any back buffers? That is, are you using double buffering or  
using a Z buffer? What is happening only makes sense (at least to me) if  
you are only using the front buffer. Normally the back buffers have to  
be resized to match the size of the window.

```
		Bob PendletonOn Wed, 2005-01-12 at 16:31 +0000, Michael Wyrzykowski wrote:

```

> On Tue, 2005-01-11 at 19:11 +0000, Michael Wyrzykowski wrote:

> * * *
> 
> Speed up your surfing with Juno SpeedBand.  
> Now includes pop-up blocker!  
> Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Michael\_Wyrzykowski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@Michael\_Wyrzykowski](https://discourse.libsdl.org/u/Michael_Wyrzykowski)\
**Post date:** [January 13, 2005, 11:35pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/10 "2005-01-13T23:35:55Z")

</div>

> > > > 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).

> > Very interesting. I would not have expected it to work that way. Are \> \> you using using any back buffers? That is, are you using double \> \> buffering or using a Z buffer? What is happening only makes sense \> \> (at least to me) if you are only using the front buffer. Normally \> \> the back buffers have to be resized to match the size of the window.

> ```
> Bob Pendleton
> 
> ```

Yes, I am using Double-Buffering. My window setup code looks like:-----  
//Set Window Attributes   
SDL\_GL\_SetAttribute( SDL\_GL\_RED\_SIZE, 5 );  
SDL\_GL\_SetAttribute( SDL\_GL\_GREEN\_SIZE, 5 );  
SDL\_GL\_SetAttribute( SDL\_GL\_BLUE\_SIZE, 5 );  
SDL\_GL\_SetAttribute( SDL\_GL\_DEPTH\_SIZE, 16 );  
SDL\_GL\_SetAttribute( SDL\_GL\_DOUBLEBUFFER, 1 );

## //create the window SDL\_Surface \*s; s = SDL\_SetVideoMode(800, 600, 0, SDL\_OPENGL | SDL\_RESIZABLE);

Also, I was just playing a non-commercial game that uses SDL and OpenGL and it also allows the user to resize the window to whatever size they want, all in real time on my laptop, so I would doubt that the game reloads in all the textures either.

What I am trying to figure out is: since it is possible to resize the window using the mouse without calling SetVideoMode() again or reloading all the textures again, is there any way to do this using code? Using glScalef() seems to work just find, but I do not know if it is possible without getting Win32-specific to resize the window without using the mouse.

* * *

Speed up your surfing with Juno SpeedBand.  
Now includes pop-up blocker!  
Only $14.95/month -visit [Juno Internet Service- Value-priced Internet Service Provider - ISP - Free, low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!

---

<div class="post-metadata">

**Author:** ![Bob\_Pendleton](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@Bob\_Pendleton](https://discourse.libsdl.org/u/Bob_Pendleton)\
**Post date:** [January 14, 2005, 3:56pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/11 "2005-01-14T15:56:28Z")

</div>

> > > > > 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).
> 
> > > Very interesting. I would not have expected it to work that way. Are \> \> you using using any back buffers? That is, are you using double \> \> buffering or using a Z buffer? What is happening only makes sense \> \> (at least to me) if you are only using the front buffer. Normally \> \> the back buffers have to be resized to match the size of the window.
> 
> > ```
> > Bob Pendleton
> > 
> > ```
> 
> ## Yes, I am using Double-Buffering. My window setup code looks like:
> 
> //Set Window Attributes   
> SDL\_GL\_SetAttribute( SDL\_GL\_RED\_SIZE, 5 );  
> SDL\_GL\_SetAttribute( SDL\_GL\_GREEN\_SIZE, 5 );  
> SDL\_GL\_SetAttribute( SDL\_GL\_BLUE\_SIZE, 5 );  
> SDL\_GL\_SetAttribute( SDL\_GL\_DEPTH\_SIZE, 16 );  
> SDL\_GL\_SetAttribute( SDL\_GL\_DOUBLEBUFFER, 1 );
> 
> ## //create the window SDL\_Surface \*s; s = SDL\_SetVideoMode(800, 600, 0, SDL\_OPENGL | SDL\_RESIZABLE);
> 
> Also, I was just playing a non-commercial game that uses SDL and OpenGL and it also allows the user to resize the window to whatever size they want, all in real time on my laptop, so I would doubt that the game reloads in all the textures either.
> 
> What I am trying to figure out is: since it is possible to resize the window using the mouse without calling SetVideoMode() again or reloading all the textures again, is there any way to do this using code? Using glScalef() seems to work just find, but I do not know if it is possible without getting Win32-specific to resize the window without using the mouse.

As far as I know there is currently know way to do what you want to do  
without reloading the textures. What is going on here is out side my  
expertise and violates what I thought I knew about SDL and OpenGL. I  
have a couple of more questions for you. I have assumed that you are  
using Windows, is that correct? Whose OpenGL drivers are you using? Have  
you tried this using other OpenGL drivers? At this point I am trying to  
extend my understanding of the problem.

```
	Bob PendletonOn Thu, 2005-01-13 at 23:35 +0000, Michael Wyrzykowski wrote:

```

> * * *
> 
> Speed up your surfing with Juno SpeedBand.  
> Now includes pop-up blocker!  
> Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Michael\_Wyrzykowski](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/c57346/32.png) [@Michael\_Wyrzykowski](https://discourse.libsdl.org/u/Michael_Wyrzykowski)\
**Post date:** [January 14, 2005, 10:21pm UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/12 "2005-01-14T22:21:36Z")

</div>

> SDL-announce)"   
> Message-ID: \<1105718188.3376.106.camel at [voyager.swordx.com](http://voyager.swordx.com)\>  
> Content-Type: text/plain

> > > > > 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).
> 
> > > Very interesting. I would not have expected it to work that way. Are \> \> you using using any back buffers? That is, are you using double \> \> buffering or using a Z buffer? What is happening only makes sense \> \> (at least to me) if you are only using the front buffer. Normally \> \> the back buffers have to be resized to match the size of the window.
> 
> > ```
> > Bob Pendleton
> > 
> > ```
> 
> > ## Yes, I am using Double-Buffering. My window setup code looks like:
> > 
> > //Set Window Attributes   
> > SDL\_GL\_SetAttribute( SDL\_GL\_RED\_SIZE, 5 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_GREEN\_SIZE, 5 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_BLUE\_SIZE, 5 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_DEPTH\_SIZE, 16 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_DOUBLEBUFFER, 1 );
> > 
> > ## //create the window SDL\_Surface \*s; s = SDL\_SetVideoMode(800, 600, 0, SDL\_OPENGL | SDL\_RESIZABLE);
> > 
> > Also, I was just playing a non-commercial game that uses SDL and \> \> OpenGL and it also allows the user to resize the window to whatever \> \> size they want, all in real time on my laptop, so I would doubt that \> \> the game reloads in all the textures either.
> 
> > > What I am trying to figure out is: since it is possible to resize \> \> the window using the mouse without calling SetVideoMode() again or  
> > > reloading all the textures again, is there any way to do this using \> \> code? Using glScalef() seems to work just find, but I do not know if \> \> it is possible without getting Win32-specific to resize the window  
> > > without using the mouse.

> As far as I know there is currently know way to do what you want to do  
> without reloading the textures. What is going on here is out side my  
> expertise and violates what I thought I knew about SDL and OpenGL. I  
> have a couple of more questions for you. I have assumed that you are  
> using Windows, is that correct? Whose OpenGL drivers are you using?  
> Have  
> you tried this using other OpenGL drivers? At this point I am trying  
> to  
> extend my understanding of the problem.

I testing the game myself on WindowsXP Pro on a laptop that has a Intel Integrated Graphics Card (16MB-64MB shared Ram). Also, I have a friend who’s testing it on Windows as well, and he has a 128MB NVidia card (not sure of the model of hand) and has reported no problems changing resolutions. I guess extra time required to load in the textures isn’t that bad (.5 - 1 second on my machine), but I was a little worried about fragmenting the heap if the person playing the game decided to constantly switch resolutions. Now that I think about it, I probably should reset the resolution to preserve the best quality on high-end monitors (as opposed to my laptop’s LCD that really has only one true resolution).\> Date: Fri, 14 Jan 2005 09:56:28 -0600

> From: Bob Pendleton   
> Subject: Re: [SDL] Re: Changing the Screen Size at Runtime  
> To: A "list for developers using the SDL library. (includes  
> On Thu, 2005-01-13 at 23:35 +0000, Michael Wyrzykowski wrote:

* * *

Speed up your surfing with Juno SpeedBand.  
Now includes pop-up blocker!  
Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!

---

<div class="post-metadata">

**Author:** ![Simon2](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@Simon2](https://discourse.libsdl.org/u/Simon2)\
**Post date:** [January 15, 2005, 1:03am UTC](https://discourse.libsdl.org/t/changing-the-screen-size-at-runtime/11732/13 "2005-01-15T01:03:12Z")

</div>

I’ve discussed once with OpenGL gurus and they told me this:

If you wish to change (close and reopen) the window, you need to unload  
every textures, clean the video memory as if you were quiting (just keep  
everything in RAM) then change video resolution. In the new resolution,  
you have to upload in VRAM all textures that are needed for the render.

This is just considering the VideoRAM, I don’t think (I’m not sure  
actually) if the application heap changes if the Video surface changes.

Also, by doing a proper “Unloading…” animation and the usual “Loading…”  
animation, this will prevent the user from always switching. At that time,  
if the user has to do something else while he use your program (chat,  
email, browse, etc…) he should consider playing in a window that fills  
the screen but not in fullscreen mode. My opinion and suggestion…

HTH,  
Simon

Original Message:-----------------  
From: Michael Wyrzykowski [wyrzy@juno.com](mailto:wyrzy@juno.com)  
Date: Fri, 14 Jan 2005 22:21:36 GMT  
To: sdl at [libsdl.org](http://libsdl.org)  
Subject: [SDL] Re: Changing the Screen Size at Runtime

> Date: Fri, 14 Jan 2005 09:56:28 -0600  
> From: Bob Pendleton   
> Subject: Re: [SDL] Re: Changing the Screen Size at Runtime  
> To: A “list for developers using the SDL library. (includes  
> SDL-announce)”   
> Message-ID: \<1105718188.3376.106.camel at [voyager.swordx.com](http://voyager.swordx.com)\>  
> Content-Type: text/plain

> On Thu, 2005-01-13 at 23:35 +0000, Michael Wyrzykowski wrote:
> 
> > > > > 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).
> 
> > > Very interesting. I would not have expected it to work that way. Are  
> > > you using using any back buffers? That is, are you using double \> \>  
> > > buffering or using a Z buffer? What is happening only makes sense \> \> (at  
> > > least to me) if you are only using the front buffer. Normally \> \> the  
> > > back buffers have to be resized to match the size of the window.
> 
> > ```
> > Bob Pendleton
> > 
> > ```
> 
> > ## Yes, I am using Double-Buffering. My window setup code looks like:
> > 
> > //Set Window Attributes   
> > SDL\_GL\_SetAttribute( SDL\_GL\_RED\_SIZE, 5 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_GREEN\_SIZE, 5 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_BLUE\_SIZE, 5 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_DEPTH\_SIZE, 16 );  
> > SDL\_GL\_SetAttribute( SDL\_GL\_DOUBLEBUFFER, 1 );
> > 
> > ## //create the window SDL\_Surface \*s; s = SDL\_SetVideoMode(800, 600, 0, SDL\_OPENGL | SDL\_RESIZABLE);
> > 
> > Also, I was just playing a non-commercial game that uses SDL and \> \>  
> > OpenGL and it also allows the user to resize the window to whatever \> \>  
> > size they want, all in real time on my laptop, so I would doubt that \> \>  
> > the game reloads in all the textures either.
> 
> > > What I am trying to figure out is: since it is possible to resize \> \>  
> > > the window using the mouse without calling SetVideoMode() again or  
> > > reloading all the textures again, is there any way to do this using \>  
> > > code? Using glScalef() seems to work just find, but I do not know if \> \>  
> > > it is possible without getting Win32-specific to resize the window  
> > > without using the mouse.

> As far as I know there is currently know way to do what you want to do  
> without reloading the textures. What is going on here is out side my  
> expertise and violates what I thought I knew about SDL and OpenGL. I  
> have a couple of more questions for you. I have assumed that you are  
> using Windows, is that correct? Whose OpenGL drivers are you using?  
> Have  
> you tried this using other OpenGL drivers? At this point I am trying  
> to  
> extend my understanding of the problem.

I testing the game myself on WindowsXP Pro on a laptop that has a Intel  
Integrated Graphics Card (16MB-64MB shared Ram). Also, I have a friend  
who’s testing it on Windows as well, and he has a 128MB NVidia card (not  
sure of the model of hand) and has reported no problems changing  
resolutions. I guess extra time required to load in the textures isn’t that  
bad (.5 - 1 second on my machine), but I was a little worried about  
fragmenting the heap if the person playing the game decided to constantly  
switch resolutions. Now that I think about it, I probably should reset the  
resolution to preserve the best quality on high-end monitors (as opposed to  
my laptop’s LCD that really has only one true resolution).

* * *

Speed up your surfing with Juno SpeedBand.  
Now includes pop-up blocker!  
Only $14.95/month -visit [Juno Internet Service - Value-priced Internet Service Provider - Dial-Up and DSL Internet Service - ISP - Free email and low-cost and fast Internet Access](http://www.juno.com/surf) to sign up today!

* * *

SDL mailing list  
SDL at [libsdl.org](http://libsdl.org)  
[http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

* * *

mail2web - Check your email from the web at  
[http://mail2web.com/](http://mail2web.com/) .
