Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

SIMPLE OpenGL rendering question?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Tyler B   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 July 2011 - 10:02 PM

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

Sponsor:

#2 josiahpeters   Members   -  Reputation: 102

Like
1Likes
Like

Posted 25 July 2011 - 11:38 PM

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 hidden surface determination to get an idea of some of the more common algorithms.

#3 Tyler B   Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 July 2011 - 09:17 AM

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!

#4 zacaj   Members   -  Reputation: 571

Like
0Likes
Like

Posted 26 July 2011 - 09:34 AM

You might want to look into frustum culling, most likely by area instead of by single cubes, since cubes are pretty simple

#5 kunos   Members   -  Reputation: 1307

Like
1Likes
Like

Posted 26 July 2011 - 10:39 AM

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
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#6 Tyler B   Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 July 2011 - 08:17 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS