Jump to content
  • Advertisement
Sign in to follow this  
HalcyonX

problem with display lists

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I posted this on the NeHe forum, but the response rate there is quite slow, so ill post it here too. For some reason, display lists are slowing down my application rather than speeding things up, even though they are only being created once (not on-the-fly). If i run my app just by straight drawing the polygons, i get ~105 fps. With display lists enabled, however, things slow down to ~28. The display lists are only created once during the drawing of the first. I am keeping a Hashtable where the key is my object's id, and value what glGenLists() returns. During each call to my drawing method, i check to see if the object's id is in the Hashtable. If it is, i just call glCallList() on the value in the Hashtable. Otherwise, i create the display list and print some output to screen, telling me its creating a new list, and then call the list. When i run the app, the "creating display list" messages only print once, so im sure that im only creating the lists once. No where else in my code are display lists created. Yet, the fps is so much lower. Can anyone help? Below is the code of my drawing function. It takes a data structure containing the object that i want to draw, and draws it. BTW, im using C# for its portability and ease of use. So... hope u guys know C#. =P
public bool drawObject(GameObject obj) 
{
	// Used for loops
	Polygon currentPolygon;
	Vertex currentVert;

	if (obj.GetType().IsSubclassOf(typeof(Creature)))
	{
		foreach (Component part in ((Creature)(obj)).components)
		{
			drawObject(part);
		}
	}
	else
	{
		if (displayLists[obj.objectID] == null)
		{
			game.print("creating display list for " + obj.objectID);
			int list = Gl.glGenLists(1);

			Gl.glNewList(list, Gl.GL_COMPILE);

			// loop through all polygons of OBJ
			for (int i = 0; i < obj.model.polygons.Length; i++)
			{
				currentPolygon = obj.model.polygons;

				Gl.glColor4f(currentPolygon.color.r, currentPolygon.color.g, currentPolygon.color.b, currentPolygon.color.a);

				// Check to see that the current bound texture isnt already
				// the one we want.
				if (!currentTexture.Equals(currentPolygon.texName))
				{
					if (!loadTexture(currentPolygon.texName))
					{
						return false;
					}
					Gl.glBindTexture(Gl.GL_TEXTURE_2D, (int) textures[currentPolygon.texName]);
					currentTexture = currentPolygon.texName;
				}

				switch (currentPolygon.verticies.Length)
				{
					case 3:
						Gl.glBegin(Gl.GL_TRIANGLES);
						break;
					case 4:
						Gl.glBegin(Gl.GL_QUADS);
						break;
					default:
						Gl.glBegin(Gl.GL_POLYGON);
						break;
				}

				Gl.glNormal3f(currentPolygon.normal.x, currentPolygon.normal.y, currentPolygon.normal.z);
				
				for (int vertI = 0; vertI < currentPolygon.verticies.Length; vertI++)
				{
					currentVert = currentPolygon.verticies[vertI];

					if (currentVert.texCoords != null)
					{
						Gl.glTexCoord2f(currentVert.texCoords.x, currentVert.texCoords.y);
					}
					Gl.glVertex3f(currentVert.x, currentVert.y, currentVert.z);
				}

				Gl.glEnd();
			}

			Gl.glEndList();

			displayLists.Add(obj.objectID, list);
		}

		// Reset view
		Gl.glLoadIdentity();
		
		float x = game.camera.chaseObject.position.x;
		float y = game.camera.chaseObject.position.y;
		float z = game.camera.chaseObject.position.z;

		Glu.gluLookAt(x + game.camera.xMod, coolGame.Utilities.Util.forceIntoRange(y + game.camera.yMod, 0.01, double.MaxValue), z + game.camera.zMod, x, y, z, 0, 1, 0);

		// Translate and rotate according to OBJ's position and angle
		Gl.glTranslatef(obj.position.x, obj.position.y, obj.position.z);
		Gl.glRotatef(obj.angle.y, 0, 1, 0);
		Gl.glRotatef(obj.angle.x, 1, 0, 0);
		Gl.glRotatef(obj.angle.z, 0, 0, 1);
		
		// call display list to do the drawing
		Gl.glCallList((int)displayLists[obj.objectID]);
	}

	return true;
}


Share this post


Link to post
Share on other sites
Advertisement
oh gosh im such a n00b... cant believe i did that... hah. It loads the texture if it hasnt been loaded yet. That explains quite a few things.. haha. Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!