Hi all,
I’m new to SDL, and somewhat newish with OpenGL. Heres my question…
I’m getting about 60 fps when rotating a 500 polygon textured object.
This is on a P4 HT 2.53 GHz with a Geforce 4 MX 440 card.
I should be getting way more than that, shouldn’t I?
Also, fsaa doesn’t seem to work at all…
Thanks in advance for your help!
Here is my core display loop…
int RunGLTest( int argc, char* argv[],
int logo, int slowly, int bpp, float gamma, int noframe,
int fsaa )
{
int i;
int rgb_size[3];
int w = 640;
int h = 480;
int done = 0;
int frames;
Uint32 start_time, this_time;
Uint32 video_flags;
int value;
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
exit( 1 );
}
/* See if we should detect the display depth */
if ( bpp == 0 )
{
if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 )
{
bpp = 8;
} else
{
bpp = 16; /* More doesn't seem to work */
}
}
bpp = 0 ;
/* Set the flags we want to use for setting the video mode */
if ( logo && USE_DEPRECATED_OPENGLBLIT )
{
video_flags = SDL_OPENGLBLIT;
} else
{
video_flags = SDL_OPENGL;
}
video_flags |= SDL_OPENGLBLIT ;
for ( i=1; argv[i]; ++i )
{
if ( strcmp(argv[1], "-fullscreen") == 0 )
{
video_flags |= SDL_FULLSCREEN;
}
}
if (noframe)
{
video_flags |= SDL_NOFRAME;
}
video_flags |= SDL_HWSURFACE;
video_flags |= SDL_HWPALETTE ;
video_flags |= SDL_HWACCEL ;
/* Initialize the display */
switch (bpp)
{
case 8:
rgb_size[0] = 3;
rgb_size[1] = 3;
rgb_size[2] = 2;
break;
case 15:
case 16:
rgb_size[0] = 5;
rgb_size[1] = 5;
rgb_size[2] = 5;
break;
default:
rgb_size[0] = 8;
rgb_size[1] = 8;
rgb_size[2] = 8;
break;
}
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if ( fsaa )
{
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, fsaa );
}
if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL )
{
fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
printf("Screen BPP: %d\n",
SDL_GetVideoSurface()->format->BitsPerPixel);
printf("\n");
printf( “Vendor : %s\n”, glGetString( GL_VENDOR ) );
printf( “Renderer : %s\n”, glGetString( GL_RENDERER ) );
printf( “Version : %s\n”, glGetString( GL_VERSION ) );
printf( “Extensions : %s\n”, glGetString( GL_EXTENSIONS ) );
printf("\n");
SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n",
rgb_size[1],value);
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
if ( fsaa )
{
SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &value );
printf( "SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n",
value );
SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &value );
printf( “SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n”,
fsaa, value );
}
/* Set the window manager title bar */
SDL_WM_SetCaption( "SDL GL test", "testgl" );
/* Set the gamma for the window */
if ( gamma != 0.0 )
{
SDL_SetGamma(gamma, gamma, gamma);
}
glEnable( GL_DEPTH_TEST );
glClearColor(0.0, 0.0, 0.2, 0.0); // This clear the background
color to dark blue
glShadeModel(GL_SMOOTH); // Type of shading for the polygons
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon
rasterization mode (polygon filled)
glEnable(GL_TEXTURE_2D); // This Enable the Texture mapping
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// FOV // Ratio // The farthest distance
before it stops drawing
perspectiveGL(45.0f,(GLfloat)w/(GLfloat)h, .5f ,5000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
unsigned long totalpolys = 0 ;
for(int x = 0; x < MAX_OBJECTS; x++)
{
cLoad3DS my3ds(&object[x], "spaceship.3ds",
“spaceshiptexture.bmp”);
if(object[x].valid == false)
{
MessageBox(NULL,“Object not loaded”, “Error”,MB_OK |
MB_ICONERROR);
return 0 ;
}
totalpolys += object[x].polygons_qty ;
}
printf("Total polygons: %ld\n", totalpolys) ;
/* Loop until done. */
start_time = SDL_GetTicks();
frames = 0;
// Absolute rotation values (0-359 degrees) and rotation increments
for each frame
// double rotation_x=0, rotation_x_increment=0.1;
// double rotation_y=0, rotation_y_increment=0.05;
// double rotation_z=0, rotation_z_increment=0.03;
double rotation_x=0, rotation_x_increment=0.5;
double rotation_y=0, rotation_y_increment=0.25;
double rotation_z=0, rotation_z_increment=0.15;
GLuint displaylist ;
displaylist = glGenLists(1) ;
glNewList(displaylist, GL_COMPILE) ;
for(int x = 0; x < MAX_OBJECTS; x++)
{
glBindTexture(GL_TEXTURE_2D, object[x].id_texture); // We set
the active texture
object[x].Draw(true) ;
}
glEndList() ;
glMatrixMode(GL_MODELVIEW); // Modeling transformation
glLoadIdentity(); // Initialize the model matrix as identity
glTranslatef(0.0,0.0,-600); // We move the object forward (the
model matrix is multiplied by the translation matrix)
rotation_x = rotation_x + rotation_x_increment;
rotation_y = rotation_y + rotation_y_increment;
rotation_z = rotation_z + rotation_z_increment;
while( !done )
{
GLenum gl_error;
char* sdl_error;
SDL_Event event;
/* Do our drawing, too. */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This
clear the background color to dark blue
// glMatrixMode(GL_MODELVIEW); // Modeling transformation
// glLoadIdentity(); // Initialize the model matrix as identity
// glTranslatef(0.0,0.0,-300); // We move the object forward (the
model matrix is multiplied by the translation matrix)
// rotation_x = rotation_x + rotation_x_increment;
// rotation_y = rotation_y + rotation_y_increment;
// rotation_z = rotation_z + rotation_z_increment;
if (rotation_x > 359) rotation_x = 0;
if (rotation_y > 359) rotation_y = 0;
if (rotation_z > 359) rotation_z = 0;
glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object
(the model matrix is multiplied by the rotation matrices)
glRotatef(rotation_y,0.0,1.0,0.0);
glRotatef(rotation_z,0.0,0.0,1.0);
glCallList(displaylist) ;
SDL_GL_SwapBuffers();
/* Check if there's a pending event. */
while( SDL_PollEvent( &event ) )
{
done = HandleEvent(&event);
}
++frames;
this_time = SDL_GetTicks();
if ( this_time >= start_time + 500)
{
static char name[1024] ;
sprintf(name, "SDL GL test [polys: %ld fps: %5.2f]",
totalpolys,((float)frames/(this_time-start_time))*1000.0);
start_time = this_time ;
frames = 0 ;
SDL_WM_SetCaption( name, "testgl" );
printf("%s\n", name) ;
}
}
/* Print out the frames per second */
this_time = SDL_GetTicks();
if ( this_time != start_time )
{
printf("%2.2f FPS\n",
((float)frames/(this_time-start_time))*1000.0);
}
if ( global_image )
{
SDL_FreeSurface(global_image);
global_image = NULL;
}
if ( global_texture )
{
glDeleteTextures( 1, &global_texture );
global_texture = 0;
}
/* Destroy our GL context, etc. */
SDL_Quit( );
return(0);
}