   SDL window resizing error
  I've made a window using SDL and I render inside it using OpenGL.when I resize the window I catch the following event:while(SDL_PollEvent(&m_event)) {  switch(m_event.type) {  case SDL_VIDEORESIZE : { //resize the windowif ( !SetWndSize(m_event.resize.w,m_event.resize.h) ) {//errorreturn true;}break;}   }}Inside my set window function I do the following:bool SetWndSize (int iWidth, int iHeight) {//prevent window from being too smallif (iWidth < 100) {iWidth = 100;}if (iHeight < 100) {iHeight = 100;}m_iWidth = iWidth;m_iHeight = iHeight;/*if (m_pSurf) {SDL_FreeSurface(m_pSurf); }m_pSurf = SDL_SetVideoMode(m_iWidth, m_iHeight, 0, SDL_RESIZABLE | SDL_OPENGL);*///resize viewportSetupProjMatrix();return true;} //SetWndSizeNOTE that I have a chunk of code commented out here.  With this implementation I can resize my window, but the window can be sized down to 0 height.  If I remove the commented section, then the user can not size the window down below 100 x 100 (which is what I want) HOWEVER when they resize the window everything goes black and I can no longer render to the opengl window.  What am I doing wrong?   
  isn't the third argument to SDL_SetVideoMode the bits per pixel? try setting that to something like 16 or 32 and see what happens.   ;  2 things.1/ do _NOT_ use SDL_FreeSurface on the video screen. SDL will take care of what needs to be done by itself2/what i would do is move _all_ my openGL initialisation into a function that can be called repeatedly. i think that calling SDL_SetVideoMode again can cause you to lose your openGL context, all your current settings and textures. they will need to be reloaded...[Edited by - rip-off on December 9, 2005 4:06:32 PM];Quote:Original post by Silexisn't the third argument to SDL_SetVideoMode the bits per pixel? try setting that to something like 16 or 32 and see what happens.0 means use current bit depth   ;  [edit]Wow, I'm slowThat SDL_FreeSurface(m_pSurf); is not reuqired nor advocated when you use SDL. The main screen is managed by the internal system, so freeing it yourself could have bad results. First take that out and see if that solves it, and if not, rebind your textures if you are using them before you continue.Quote:Original post by Silexisn't the third argument to SDL_SetVideoMode the bits per pixel? try setting that to something like 16 or 32 and see what happens.By passing in 0, it uses the desktop resolution.;  As others have said, when you call SDL_SetVideoMode() a new OpenGL context is created, and the old is gone. That explains why you everything is "black". All the settings,the textures,the lists are gone and you must load them and initialize them again.Now, what I'm about to say is not on SDL documentation, but it's what I have found out by experience. Of course, it's crazy to reload the entire data each time the user just wants to resize the window. The thing is, since you're dealing with OpenGL you don't really need to call SDL_SetVideoMode(). The OS will resize the window anyway, you can define your drawing are with glViewport and it will work just fine. That way, you won't have to destroy the window and you won't loose your GL context. If you want to be able to resize the window yourself though(to prevent it from going under 100), you'll have to use the windows API. I don't know any way to do it with SDL. This is what I do:SDL initialization:SDL_SetVideoMode(512,512,0,SDL_RESIZABLE|SDL_OPENGL); m_hwnd=GetActiveWindow();SetWndSize:void SetWndSize(int w,int h){if (w<100) w=100;if (h<100) h=100;m_width=w;m_height=h;RECT bounds;bounds.left=0;bounds.top = 0;bounds.right=m_width;bounds.bottom = m_height;AdjustWindowRectEx(&bounds,GetWindowLong(m_hwnd,GWL_style),FALSE,0);SetWindowPos(m_hwnd,0,0,0,bounds.right-bounds.left,bounds.bottom-bounds.top,SWP_NOZORDER|SWP_NOMOVE);glViewport(0,0,m_width,m_height);SetupProjMatrix();};Quote:Original post by Drew_Benton[edit]Wow, I'm slowThat SDL_FreeSurface(m_pSurf); is not reuqired nor advocated when you use SDL. The main screen is managed by the internal system, so freeing it yourself could have bad results. First take that out and see if that solves it, and if not, rebind your textures if you are using them before you continue.Quote:Original post by Silexisn't the third argument to SDL_SetVideoMode the bits per pixel? try setting that to something like 16 or 32 and see what happens.By passing in 0, it uses the desktop resolution.If I take out the SDL_FreeSurface then I still get the same results... a black screen after I resize.   ;Quote:Original post by mikemanAs others have said, when you call SDL_SetVideoMode() a new OpenGL context is created, and the old is gone. That explains why you everything is "black". All the settings,the textures,the lists are gone and you must load them and initialize them again.Now, what I'm about to say is not on SDL documentation, but it's what I have found out by experience. Of course, it's crazy to reload the entire data each time the user just wants to resize the window. The thing is, since you're dealing with OpenGL you don't really need to call SDL_SetVideoMode(). The OS will resize the window anyway, you can define your drawing are with glViewport and it will work just fine. That way, you won't have to destroy the window and you won't loose your GL context. If you want to be able to resize the window yourself though(to prevent it from going under 100), you'll have to use the windows API. I don't know any way to do it with SDL. This is what I do:SDL initialization:*** Source Snippet Removed ***SetWndSize:*** Source Snippet Removed ***Thanks for the code snippet.  The only thing that I have a problem with it, is that my code will no longer be cross platform compatible, since now I will be relying on Window function calls.... hmmm have to weigh my options.  Maybe it will be safer if I just re-init everything...;  i believe the only safe way with a screen change is to reload everything again (textures/VBOS/programs)mikeman's method should work in 99% of cases though   ;  I'm under the same impression as zedzeek, i dont even know if state is guaranteed to be saved.hope that helps-Dan   