Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a 2d game I've made using openGL ES. The game contains a large quad that fills the entire screen (as a background image) and many smaller quads that make up a number of balls that bounce across the screen.

To illustrate displaying a ball, I may have a single quad with vertices (0,0),(0,1),(1,1),(1,0). I then fill this quad with a texture (a colored ball).

I am wondering if I need to perform back-face culling (for performance reasons). Given, these 4 vertices, I assume a polygon is drawn to connect them. Is it actually the case that two polygons are drawn? One facing forward and another one facing the back? I'm struggling to understand.

I have tried getting face culling working and I think I've succeeded, but I've not really noticed any difference in rendering times.

Not sure if relevant, but here is my environment setup code

gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glViewport(0, 0, width, height);
gl.glLoadIdentity();
gl.glMatrixMode (GL10.GL_PROJECTION);
gl.glLoadIdentity ();
gl.glOrthof(0, width, height, 0, 0, 1);
gl.glMatrixMode (GL10.GL_MODELVIEW);
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Back face culling is typically used to prevent the drawing of polygons to the screen that are facing away from the camera. For example, if one were to draw a complex three dimensional object to the screen, many of the polygons on the model may not even be visible and culling them will prevent the rendering time of these non-visible polygons. The "face" aka visible side of the polygon is determined by the order in which you specify the vertices. Polygons usually only have one face. In a program you might say

glFrontFace( GL_CCW );
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);

This would mean you are going to specify the vertices of your polygons in counter clock wise order, culling the polygons facing away from the camera. Based on the description of your program, it does not sound like you need to enable culling. As long as you are consistent with the ordering of your vertices for your polygons, your two dimensional program should not need culling. As for the question of whether two sides are being drawn, the front and back, no they are not.

share|improve this answer
add comment

If you draw one quad, only one quad is being drawn. You don't need back-face culling for your situation.

Back-face culling is used in 3d graphics as an optimization. For example, if you're drawing a cube, your code would draw 6 quads (one for each side of the cube). However, on screen, there will only be 3 sides ever visible at one time. The other 3 sides will be behind the 3 that you see.

You can use back-face culling to tell OpenGL to only draw the 3 sides that are facing towards the camera. That way you can keep your cube-drawing code simple — always draw 6 quads — but let the system only draw the ones that face the camera. To make this work you have to orient the vertices consistently and tell OpenGL which orientation you're using (see user7679's answer).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.