From the code I have of a program that draws and moves a square around an application window, I'm having trouble when resizing the application window. When I handle a resize and alter states accordingly, everything on the screen that should be drawn and was before the resize vanishes. I have no idea why because none of the objects internal coordinates are changed during the window resizing.
My question is can anyone point me in the right direction to solve my problem.(The code compiles fine)
void ResizeWindow()
{
screen_width = event.resize.w;
screen_height = event.resize.h;
SDL_SetVideoMode(screen_width, screen_height, bpp, SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF);
glViewport(0, 0, screen_width, screen_height);
glMatrixMode(GL_PROJECTION);
glOrtho(0, screen_width, 0, screen_height, -1, 1);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
}
Main loop:
while (running == true)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_VIDEORESIZE: ResizeWindow(); break; // resizing called here
case SDL_QUIT: running = false; break;
case SDL_KEYDOWN: square.Handle_Input(down); break;
case SDL_KEYUP: square.Handle_Input(up); break;
}
}
square.Move();
square.Check_Collision();
glClear(GL_COLOR_BUFFER_BIT);
square.Draw();
SDL_GL_SwapBuffers();
}
It all runs perfectly until the window is resized.
SDL_WINDOWEVENT_RESIZED
in sdl 2.0 – lubosz