我正在使用 SDL 和 C++ 创建游戏,但是每当我尝试渲染位图时,我都会在运行时收到错误消息“OpenGL 处于活动状态,请使用 SDL_GL_SwapBuffers()。” 但问题是,我正在使用 SDL_GL_SwapBuffers()。这是代码:
绘图功能:
bool d2Sprite::Draw(SDL_Surface *dest, SDL_Surface *src, int x, int y)
{
if(dest == NULL || src == NULL)
{
cout << "Unable draw sprite! " << SDL_GetError() << endl;
return false;
}
SDL_Rect destR;
destR.x = x;
destR.y = y;
SDL_BlitSurface(src, NULL, dest, &destR);
return true;
}
游戏循环: void d2Main::GameLoop() { cout << "游戏循环运行!" <<endl;
d2Main::Load();
while(d2Main::gameRunning)
{
while(SDL_PollEvent(&event))
{
d2Main::HandleEvents(&event);
}
d2Main::Update();
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
d2Main::Render();
SDL_UpdateRect(screen, 0, 0, 0, 0);
glPopMatrix();
SDL_GL_SwapBuffers(); // <-- I AM USING IT
SDL_Delay(0.8);
}
SDL_Quit();
}