3
\$\begingroup\$

So basically my question is im making a 2D game with openGL and SDL.

So what im trying to do is resize the game and have the openGL quad scale to the size my window becomes.

void CApp::OnResize(int w, int h){

textureWidth = (float)w;
textureHeight = (float)h;

SDLWindow::SetGLWindow(w, h, Surf_Display);

}


bool SDLWindow::SetGLWindow(int width, int height, SDL_Surface * Surf_Display)
{
if((Surf_Display = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_OPENGL | SDL_RESIZABLE)) == NULL) {
    return false;
    }

glClearColor(0, 0, 0, 0);
glClearDepth(1.0f);

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(0, width, height, 0, 1, -1);

glMatrixMode(GL_MODELVIEW);

glEnable(GL_TEXTURE_2D);

glLoadIdentity();

return true;

}

So this works just fine. However while resizing the window, the image isnt scaling. It only scales after i release the mouse button. I am curious if i can scale the image at the same time?

\$\endgroup\$
2
\$\begingroup\$

I'm not too familiar with SDL (more experience with GLUT), but I looked around a bit and found this post. The reply you're looking for is near the bottom by the user 'rip-off'.

It seems that SDL will halt while certain events are occuring, such as resizing the window. However, the program still has to draw, so there are portions of it which are still executing. rip-off suggests taking control of the portion which continues executing by passing your own event filter to SDL_SetEventFilter, and calling your draw() function each time the event is a resize.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.