graphics rendering problem

Started by
10 comments, last by dmatter 15 years, 9 months ago
Hi I've written an OpenGL program that creates a game scene with a game object in it to move around. The problem is, is that the game object is incredibly slow to translate. When I remove the game scene graphics, the speed is fine. Is there anyway to overcome this problem? I posted a thread earlier but I don't think I explained the problem well enough. Thank you in advance for any suggestions. Andrew
Advertisement
You either need better drivers or you're doing something wrong.

If you post some relevant code then somebody here may be able to diagnose any issues with your program.
Off hand: Your other thread mentions textures, a common pitfall is to reload the textures from the harddrive every frame - you're not doing that at all?

By the by, creating multiple threads for the same issue is frowned upon, you might want to consider transferring anything pertinent from the other thread into this one and deleting that thread (edit the post and there's a delete tickbox) - The mods will certainly appreciate it. [smile]
Hi

Below is the code for my DrawGLScene in my OpenGL program:

nt DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing{	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer	glLoadIdentity();		glTranslatef(transX, transY, transZ);	// DRAW THE SKY //		// Bind the sky texture		glBindTexture(GL_TEXTURE_2D, texture[3]);		// Draw the sky dome		glPushMatrix();		glRotatef(-90,1,0,0);		glBegin(GL_TRIANGLE_STRIP);		for(int i = 0; i != NumVertices; i++)		{			glTexCoord2f(Vertices.u, Vertices.v);			glVertex3f(Vertices.x, Vertices.y, Vertices.z);		}			glEnd();		glPopMatrix();		// DRAW THE GROUND //		// Bind the grass texture	glBindTexture(GL_TEXTURE_2D, texture[0]);	/* Draw the ground */	glBegin(GL_QUADS);		for(int i = 0; i != MAX_FLOOR_TILES; i++)			floortileArray.createFloorTile();	glEnd();	// Bind texture used for boxes	glBindTexture(GL_TEXTURE_2D, texture[1]);		//  DRAW BOX CRATES  //		/* Draw Boxes on the ground */	glBegin(GL_QUADS);	// Draw 3 crates near side of ground	for(int i = 0; i != MAX_CRATES; i++)		nearCrate.CreateBox();	// Draw 3 crates far side of ground	for(int i = 0; i != MAX_CRATES; i++)		farCrate.CreateBox();	glEnd();	// DRAW THE TREES //		// Bind texture used for trees	glBindTexture(GL_TEXTURE_2D, texture[2]);		glBegin(GL_TRIANGLES);								// Start Drawing A Triangle	// Draw trees on the left hand side	for(int i = 0; i != MAX_TREES; i++)		leftTrees.generateFullTree();	// Draw right trees	for(int i = 0; i != MAX_TREES; i++)		rightTrees.generateFullTree();		glEnd();	 	// DRAW THE VAN //		glPushMatrix();	glTranslatef(vanTransX, vanTransY, vanTransZ);		glRotatef(vanXRot,1.0f,0.0f,0.0f);	glRotatef(vanYRot,0.0f,1.0f,0.0f);	glRotatef(vanZRot,0.0f,0.0f,1.0f);	glBegin(GL_QUADS);		myTransit.constructVan();	glEnd();	glPopMatrix();	glColor3f(1.0f, 1.0f, 1.0f);} // End of GLDrawScene function


What improvements could I make to the above to help prevent the severe slow down that I'm getting?

Thank you in advance.

Andrew
Avoid using opengl immediate mode. Use vertex buffer objects or the like instead.
Buggy Racer & Stuffhttp://programmingcorner.freaksolutions.com
hexmax, could you explain in a bit more detail? I'm still fairly new to OpenGL.

Thank you.
Using immediate mode in opengl (that is calls like glVertex3f and so on)
induces a bottleneck since the driver has to send commands to the hardware
for each drawing command you issue. Especially for models or objects containing
many vertices this results in a considerably low rendering performance.

By using vertex buffer objects the vertex data is sent to the hardware once and
can be drawn by using just a few commands.

Have a look at http://developer.nvidia.com/object/using_VBOs.html
This document should answer all your remaining questions.
Buggy Racer & Stuffhttp://programmingcorner.freaksolutions.com
is there anyway I can speed up rendering using existing OpenGL commands such as glVertex3f?

Look into display lists. They'll speed things up without requiring a whole rewrite of your rendering approach, as vertex arrays would. If any of your geometry is dynamic, though, you'll have no choice but to use VAs.
how do you mean if my geometry is dynamic?
If the stuff you're rendering (the geometry) doesn't change (i.e. is static), you'll be able to use display lists. For example, terrain is often static - you have roads, mountains etc that always stay in the same position. But if the terrain is dynamic - if you can punch holes in the mountains with a bomb, say - you'll need to be able to update it on the fly, which is prohibitive with display lists.

There should be a number of tutorials around the web on display lists.

This topic is closed to new replies.

Advertisement