Sign in to follow this  
mavvie

SIMPLE OpenGL rendering question?

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
Could you post some code on how you are rendering the blocks?

Are you drawing each vertex separately like below?


[code]
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[/code]


If so you could speed your framerate by looking into [url="http://nehe.gamedev.net/tutorial/vertex_buffer_objects/22002/"]Vertex Buffered Objects[/url].

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

Share this post


Link to post
Share on other sites
[quote name='josiahpeters' timestamp='1311658701' post='4840387']
Could you post some code on how you are rendering the blocks?

Are you drawing each vertex separately like below?


[code]
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[/code]



If so you could speed your framerate by looking into [url="http://nehe.gamedev.net/tutorial/vertex_buffer_objects/22002/"]Vertex Buffered Objects[/url].
[/quote]

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!

Share this post


Link to post
Share on other sites
You might want to look into frustum culling, most likely by area instead of by single cubes, since cubes are pretty simple

Share this post


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

Share this post


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

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