OpenGL drawing system

Hi, I’ want to know when an object is drawn outside the viewport if openGL does still draw it anyway, or ignores it?


I have a viewport of
Left: -200
Right: 200
Top: -200
Bottom: 200

and an object out of this bounds does it still draws?


and an object out of this bounds does it still draws?

Define “draws”? In general, fragments generated outside of the viewport are still ignored. However, the triangles will still have to go through all of the vertex processing before clipping.

In general, you should try not to draw too much stuff outside the viewport. But you shouldn’t try culling at the level of triangles. Just do a viewport test to see if the object as a whole is at least partially in view before drawing it.

Yes, thats what I want to chekc if a triangle is inside the viewport, but how can I do that?

the viewport coordinates are just a reference, not global coordinates, I want to check for each object I have if its inside the viewport, and drawing only the ones that are

thks again

project the points of the triangle by the modelview then projection matrix, then test against the 6 clipping planes

Yes I understand, I only don’t know how to make that, I’m still knowing the opengl commands

And won’t that consume much more cpu that letting opengl draw them outside the viewport?

because I’m using a list of objects, and I need to check each one to draw them, if I also need to do that checking, won’t it consume much more of cpu?


You need to look up “frustum culling” for this. The general theory is - as Alfonse said - that you don’t cull on the level of triangles. Instead you take groups of triangles - say a model of something, or each object on your list - and cull on that level.

Yes, it does consume some extra CPU, but it’s a tradeoff versus consuming extra GPU resources, and more often than not that tradeoff is worth it. Even Quake did this, so it’s been a known-good technique for almost 15 years.

Mmh, Quake did this because this was mandatory for performance on a software rasterizer …
Now a GPU can eat a lot of triangles, so do not spend too much time culling few triangles. Instead cull complex objects with simple tests.
Measure rendering time with and without culling, to verify assumptions are correct.

google on the subjects. Some cull is still useful, even in the days of modern GPUs. Of course, you’ll have to bench on a variety of hw to be sure.

Look first at AABB-frustum tests.