Sign in to follow this  
lazE

OpenGL Optimizations for a newbie like me

Recommended Posts

Hey, I am coming dangerously close to finishing my first OpenGL project and I am pretty happy about it. The problem is that everything is sooo slow even on really good hardware. My scene is pretty much just a large heightmap-based terrain stored in a vertex buffer and a couple of 3DS files loaded based on the tut at gametutorials.com with a single ambient light. The use can control the movement of a hovercraft and shoot at other hovercraft so theres a certain amount of physics going on here. The 3DS files are pretty slow to render as theyre done one vertex at a time. Ideally I could implement some simple algos that dont require me to entirely rewrite that whole class... I was thinking something along the lines of having a distance check from my character to other objects/terrain strips and if theyre too far away I wouldnt render them. However, I would be seeting this distance to be my far plane and Im not even sure if not making the render to things outside of the far plane will even do anything for me. Can someone shed smoe light on this? Thanks.

Share this post


Link to post
Share on other sites
Let us know about the polygon counts of the terrain and the objects and your system specs. How many hardware lights are there in the scene, what is the size of the world and of the view frustum, are you doing any frustum culling?

Secondly, are you using Vertex buffers for the objects too?

Try disabling various components (physics, ai, objects rendering) and check where the FPS varies most.

Share this post


Link to post
Share on other sites
Quote:
Original post by lazE
Hey,

I am coming dangerously close to finishing my first OpenGL project and I am pretty happy about it. The problem is that everything is sooo slow even on really good hardware.

My scene is pretty much just a large heightmap-based terrain stored in a vertex buffer and a couple of 3DS files loaded based on the tut at gametutorials.com with a single ambient light. The use can control the movement of a hovercraft and shoot at other hovercraft so theres a certain amount of physics going on here.

The 3DS files are pretty slow to render as theyre done one vertex at a time. Ideally I could implement some simple algos that dont require me to entirely rewrite that whole class...

I was thinking something along the lines of having a distance check from my character to other objects/terrain strips and if theyre too far away I wouldnt render them. However, I would be seeting this distance to be my far plane and Im not even sure if not making the render to things outside of the far plane will even do anything for me. Can someone shed smoe light on this?

Thanks.


I'm currently working on terrain myself. Currently I use Vertex arrays, but I might change to display lists. Also, I implemented nodetree(I actually used a quad tree instead of an oct tree) to render the terrain so it doesn't render what it doesn't see and the performance increased drastically. I went from 17 FPS to around 47 FPS. If you still have performance problems, you may want to space out vertices in your terrain a little farther.

Share this post


Link to post
Share on other sites
You using any techiniques to time different parts of the program then?

Partitioning space so it only bothers to try and render what's in the viewport would be a bonus if it's rendering everything all the time.

Share this post


Link to post
Share on other sites
Quote:
Original post by lazE
The 3DS files are pretty slow to render as theyre done one vertex at a time.

That's your problem right there. The more calls you make to OpenGL, the slower your program will be. Look into vertex arrays.

Share this post


Link to post
Share on other sites
joanusdmentia got a strong point, that is a very uneffective way of rendering, need to minimalize the number of drawcalls per frame. And as stated by others, if you can avoid it, not rendering things that cannot bee seen can cause dramatic speedups if that is your bottleneck. Both these issues are in teh same category, bring the amount of drawbatches and batchsizes as small as possible.

Other things that are very expensive operations and can bring any hardware combination down on its knees are context and texture switches. These should be kept to a absolute minimum.

However where you really should start is attaching a profiler to your program and see where you spend your time. AMD Codeanalyst is free so atleast worth a try.

Share this post


Link to post
Share on other sites
About to run to class so I don't have time to play with the profiler but, I will definitely try that.

I implemented a distance check so that I only render objects that are within the farplane of the perspective. This really improved my FPS by alot (Im above 30 now) but, the simple fact is that for what I have on screen any pro it shouldnt be that low.

I will definitely look into changing my code to use vertex arrays instead of vertices for the 3DS files. Rather than changing the tutorial at gametutorials.com I will probably opt for rewriting the code myself based on the file format information thats available on the web.

Also, a few of the above posters mentioned algorithms for improving the rendering of my terrain. As I metioned, I am using vertex arrays for the terrain and doing it one strip at a time. I'm going to take a wild guess here and assume that any algo I use to render less of the terrain will involve a switch from using strips to using regular triangles or at the very least smaller strips...can I get some more information on that?

Thanks.

Share this post


Link to post
Share on other sites
For the record, Max files are NOT designed for use in games. They usually have higher poly counts than you need. Check out a simpler format such as MD2 which only has features you can implement in realtime.

As for your problem, at least use vertex arrays. Some other forms of compiled lists might help your frame rate.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this