# 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 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 on other sites
Quote:
 Original post by lazEHey, 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 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 on other sites
Quote:
 Original post by lazEThe 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 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 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 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.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627684
• Total Posts
2978627
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 9
• 14
• 12
• 10
• 12