Pingus / pingus

GNU General Public License v3.0
170 stars 31 forks source link

Resizing OpenGL window doesn't work #157

Closed Grumbel closed 2 years ago

Grumbel commented 9 years ago

Resizing OpenGL window doesn't work, turns the screen yellow, prints this on the console:

[ERROR /home/ingo/projects/pingus/trunk/pingus/src/engine/display/opengl/opengl_framebuffer.cpp:77] video mode switching not implemented: 801x600 [ERROR /home/ingo/projects/pingus/trunk/pingus/src/engine/display/opengl/opengl_framebuffer.cpp:77] video mode switching not implemented: 954x677 [ERROR /home/ingo/projects/pingus/trunk/pingus/src/engine/display/opengl/opengl_framebuffer.cpp:77] video mode switching not implemented: 1031x725 [ERROR /home/ingo/projects/pingus/trunk/pingus/src/engine/display/opengl/opengl_framebuffer.cpp:77] video mode switching not implemented: 1030x723

TNian145 commented 6 years ago

You're just missing a glLoadIdentity() call after switching to GL_PROJECTION matrix. Multiplying the new orthographic matrix with the old one is not a good idea.

void
OpenGLFramebuffer::set_video_mode(const Size& size, bool fullscreen, bool resizable)
{
  if (m_window)
  {
    SDL_SetWindowSize(m_window, size.width, size.height);

    log_error("video mode switching not implemented: %1%x%2%", size.width, size.height);
    glViewport(0, 0, size.width, size.height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity(); // <------------- HERE
    glOrtho(0, size.width, size.height, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClearColor(1.0, 1.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  }