Simple OpenGL ES problem - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Simple OpenGL ES problem (/thread-1337.html)
Simple OpenGL ES problem - soulstorm - May 6, 2009 03:48 AM
I am trying to do some basic OpenGL ES with my iPhone, but I have some problems doing so. In my Xcode, I have created a new OpenGL ES based application project and I have changed the drawView function in the EAGLView.m file to look like this:
Although I can get my two rotating squares, when the rotation is 180 degrees, the smaller square still seems to be in front of the bigger one, but this should not happen... I know the answer is simple but I can't find it! I have already enabled GL_DEPTH_TEST as you can see. The same thing happens if I try setting the z value of the smaller square to something else (like a positive value).
Can anyone help?
Simple OpenGL ES problem - AnotherJake - May 6, 2009 07:19 AM
You need to enable the depth buffer (you'll find this at the top of EAGLView.m):
#define USE_DEPTH_BUFFER 1
And you need to clear it every frame (do this in drawView):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Simple OpenGL ES problem - soulstorm - May 14, 2009 12:36 PM
Yes, that was indeed simple. Sorry for wasting your time.
Simple OpenGL ES problem - AnotherJake - May 14, 2009 03:53 PM
No problem, it is often very easy to miss simple details, especially when learning OpenGL.