Advertisement

SDL and OpenGL framerate issue (solved)

Started by January 21, 2005 05:35 PM
2 comments, last by Drew_Benton 20 years, 1 month ago
I am contructing a 3D engine using SDL (v.1.2.7) and OpenGL but I have a really slow framerate on my GeForce 6800LE card compared to the ATI Radeon 9800. From a 200 fps on the ATI I get a 30 on the GeForce. I'm not an expert on benchmarking graphics card but there shouldn't be such a difference considering I use about 1500 polygons with no lightning! The code for my engine is the same and I don't use any extensions or shader code. From what it looks my GeForce have the bottleneck when blitting the buffered display surface to the screen. My code for setting up the video mode together with my main loop and render function:

void MTApplication::createWindow(int i_width, int i_height, bool i_fullscreen)
{
	const SDL_VideoInfo* info = NULL;
    int bpp = 0;
    int flags = 0;

	// Get information from system
    info = SDL_GetVideoInfo();
    bpp = info->vfmt->BitsPerPixel;
	

    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_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 16);

	if (i_fullscreen)
		flags = SDL_OPENGL | SDL_FULLSCREEN;
	else
		flags = SDL_OPENGL | SDL_ANYFORMAT | SDL_HWACCEL | SDL_HWSURFACE;

   if( SDL_SetVideoMode( i_width, i_height, bpp, flags ) == 0 ) {
		fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
		SDL_Quit();
		return;
    }
	
	SDL_WM_SetCaption("Project: The Room - Version 2.0", 0);
	MTLOG::LOG("MTApplication:: Window created");
}

// Render using OpenGL
void MTApplication::render()
{

	// glClear( GL_COLOR_BUFFER_BIT );

	// Set modelview matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// ############################################
	// Process our scenegraph
	m_scenegraph->process();
	
	// Animation test
	animate();

	// Draw world axis and grid
	/*glPushMatrix();
		glScalef(10.0f, 10.0f, 10.0f);
		drawWorldAxis();
		glScalef(10.0f, 10.0f, 10.0f);
		drawWorldGrid(10.0f);
	glPopMatrix();*/
 
	// Swap buffers
	SDL_GL_SwapBuffers();
}


// Run this application
void MTApplication::run()
{
	
	// Main loop
	m_running = true;
	m_appState = MT_APP_PLAYER_IN_WORLD;
	
	while (m_running) 
	{		
		glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

		// Do CPU tasks
		MTEventHandler::processEvents(m_event);
		doLogic();

		// Do GPU tasks
		render();
	}

}



I have no problem with OpenGL in demos/games and I have the latest drivers for my graphics card. I have tested with different flag settings for the video mode with no success. Turning off double buffer causes flickering but increases the framerate with 500%! Any ideas? Anyone had the same problem? Is there a perhaps a better way to handle the buffer system? [Edited by - Master Tonberry on January 21, 2005 6:55:19 PM]
_____________________________My open source shadow engine:http://www.mikaellagre.com/theroom/
The problem I think is with your video card. Make sure that VSync is turned off as well as all the goodies - such as AA, Tribilinear Filtering, all that good stuff for quality you use for Doom3 and HL2 [wink]. That should fix it.

- Drew
Advertisement
Hey that sure improved it! A lot! Thanx for the tip! :)
I do wonder what effect made my application so slow though. The settings on the graphic card was pretty much standard and comparable to the ATI card settings. And still... other OpenGL demos ( small demos not fully programmed games ) without the SDL wrapper did run smoothly.
I'll continue to experiment what settings made my application slow. :)

EDIT: It was "Wait for vertical sync" in the graphics card settings which I thought I already had set to off ... :D
_____________________________My open source shadow engine:http://www.mikaellagre.com/theroom/
Yeap attack of the darn VSync! Well compared to other pure OpenGL programs - SDL was not designed in the same way - so it was probabally choking with all of the graphics instructions where as the Windows apps can handle them fine. Just an idea.

- Drew

This topic is closed to new replies.

Advertisement