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.
I can verify that glClear(GL_COLOR_BUFFER_BIT) and SDL_GL_SwapBuffers() are being called from my render loop, and that SDL_SetVideoMode is succeeding, but it still won’t render. It’s not a shared library issue, since other SDL/GL apps work fine.
Any ideas?
EDIT:
Here’s the graphics initialization:
void GraphicsManager::initGraphics() {
// Access prefs
PreferencesManager* prefMgr = PreferencesManager::getInstance();
int width = prefMgr->getIntKey("res_width");
int height = prefMgr->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();
}
Here’s my main loop:
while(stateMgr->getState() != GS_QUIT) {
// Process input events
inputMgr->processEvents();
// Update the current system mode
stateMgr->update();
// Update GUI state
guiMgr->update();
// Render
gfxMgr->render();
//char buf[16];
//snprintf(buf, 16, "FPS: %4.2f", gfxMgr->getFramerate());
//testWindow->getChild("TestRoot/Framerate")->setText(buf);
SDL_Delay(10);
}
And here’s the render function:
void GraphicsManager::render() {
std::list<IRenderCallback*>::iterator rci;
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT);
// Run render callbacks
/*for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) {
(*rci)->preRender();
}
// Iterate through all renderables and render them
std::list<Renderable*>::iterator i;
for(i=m_renderables.begin();i != m_renderables.end();i++) {
(*i)->render();
}
// Run render callbacks
for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) {
(*rci)->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)->postRender();
}
}
Break it down. Do the (mostly-ish) simplest thing that should work:
If that works all you have to do (ha!) is figure out how the simple program execution flow differs from your large program. If it doesn’t work your environment is probably goofed somehow.
What do the
GL_VERSION/VENDOR/RENDERERchecks print on your system?