Simple graphics running very slow

Started by
15 comments, last by holtaf 12 years, 9 months ago
Hi guys! I have some problems while trying to display some simple graphics( I am using OpenGL and c++ ).
I have this simple code :

glBegin( GL_QUADS );
glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
glEnd();



I want to apply texture on whole screen and It runs veeery slow( with 4~10 fps )! Whats the problem ???

Thanks in advice
-holtaf
Advertisement
Any suggestions ????
First step is to ensure your video card drivers are up-to-date and that you're not defaulting to OpenGL 1.1. Check the values returned for glGetString(GL_VENDOR), and glGetString(GL_VERSION). If you get something like "Microsoft Corp.", and "1.1.0" for vendor/version, you need to update drivers, since the default GL drivers on Windows are slooooow.
First : I'm running on GNU/Linux ( Ubuntu 10.10 );
Second : When I draw smaller quads it's running ok, with 30~40 fps;
Third : Thanks for reply :)
What do you mean you want to "apply texture to the whole screen" ? You mean draw ONE quad that covers the whole screen? Because from your next post it sounds like you're drawing many quads. Or what exactly are you doing? Can you post more code or the full drawing code?
Yes I want do draw one quad to whole screen. Sorry I can't post my whole code it's very big!

Yes I want do draw one quad to whole screen. Sorry I can't post my whole code it's very big!


We don't need your entire code, but an outline of the loop that runs every frame and your rendering function will help us to help you :)
Some suggestions:

1. check that you're not loading the texture every frame (or doing something every frame that can be done once in initialization)
2. check if the texture size is bigger than the desired quad size. If so, reduce it. (what size is the texture?)
Ok I'll post some code

Here is Initialization :

glEnable( GL_TEXTURE_2D );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );


glGenTextures( 16, &texture.m_textureIds[0] );


m_mapTextureId = texture.loadTexture( "map.bmp");
m_playerTextureId = texture.loadTexture( "player.bmp");




Here is render function


void Game::render(){

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

switch ( m_sceneId ) {

case SCENE_MENU :
//menu.render();
break;
case SCENE_GAME :
texture.setActiveTexture( m_mapTextureId );
map.draw();
texture.setActiveTexture( m_playerTextureId );
player.draw();
break;
}



glXSwapBuffers( m_pDisplay, m_Window );
}


And here is map.draw() function


void Map::draw() {
glPushMatrix();
glColor3f( 1.0, 1.0, 1.0 );
glBegin( GL_QUADS );
glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
glEnd();
glPopMatrix();
}




Note : texture.setActiveTexture( int ) is only binding the current texture, and you can avoid the player.draw() because it's draws a tiny square.
Are you certain that you don't have an expensive fragment shader enabled? That would explain the obvious decrease in performance with larger quads...

This topic is closed to new replies.

Advertisement