🔒 Locked
graphics rendering problem
Advertisement
Original Post
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
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]
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:
What improvements could I make to the above to help prevent the severe slow down that I'm getting?
Thank you in advance.
Andrew
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 functionWhat improvements could I make to the above to help prevent the severe slow down that I'm getting?
Thank you in advance.
Andrew
hexmax, could you explain in a bit more detail? I'm still fairly new to OpenGL.
Thank you.
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.
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.
is there anyway I can speed up rendering using existing OpenGL commands such as glVertex3f?
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.
There should be a number of tutorials around the web on display lists.
Display lists sound like the way to go, the only object in the game scene that moves is the game object which at the moment is incredibly slow in that it barely moves (you have to wait about 5 secs before any movement). Remove the game scene and just leave the object and it rotates and translates with no problem.
Quote:
Original post by Andrew1979
the game object which at the moment is incredibly slow in that it barely moves (you have to wait about 5 secs before any movement). Remove the game scene and just leave the object and it rotates and translates with no problem.
You see, even though you're using an inefficient way to render things currently I don't think it should be this bad. I suspect that either you're rendering in software mode (with no hardware acceleration), your drivers need updating, or that one/some of those functions you call from the scene rendering code are very costly.
It's all fine and well looking to optimise things when your program runs slow, but you need to know what to optimise. glIntercept may shed some light on the issue (though I've never actually used it), and also any other general program profiler you may have handy.
One thing I would definitely try: Since you know that it's the scene rendering slowing things down, try to find out if it's one specific aspect of the scene, like maybe it's the generateFullTree() function for example.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement