Jump to content
  • Advertisement
Sign in to follow this  
Andrew1979

OpenGL graphics rendering problem

This topic is 3716 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

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

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!