I'm drawing to draw a simple tile map just to test it. Here is the loop:
while(running)
{
SDL_Delay(10);
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
running = false;
}
Uint8 *keyboard = SDL_GetKeyState( NULL );
if( event.type = SDL_KEYDOWN )
{
if( keyboard[SDLK_ESCAPE] )
{
running = false;
}
}
}
video->beginRendering();
for( int y = 0; y < 24; y++ )
{
for( int x = 0; x < 32; x++ )
{
video->drawImage( tiles, Rect( 2*32, 32, 32, 32), Coord( x * 32, y * 32), Color(), 0 );
}
}
video->drawImage( img, Rect(0, 0, 24, 48), Coord( 100,100 ), Color( 255,255,255,255 ) );
video->endRendering();
}
Its only one layer of 32x32 tiles across a 1024x768 screen. When I lower the number of tiles per x/y to 5 it runs fine...but doing the whole screen runs less then a frame a second. How can I improve the frame rate? I think it might be because I'm drawing a quad instead of two triangles...which I'm not exactly sure how I would align the textures on two triangles.
void VideoDriver::drawImage( Image *image, Rect &src, Coord &dest, Color &color, int skew )
{
if(image == NULL)
return;
float texX1 = src.x / (float)image->getWidth();
float texY1 = src.y / (float)image->getHeight();
float texX2 = (src.x + src.width) / (float)image->getWidth();
float texY2 = (src.y + src.height) / (float)image->getHeight();
glBindTexture( GL_TEXTURE_2D, image->getTexture() );
glEnable( GL_TEXTURE_2D );
glBegin( GL_QUADS );
glColor4ub( color.r, color.g, color.b, color.a );
glTexCoord2f( texX1, texY1 );
glVertex3f( dest.x + skew, dest.y + (+skew / 2), 0 );
glTexCoord2f( texX2, texY1 );
glVertex3f( dest.x + src.width + skew, dest.y + (+skew / 2 ), 0 );
glTexCoord2f( texX2, texY2 );
glVertex3f( dest.x + src.width, dest.y + src.height, 0 );
glTexCoord2f( texX1, texY2 );
glVertex3f( dest.x, dest.y + src.height, 0 );
glEnd();
}