Advertisement

[SDL]Framerate limited to 60.

Started by April 30, 2012 03:50 PM
3 comments, last by mihaimoldovan 12 years, 7 months ago
Ever since i got a new pc with nvidia's gpu, framerate in sdl has always been limited to 60(which is also my monitor's refresh rate).
My first guess was that my drivers are forcing vsync onto SDL so i tried forcing it off in nvidia's control panel and then the framerate wasnt limited but was over 5000 frames per second.
I don't have that problem in other games, but i suppose they might do something to disable vsync.
I just wonder if there is a way to remove this limit so i would have framerate higher than my refresh rate.
My old gpu never had this problem with very same code i posted below.

ScreenShot: http://localhostr.co...pZ5xZ2i/sdl.jpg

Code:

#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
int WINDOW_OPT[3] = {800, 600, 32};
void InitGL()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WINDOW_OPT[0], WINDOW_OPT[1], 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glDisable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glCullFace(GL_FRONT);

}
int main(int argc, char** argv)
{
SDL_Surface* window = SDL_SetVideoMode(WINDOW_OPT[0], WINDOW_OPT[1], WINDOW_OPT[2], SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER);
SDL_Event event;
SDL_WM_SetCaption("TEST", NULL);

InitGL();

bool run = true;
while(run)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE)
{
run = false;
}
}
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

glBegin(GL_QUADS);
glVertex2f(100, 100);
glVertex2f(200, 100);
glVertex2f(200, 200);
glVertex2f(100, 200);
glEnd();

SDL_GL_SwapBuffers();
}

SDL_Quit();
return 0;
}
Hello.

Since you are using openGL for graphics and refreshing the screen I'd say the problem is related to that rather then SDL.
I have no experience of openGL but I googled it for you and found this.. not sure if it helps you but it's a start atealst.

http://www.gamedev.n...opengl-c-vsync/

*Edit: spelling
Advertisement
Thanks man, i thought it was SDL related but now i figured it out.
VSync can be forced On/Off in the video card driver config panel but it's preferable to let it to "Application settings", which allow programmers to set it on/off in their code. In your case, using SDL and OpenGL you can use SDL_GLattr() with the SDL_GL_SWAP_CONTROL flag. In any way, I actually think have vsync enabled 100% of the time is preferable, otherwise you get screen tearing and getting more FPS than 60 is useless.
Yeah this is because VSync is enabled, not necessarily a bad thing but if you are really looking to disable it you should look at the SGI SwapControl extension (and the same from EXT, because sometimes only one or the other is supported .. yay vendor fragmentation)

This topic is closed to new replies.

Advertisement