Jump to content
  • Advertisement
Sign in to follow this  
UnIXbLueStar

OpenGL Processing only triangles in viewport

This topic is 3644 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I bought a OpenGL 2.0 book. I already knew about glPerspective, glFrustum and glClipPane. Tho they said that with glPerspective and glFrustum, the polygons outside the viewport aren't drawn. Here is my problem. I have a terrain of (256 * 256) * 2 triangles. I put it in a display list. Even with glPerspective, glFrustum, i get the same lag when there is 2 triangle in my viewport than if they were all there. I tried glClipPane to cut the left and right of the viewport.. still lag with only 2 triangles in the viewport. OpenGL keep lagging just like if he was drawing them. So whats the point in clipping the triangles outside the viewport ? My old algorithm was to draw the only vertex approximatively viewable in the viewport with a width range and height range. But that involved some math, and doing 2 loop to redraw the part of the map every game loop. It was a way better on the performance though. Is there a way to draw only parts of a display list ? If not why would i use a display list for a terrain if i only need to show parts of it ? Was my old algorithm the way to do it ? If not, what is the best way ? P.S: my game work in a Diablo II like view. We view terrain from top, with a little perspective angle. The camera always point in the same axis. The camera can move but will always point about 10 unit in X positive.

Share this post


Link to post
Share on other sites
Advertisement
The OpenGL implementation checks every polygon you send to it against your view frustum in order to determine which fragments actually fill your screen.

You're requesting that 256*256*2=131,702 polygons get drawn. Each point of each triangle is tested against your frustum by the implementation: that's a lot of data that needs to be processed. So how can you fix this? It's doubtful that you'll come up with a faster way to test each single triangle that the OpenGL implementation: it's like accelerated in hardware, and if the hardware isn't available then OpenGL is already processing it in software (probably quite efficiently for software, too).

I would recommend you break up your 256*256 into smaller segments (such as in a quadtree, or perhaps just a simple grid) in order to determine which segments are viewable at any given time. This way you can perform very fast tests to determine if an entire segment is not visible and avoid sending it down the graphics pipeline and thus preventing the more costly per-vertex frustum testing.

Share this post


Link to post
Share on other sites
So my old algorithm was the way to do it ?
i have the whole grid in a 2 dimension array.

I determine the X range and Y range and then do somehting like this

for (int x = viewx; x < viewx + xrange; x++)
{
for (int y = viewy; y < viewy + yrange; y++)
{
...
gl.glVertex3f(vertexArray[x][y], ... ...);
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!