Weird problem with window resizing & SDL
Hey guys, I hope that one of you has encountered this before.
My main question is: Is it really necessary to call SDL_SetVideoMode every time after you resize the window? It seems to work if I call it or not. I only use SDL to create the window, then I will draw to it with OpenGL. However, it seems possible that it needs to reallocate the framebuffer with a new size or something. I couldn't find any clear explanation on the web.
Lets just say we do that. Everything works great (after some work with reloading everything...) except for one thing. I can't explain it well, but basically when I maximize the window, the title bar goes up a little higher than is supposed to. Half of it gets cut off by going off the top of the screen. I played around with it a little, and for some reason, if you resize the screen when the title bar it near the top of the screen, the whole window actually shifts up a little. It does this when you call SDL_SetVideoMode and it "remakes" the screen, and it worked great when I didn't call it.
Since it's kind of hard to explain, I'll let you see it for yourself if you trust me: Download Aliqui (16k)
It looks for some files (settings, bmp, etc.), but I didn't include them to make it simpler. It's just the exe, and it should do fine by itself. This is also a chance for me to test my code.. please tell me if it fails to run, and tell me what "log.txt" says! It just loads a window and draws something simple. (though as most of you know, a LOT more goes on in the background :)).
Anyway, that's it, thanks!
EDIT: It has simple controls. ESC to quit and F1 to toggle fullscreen.
Ok I tested that all out and then tried my own stuff (I have ss if you'd want them for visual pictures of what's going on) and I saw the same thing happen to me. So here's what you should do:
1. Make sure you pass in the SDL_RESIZABLE flag to the video mode. Initially you will get that, but when you call the video again, it's easy to forget.
2.
The -1 was a hack that I just found makes it work right. Give that a try and see if it fixes your problem.
3. After that, it should all work out fine. When you double click on the screen it will make it not all cutoff at the top. Since it is a hack though, when you do regular resize you will get a -1 size penalty hehe. I'm sure you can mess around with that to fix it.
1. Make sure you pass in the SDL_RESIZABLE flag to the video mode. Initially you will get that, but when you call the video again, it's easy to forget.
2.
if ( event.type == SDL_VIDEORESIZE ){ g_Width = event.resize.w; g_Height = event.resize.h; SDL_SetVideoMode( g_Width, g_Height-1, g_BPP, g_Flags );// Don't forget to reset this!! glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45, (float)g_Width/(float)g_Height, 1, 1000 ); glMatrixMode(GL_MODELVIEW);}
The -1 was a hack that I just found makes it work right. Give that a try and see if it fixes your problem.
3. After that, it should all work out fine. When you double click on the screen it will make it not all cutoff at the top. Since it is a hack though, when you do regular resize you will get a -1 size penalty hehe. I'm sure you can mess around with that to fix it.
Haha, what a hack [grin] So this is a known bug? I couldn't anything on their forums or anywhere on the internet about this. Maybe I just used bad keywords. Seems like an obvious bug though.. I guess if you're gonna maximize it, might as well make it fullscreen.
Yep, I set the RESIZABLE flag again. In fact, the same function is called when the window needs to be recreated (SDL_SetVideoMode needs to be called).
I tried your fix and indeed it worked. It's a little impractical for my app though, because the same place could be calling it with a fullscreen flag and the -1 would make it an unsupported resolution! I could do an if/then statement, but geez.. such a hack for a small fix.
I'm just not gonna worry about it. Thanks though, glad to know it's not just my code [smile] I'll keep the hack in mind... maybe there's a way to disable maximization...
Yep, I set the RESIZABLE flag again. In fact, the same function is called when the window needs to be recreated (SDL_SetVideoMode needs to be called).
I tried your fix and indeed it worked. It's a little impractical for my app though, because the same place could be calling it with a fullscreen flag and the -1 would make it an unsupported resolution! I could do an if/then statement, but geez.. such a hack for a small fix.
I'm just not gonna worry about it. Thanks though, glad to know it's not just my code [smile] I'll keep the hack in mind... maybe there's a way to disable maximization...
I noticed this problem after one of the more recent versions of SDL came out, and it just seems that it never was fixed for 1.2.8. I think it was fine in 1.2.6. Anyway, it's not a very serious issue, and most games would run in fullscreen anyway, right? I imagine nobody got around to the fix.
Kind of a funny observation: If you maximize the window (title bar will now be higher than your screen) and then minimize, and then restore, it will end up back to normal too.
This also only seems to happen in windows, as the linux build of my SDL apps resize normally.
Kind of a funny observation: If you maximize the window (title bar will now be higher than your screen) and then minimize, and then restore, it will end up back to normal too.
This also only seems to happen in windows, as the linux build of my SDL apps resize normally.
[edit] Ohh, thanks for that info Redleaf on Linux and it working on 1.2.6. Perhaps it is a bug with Windows...
[grin] I don't know if it's a known bug or not, but it is indeed weird. However, what I think is happening with windowed is the fact that it is an odd resolution that made it clip weird. For example, try adding one instead, it works fine as well. I also set my fullscreen flag and did that and nothing bad went wrong *yet*, so you may want to test that out if you do, I'm not sure if you can generate an illegal size with fullscreen. There was one interesting post here on catching that maximize event, but it was no help to me [lol]. Oh well, if I stumble upon anything I'll let you know. Cheers!
[grin] I don't know if it's a known bug or not, but it is indeed weird. However, what I think is happening with windowed is the fact that it is an odd resolution that made it clip weird. For example, try adding one instead, it works fine as well. I also set my fullscreen flag and did that and nothing bad went wrong *yet*, so you may want to test that out if you do, I'm not sure if you can generate an illegal size with fullscreen. There was one interesting post here on catching that maximize event, but it was no help to me [lol]. Oh well, if I stumble upon anything I'll let you know. Cheers!
If you're brave enough, you can even venture into the source and see if you can find/fix the problem and submit a patch proposal. That's one of the great things about open source software... you can look at the source :-P.
Quote:Original post by Drew_Benton
[edit] Ohh, thanks for that info Redleaf on Linux and it working on 1.2.6. Perhaps it is a bug with Windows...
[grin] I don't know if it's a known bug or not, but it is indeed weird. However, what I think is happening with windowed is the fact that it is an odd resolution that made it clip weird. For example, try adding one instead, it works fine as well. I also set my fullscreen flag and did that and nothing bad went wrong *yet*, so you may want to test that out if you do, I'm not sure if you can generate an illegal size with fullscreen. There was one interesting post here on catching that maximize event, but it was no help to me [lol]. Oh well, if I stumble upon anything I'll let you know. Cheers!
Yeah, looks like it's something weird with odd numbers... good point, I was wondering why the change of 1 fixed it.
SDL is pretty good at doing fullscreen. I think it defaults to 800x600 if the supplied resolution isn't supported, so that's probably what's happening.
Quote:
If you're brave enough, you can even venture into the source and see if you can find/fix the problem and submit a patch proposal. That's one of the great things about open source software... you can look at the source :-P.
True.. if only someone would actually do that :p Since it's not a huge deal, I won't worry about it and they'll probably fix it by the time I show my application to people.
strange, i had exactly the same problem a few weeks ago. now i accidentally came across this thread and wanted to try the -1 hack but it didn't seem to be necessary anymore. resizing worked without problems. i don't think i changed anything in the meantime. :p
I downloaded your exe and couldn't see anything wrong whatsoever. Maybe my SDL is more up-to-date? I'm on XP Home SP2.
Quote:Original post by ukdeveloper
I downloaded your exe and couldn't see anything wrong whatsoever. Maybe my SDL is more up-to-date? I'm on XP Home SP2.
Did you double click on the title bar to make it fullscreen? It still happens for me. What video card do you have?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement