[SDL] SDL_PollEvent VS SDL_WaitEvent

Will Childman c7liu at uwaterloo.ca
Thu Jan 27 18:28:33 PST 2005


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 at juno.com
Date: Fri, 14 Jan 2005 22:21:36 GMT
To: sdl at libsdl.org
Subject: [SDL] Re: Changing the Screen Size at Runtime



> Date: Fri, 14 Jan 2005 09:56:28 -0600
> From: Bob Pendleton <bob at pendleton.com>
> Subject: Re: [SDL] Re: Changing the Screen Size at Runtime
> To: A "list for developers using the SDL library. (includes
> 	SDL-announce)"	<sdl at libsdl.org>
> Message-ID: <1105718188.3376.106.camel at 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 http://www.juno.com/surf to sign up today!


_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .






More information about the SDL mailing list