SIMPLE OpenGL rendering question?

Started by
4 comments, last by mavvie 12 years, 8 months ago
Hey all :)
This is my first post :o

Basically I have created a large (1K+ line) program using OpenGL that works just fine, and I'm working on a game engine.
However before I even consider games, I have a large problem. Creating models works fine, I understand texture mapping (but I'm not doing it--just glColor3f()), but if I create an array of 1000 cubes and then a person shape that is half inside the cubes, framerate gets messed up. If I move the camera out a distance, I get solid 64FPS, but when I zoom in (fly right over the cubes and person) the framerate drops to about 10....I have no idea how to fix this problem, and I also don't know what the problem is exactly.

Is the problem rendering 1000 blocks even though the final render only shows about 100-200? (How can I fix this problem?)

or is the problem rendering a person then rendering cubes that cover half the body? (I could probably fix this myself by adding a game engine to prevent falling/force staying on top of the blocks...)

Thanks in advance for any replies :)
Advertisement
Could you post some code on how you are rendering the blocks?

Are you drawing each vertex separately like below?



glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle



If so you could speed your framerate by looking into Vertex Buffered Objects.

If you are already doing VBOs try looking at this Wikipedia article on [font=sans-serif][size=2]hidden surface determination to get an idea of some of the more common algorithms.[/font]

Could you post some code on how you are rendering the blocks?

Are you drawing each vertex separately like below?



glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle




If so you could speed your framerate by looking into Vertex Buffered Objects.


Thanks for the reply sir :)
I checked the code and indeed I am drawing each vertex separately...I have a function DrawCube()...
But i still don't understand why the framerate is fine everywhere I move except when I move near a few blocks on the far left side...
Should I attach the .exe or just source code?
Either way I'll incorporate Vertex Buffered Object and update you :)

Thanks again!
You might want to look into frustum culling, most likely by area instead of by single cubes, since cubes are pretty simple
it doesnt look like a vertices problem to me.. more like a fragment problem, by zooming in more screen space is actually written.

what card and driver are you using?

even 64 is pretty slow for 1000 cubes

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

thanks for all the replies, i've made changes and it works great:

z-buffering, vertex arrays/indices/glDrawElements() for cube drawing, and general optimization.

and it is noted that my laptop's graphics card is shitty and games will likely run better on desktops :P

This topic is closed to new replies.

Advertisement