Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL window with SDL not showing
    text
    copied!<p>I'm working on a program with OpenGL/SDL, but the window won't draw. The window's entry appears in the taskbar and the alt+tab menu, but no thumbnail is shown. When I click it, it's marked as active, but nothing changes onscreen. </p> <p>I can verify that <code>glClear(GL_COLOR_BUFFER_BIT)</code> and <code>SDL_GL_SwapBuffers()</code> are being called from my render loop, and that <code>SDL_SetVideoMode</code> is succeeding, but it still won't render. It's not a shared library issue, since other SDL/GL apps work fine. </p> <p>Any ideas?</p> <p>EDIT:</p> <p>Here's the graphics initialization:</p> <pre><code>void GraphicsManager::initGraphics() { // Access prefs PreferencesManager* prefMgr = PreferencesManager::getInstance(); int width = prefMgr-&gt;getIntKey("res_width"); int height = prefMgr-&gt;getIntKey("res_height"); if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "Cannot initialize SDL video!\n"); exit(1); } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); m_screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL); if(!m_screen) { fprintf(stderr, "Error: Invalid screen pointer\n"); exit(2); } SDL_ShowCursor(SDL_DISABLE); // Setup OpenGL stuffs glDisable(GL_DEPTH_TEST); // We're only using 2D glClearColor(0.0, 0.0, 0.0, 0.0); glViewport(0.0, 0.0, width, height); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, width, height, 0.0, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glClear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapBuffers(); // Init FPS stuff m_avgFps = 60.0f; m_lastUpdate = SDL_GetTicks(); } </code></pre> <p>Here's my main loop:</p> <pre><code>while(stateMgr-&gt;getState() != GS_QUIT) { // Process input events inputMgr-&gt;processEvents(); // Update the current system mode stateMgr-&gt;update(); // Update GUI state guiMgr-&gt;update(); // Render gfxMgr-&gt;render(); //char buf[16]; //snprintf(buf, 16, "FPS: %4.2f", gfxMgr-&gt;getFramerate()); //testWindow-&gt;getChild("TestRoot/Framerate")-&gt;setText(buf); SDL_Delay(10); } </code></pre> <p>And here's the render function:</p> <pre><code>void GraphicsManager::render() { std::list&lt;IRenderCallback*&gt;::iterator rci; // Clear the screen glClear(GL_COLOR_BUFFER_BIT); // Run render callbacks /*for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) { (*rci)-&gt;preRender(); } // Iterate through all renderables and render them std::list&lt;Renderable*&gt;::iterator i; for(i=m_renderables.begin();i != m_renderables.end();i++) { (*i)-&gt;render(); } // Run render callbacks for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) { (*rci)-&gt;preFlip(); }*/ // Flip the buffers SDL_GL_SwapBuffers(); // Update FPS stuff Uint32 now = SDL_GetTicks(); Uint32 timeTaken = now - m_lastUpdate; m_lastUpdate = now; double seconds = (double)timeTaken / 1000.0f; m_avgFps = (1.0f / seconds); // Run render callbacks for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) { (*rci)-&gt;postRender(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload