Speed improvements

Started by
6 comments, last by Demosthenes 21 years, 5 months ago
Hi. I want to improve the speed of this code: it's supposed to draw a planet, but it's already getting to slow for only 6 planets on screen at the same time. Suggestions?
  
        glPushMatrix();

	glRotatef(-90, 1.0f, 0.0f, 0.0f);

	glRotatef(pos_ang.x, 1.0f, 0.0f, 0.0f);	
	glRotatef(pos_ang.y, 0.0f, 0.0f, 1.0f);	
	glRotatef(pos_ang.z, 0.0f, 1.0f, 0.0f);

	glRotatef(rot_ang, 0.0f, 0.0f, 1.0f);	

	glDisable(GL_BLEND);		
	glEnable(GL_DEPTH_TEST);
	glBindTexture(GL_TEXTURE_2D, surface_texture);		
	gluSphere(surface_obj, r, SPHERE_PRECISION, SPHERE_PRECISION);

	glPopMatrix();

	glPushMatrix();

	if(cloud_texture != NULL)
	{
		glRotatef(-90, 1.0f, 0.0f, 0.0f);

		glRotatef(cloud_pos_ang.x, 1.0f, 0.0f, 0.0f);	
		glRotatef(cloud_pos_ang.y, 0.0f, 0.0f, 1.0f);	
		glRotatef(cloud_pos_ang.z, 0.0f, 1.0f, 0.0f);

		glRotatef(cloud_rot_ang, 0.0f, 0.0f, 1.0f);	

		glDisable(GL_DEPTH_TEST);	
		glEnable(GL_BLEND);		
		glBindTexture(GL_TEXTURE_2D, cloud_texture);		
		gluSphere(cloud_obj, r + 0.035f, SPHERE_PRECISION, SPHERE_PRECISION);
	}

	glPopMatrix();

	rot_ang += rot_speed;
	if(rot_ang > 360) rot_ang -= 360.0f;
	if(rot_ang < 360) rot_ang += 360.0f;

	cloud_rot_ang += cloud_rot_speed;
	if(cloud_rot_ang > 360) cloud_rot_ang -= 360.0f;
	if(cloud_rot_ang < 360) cloud_rot_ang += 360.0f;
   
[edited by - Demosthenes on November 5, 2002 2:01:16 PM]
Advertisement
I''m lazy and have to get up early tomorrow, so I''m not going to give you any specific code... But from what I see, it looks like you''re changing states a bit more than you could be. You''ve got several glEnable()''s, glDisable()''s, and glBindTexture()''s in there, and if it goes through this chunk of code for every planet then you might want to think about a way to lump together all the planets so you don''t change states and textures quite as much (does that even make sense?). Also, while I don''t know how efficient GLUT is, maybe using a display list for the planet ''model'' would speed things up a bit (but for all I know, that''s exaclty what GLUT does... ). Just some thoughts.

--Buzzy
Thanks.

I will draw the cloud textures together, to change the blending state only once.

As for Glut, I don''t even know what it is, what I know about OpenGL I learned from the first seven NEHE tutorials... But I''ll find out.
how often do you call this piece of code
i get 70 fps which 15900 polygons when i use glbindtexture glbegin glend for every polygon i have been too lazy to port my map format to vertex arrays :D
http://www.8ung.at/basiror/theironcross.html
That call to gluSphere will recalculcate the sphere geomatry every time. Put it in a display list at init time (or several if you need planets with different tesselation levels) and my guess is you''ll see a major speed up. Just compile the list once and then just glCallLists in the display function.
Basiror: I call it every frame. I only noticed slow-downs while scrolling.

I've just implemented the display lists and the scrolling slowndown dimished. Thanks.

I have another problem, though: I have a planet surface texture, and a cloud texture, that I draw over the planet. But if I try to draw all cloud textures after all the planets are drawn, so that I can change to "blending mode" only once, no cloud is drawn. Any clue?

[edited by - Demosthenes on November 6, 2002 5:10:12 PM]
Make sure that all the translations are done right for all the planets. I''d guess somethings not transforming right...
quote: Make sure that all the translations are done right for all the planets. I''d guess somethings not transforming right...


Yep. I forgot I was doing translations between the drawing of planets. It''s working now, and much faster.

This topic is closed to new replies.

Advertisement