Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back face culling + GL_TRIANGLE_STRIP?

Tags:

opengl

If I've got 4 vertices which I render in this order:

2-3
|\|
0-1

using GL_TRIANGLE_STRIP and then I enable back-face culling with the front face defined as CCW, then would the bottom-left triangle be facing me and the other one not? If so, what's the most efficient way of rendering a square so that both faces are visible? Do I have to use GL_TRIANGLES and pass down 6 vertices instead of 4?

like image 721
mpen Avatar asked Feb 05 '12 23:02

mpen


People also ask

What does back face culling do?

In computer graphics, back-face culling determines whether a polygon of a graphical object is drawn. It is a step in the graphical pipeline that tests whether the points in the polygon appear in clockwise or counter-clockwise order when projected onto the screen.

How do you implement back face culling in OpenGL?

To enable face culling we only have to enable OpenGL's GL_CULL_FACE option: glEnable (GL_CULL_FACE); From this point on, all the faces that are not front-faces are discarded (try flying inside the cube to see that all inner faces are indeed discarded).

What is front face culling?

Face culling allows non-visible triangles of closed surfaces to be removed before expensive Rasterization and Fragment Shader operations. To activate face culling, GL_CULL_FACE must first be enabled with glEnable. By default, face culling is disabled.

What is block face culling?

When making custom block models, you can run into an issue known as culling. This is when the adjacent blocks have their face(s) hidden to save on render time. If your block model does not take up the full 16x16 area, you will see holes in adjacent blocks.


2 Answers

The strip primitive does the right thing with respect to backface culling. You can think of the tris' winding order as being managed so that the order is consistent for each triangle in the strip - e.g. you can think of the GPU rendering (0,1,2), (2,1,3) ...

like image 124
moonshadow Avatar answered Oct 17 '22 02:10

moonshadow


All triangles in triangle strip maintain same direction/winding order. They don't flip one after another. So either both triangles will be towards you or away from you (assuming your primitive is flat square shape (that is convex and doesn't intersect itself) where all vertices belong to same plane).

P.S. You know, you COULD render trianglestrip primitive in OpenGL application with culling enabled and see for yourself.

like image 35
SigTerm Avatar answered Oct 17 '22 03:10

SigTerm