Hey all, I'm writing my first SDL app at the moment, and it seems to be really slow. I'm only calling SDL_PollEvent() in a loop, followed by a SDL_Flip(). I'm not rendering anything at all.
Heres my main loop:
void CApp::Run()
{
SDL_Event theEvent;
bool bExit = false;
U32 dwFrames = 0;
U32 dwStart = SDL_GetTicks();
U32 dwStop = dwStart;
while(!bExit)
{
// Check for events //
while(SDL_PollEvent(&theEvent))
{
switch(theEvent.type)
{
case SDL_QUIT:
Log("SDL_QUIT received\n");
bExit = true;
break;
case SDL_KEYUP:
m_theKeys[theEvent.key.keysym.sym] = false;
break;
case SDL_KEYDOWN:
m_theKeys[theEvent.key.keysym.sym] = true;
break;
case SDL_MOUSEMOTION:
m_nMouseX = theEvent.motion.x;
m_nMouseY = theEvent.motion.y;
break;
case SDL_MOUSEBUTTONDOWN:
if(theEvent.button.button == SDL_BUTTON_LEFT)
m_bMouseButtonStates[0] = 1;
else if(theEvent.button.button == SDL_BUTTON_MIDDLE)
m_bMouseButtonStates[1] = 1;
else if(theEvent.button.button == SDL_BUTTON_RIGHT)
m_bMouseButtonStates[2] = 1;
break;
case SDL_MOUSEBUTTONUP:
if(theEvent.button.button == SDL_BUTTON_LEFT)
m_bMouseButtonStates[0] = 0;
else if(theEvent.button.button == SDL_BUTTON_MIDDLE)
m_bMouseButtonStates[1] = 0;
else if(theEvent.button.button == SDL_BUTTON_RIGHT)
m_bMouseButtonStates[2] = 0;
break;
}
}
// Flip screen //
SDL_Flip(m_pSurface);
dwFrames++;
if(SDL_GetTicks() > 10000)
{
bExit = true;
Log("DEBUG: Exiting app after 10 seconds\n");
}
}
// Report FPS //
U32 dwTime = SDL_GetTicks()-dwStart;
Log("Exiting main loop. Executed "+IntToString(dwFrames)+" frames in "+
IntToString(dwTime)+"ms ("+
FloatToString(((float)dwFrames) / (float)(dwTime/1000))+" FPS)\n");
}
And heres my init code:
bool CApp::Init(bool bFullscreen)
{
U32 dwFlags;
// Create backbuffer //
dwFlags = SDL_HWSURFACE | SDL_DOUBLEBUF;
if(bFullscreen) dwFlags |= SDL_FULLSCREEN;
m_pSurface = SDL_SetVideoMode(800,600,32,dwFlags);
if(!m_pSurface)
{
m_strError = SDL_GetError();
return false;
}
// Done //
return true;
}
And heres the results:
Windowed: "Exiting main loop. Executed 1062 frames in 9932ms (118.000000 FPS)"
Fullscreen: "Exiting main loop. Executed 616 frames in 9042ms (68.444443 FPS)"
That seems pretty slow to me. If this were a DirectX app, I'd be expecting around 2 or 3 thounsand FPS...
Is SDL always like this, or is it something i've got set up wrong? Is this just an initial slowdown, and actually drawing stuff won't lower the frame rate much?
Cheers,
Steve