Very Basic OpenGL ES problem

Discussion in 'iOS Programming' started by Soulstorm, May 6, 2009.

  1. macrumors 68000


    Feb 1, 2005
    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:

    - (void)drawView {
    	[EAGLContext setCurrentContext:context];
    	glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    	glViewport(0, 0, backingWidth, backingHeight);
    	glOrthof(-100.0f, 100.0f, -150.0f, 150.0f, -100.0f, 100.0f);
    	static GLfloat rotation = 0.0f;
    	glRotatef(rotation, 0.0f, 1.0f, 0.0f);
    	rotation += 1.0f;
    	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    	const GLfloat squareVertices[] = {
    		-50.0f, -50.0f, -1.0f,
    		50.0f,  -50.0f,	-1.0f,
    		-50.0f,  50.0f, -1.0f,
    		50.0f,   50.0f, -1.0f,
    	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
    	glVertexPointer(3, GL_FLOAT, 0, squareVertices);
    	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    	const GLubyte squareColors[] = {
            255, 255,   0, 255,
            255, 255,   0, 255,
            0,     0,   0,   0,
            255,   0, 255, 255,
    	glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
    	const GLfloat squareVertices2[] = {
    		-40.0f, -40.0f, -12.0f,
    		40.0f,  -40.0f, -12.0f,
    		-40.0f,  40.0f, -12.0f,
    		40.0f,   40.0f, -12.0f,
    	glVertexPointer(3, GL_FLOAT, 0, squareVertices2);
    	glDrawArrays(GL_TRIANGLE_STRIP,0, 4);
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
        [context presentRenderbuffer:GL_RENDERBUFFER_OES];
    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?
  2. macrumors 6502a

    Sep 3, 2005
    Cramlington, UK
    Did you create your framebuffer with a z buffer?

    ß e n

Share This Page