Jump to content
  • Advertisement
Sign in to follow this  
M2tM

[SDL/OpenGL] Resize without destroying context?

This topic is 4468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking for advice on resizing my SDL window without having to re-load all my textures... (This sounds like it's what people have to do when the window is resized, but that sounds rediculous... To have to re-load textures from file EVERY time the window is resized? WTF?) Anyway, I have a second problem beyond just re-loading from file (that would be easy) I have dynamic textures being rendered to all the time... What do I do with these? Ideally there's an easy way to just resize the window keeping all the flags the same without having to worry about needing to re-create the OpenGL context... Any advice? Or is my problem non-existant (I am misreading docs and such.) It certainly appears that my problem is textures being unloaded or at the very least becoming diassociated with their GLuints. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I normally dont suggest such hacks, but this is what I have found.

SDL will deliver you a SDL_RESIZE event after it resizes the window itself. Another call to SDL_SetVideoMode is not required to continue drawing. You *seem* to keep all your textures, but you still have to reset your screen via glViewPort etc...

Obviously you can no longer rely on the SDL_GetVideoSurface() pointer, or the pointer that was returned from SDL_SetVideoMode() to have the correct w and h, or to use in any way.

Summary:

0) dont recall SDL_SetVideoMode()
1) re-run your opengl screen setup, but not texture loading.

Just to be very clear, this is a hack and you should test this out for yourself to verify. For me it works on windows.

Share this post


Link to post
Share on other sites
Well, holy shit. It seems to work...

Since I don't really rely on keeping track of the screen pointer at all anyway that's totally fine with me if the pointer to the surface becomes invalid... As it isn't even being stored anyway.

I will definitly need to test this on a number of systems and platforms to ensure it won't just blow up one day...

But thank you.

++ for the hacky implementation (comments "HACKY" right next to it in code)

It would be ideal if they just had a way of resizing the screen without necisserally destroying the goddamn context when all that changes is the window dimensions.

Edit: I'd rate you up, but you're already at 5

Share this post


Link to post
Share on other sites
The SDL 1.3 API has better support for openGL context handling, so this problem will hopefully dissapear when it becomes standard...

Share this post


Link to post
Share on other sites
From my understand the above isn't a hack, it's pretty much the standard way to do it, but then again, maybe the standard way to do it is a hack? =P

But about your second question, if you have dynamic textures you need to reload, what I do is assign them a random file name, and just dump them to a file before I do anything that requires destroying the context, than just reload them after the context has been reset. Obviously you then delete all those temp files. It's simple, and it works.

Share this post


Link to post
Share on other sites
Apparantly SDL_GetMouseState(&screenX, &screenY); no longer works though... It seems to go based on the original width and height of the window. It only gets the maximum width and height that the window once was. However, if the window is smaller than it started I think windows takes over and leaves the cursor at the edge of the window. The exception to this is if you are clicking and dragging from within the window at which point the cursor is allowed to go to the max and min bounds of the window.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnnyCasil
From my understand the above isn't a hack, it's pretty much the standard way to do it, but then again, maybe the standard way to do it is a hack? =P

But about your second question, if you have dynamic textures you need to reload, what I do is assign them a random file name, and just dump them to a file before I do anything that requires destroying the context, than just reload them after the context has been reset. Obviously you then delete all those temp files. It's simple, and it works.


The documentation basically tells you to call SDL_SetVideoMode with the new screen height and width when you recieve a SDL_VIDEORESIZE event. Doing so *is* required if you are not using a video surface created with SDL_OPENGL, but it doesnt seem to be documented anywhere that you can do this under ogl and get away with it.

If someone could point me to some official documentation that shows this behaviour I would be very grateful.

For now though I have image reloading code still in case I need it.

Share this post


Link to post
Share on other sites
Quote:
Original post by M2tM
Apparantly SDL_GetMouseState(&screenX, &screenY); no longer works though... It seems to go based on the original width and height of the window. It only gets the maximum width and height that the window once was. However, if the window is smaller than it started I think windows takes over and leaves the cursor at the edge of the window. The exception to this is if you are clicking and dragging from within the window at which point the cursor is allowed to go to the max and min bounds of the window.


Ah, I figured that it wasn't perfect. I always used relative co-ordinates, but it makes sense that this could also fail. You could record the new screen width and height somewhere and make your own function to correct the return values.

Share this post


Link to post
Share on other sites
See, image reloading wouldn't be nearly as big a deal as it is except that I have a bunch of textures created dynamically and updated often within my program... Wouldn't I need to like... Save these to file or memory outside OpenGL and then re-load it every time I wanted to resize? I mean, I have a texture manager keeping track of everything so it's not like I don't know what textures are around, it's just that I think it is an intense waste of resources...

I mean, I guess I might have to do it anyway, it's just such a pain in the ass for what should be simple...

*edit: yeah, I could... I'm not entirely sure how I would go about getting the mouse position outside the window from within SDL though...

Maybe I could make another SDL surface for mouse stuff... I don't know how I'd go about this though. I'm really a huge SDL noob, I just use what I have to in order to get OpenGL to run.

Any hints would be appreciated... If the relative thing works outside the window bounds that would solve my problem and I could create something based on that... If it doesn't get coords outside the window position however, I'm hooped for that approach... Unless I misunderstand you.

Share this post


Link to post
Share on other sites
Yeah, I keep track of the screen size in my renderer anyway so it's not a big deal on the OpenGL/coordinate side of things.

Apparantly it only gets events when the window: A) has focus and B) has the mouse over it, or if the mouse button is down and the cursor is being dragged anywhere on the screen.

http://www.libsdl.org/pipermail/sdl/1999-October/022044.html

Edit: Alternatively I could just make the surface huge and then shrink it immediately.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!