Jump to content

  • Log In with Google      Sign In   
  • Create Account


Simple graphics running very slow


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 July 2011 - 11:13 AM

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

Sponsor:

#2 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 July 2011 - 12:08 PM

Any suggestions ????

#3 JTippetts   Moderators   -  Reputation: 8161

Like
0Likes
Like

Posted 06 July 2011 - 12:11 PM

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.

#4 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 July 2011 - 12:33 PM

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 :)

#5 gsamour   Members   -  Reputation: 140

Like
0Likes
Like

Posted 06 July 2011 - 12:47 PM

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?

#6 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 July 2011 - 12:53 PM

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

#7 cstony   Members   -  Reputation: 304

Like
0Likes
Like

Posted 06 July 2011 - 12:54 PM

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 :)

#8 gsamour   Members   -  Reputation: 140

Like
0Likes
Like

Posted 06 July 2011 - 12:59 PM

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?)

#9 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 July 2011 - 01:13 PM

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.

#10 SuperVGA   Members   -  Reputation: 1118

Like
0Likes
Like

Posted 06 July 2011 - 01:16 PM

Are you certain that you don't have an expensive fragment shader enabled? That would explain the obvious decrease in performance with larger quads...

#11 gsamour   Members   -  Reputation: 140

Like
0Likes
Like

Posted 06 July 2011 - 01:20 PM

What happens if you don't draw the player? What is the fps then? Drawing a tiny square doesn't always mean higher fps ;)

EDIT: phrased in a better way -> "drawing a tiny square can mean low fps sometimes"

#12 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 July 2011 - 01:24 PM

When I remove a map drawing part of code :


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 );
}



It runs ok , so the problem is in the map drawing.

#13 gsamour   Members   -  Reputation: 140

Like
0Likes
Like

Posted 06 July 2011 - 01:32 PM

What is your game's target resolution? And what is map.bmp's width and height?

#14 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 July 2011 - 01:38 PM

Window : 640x480
Bitmap : 512x512( RGB )

#15 gsamour   Members   -  Reputation: 140

Like
0Likes
Like

Posted 06 July 2011 - 02:09 PM

Any way you can share your code via download? If not, here's more questions/requests...

Can you post your loadTexture() function?
Are you using shaders at all? (doesn't look like it)

#16 Waterlimon   Crossbones+   -  Reputation: 2382

Like
0Likes
Like

Posted 06 July 2011 - 02:13 PM

Try drawing triangles instead of quads?

Waterlimon (imagine this is handwritten please)


#17 holtaf   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 July 2011 - 01:40 AM

Ok here is my whole code. ( No i'm not using any shaders );
game.tar.gz






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS