我正在使用OpenGL/SDL編寫程序,但窗口不會繪製。該窗口的條目出現在任務欄和alt +選項卡菜單中,但不顯示縮略圖。當我點擊它時,它被標記爲活動,但屏幕上沒有任何變化。SDL沒有顯示的OpenGL窗口
我可以驗證glClear(GL_COLOR_BUFFER_BIT)
和SDL_GL_SwapBuffers()
正在從我的渲染循環中調用,並且SDL_SetVideoMode
成功,但它仍然不會呈現。這不是共享庫問題,因爲其他SDL/GL應用程序可以正常工作。
任何想法?
編輯:
這裏的顯卡初始化:
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();
}
這裏是我的主循環:
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);
}
和這裏的渲染功能:
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();
}
}
特別是,您的窗口創建和主循環。 – Thomas
好的,我添加了主循環,渲染代碼和渲染初始化 – computergeek6