I'm having some problems porting my D3D code to OpenGL ES. I have a Graphics Device class that encapsulates all rendering commands. The code below is in an ObjC++ file.

The problem code is the called to get the render buffer width and height. It doesn't actually return any value in the w or h GLints.

It should be noted that the code below is from an older iPhone project, and it works there. Am I missing something really stupid?

Checking the framebuffer status returns a value of complete, since OpenGL ES seems quite happy to initialize a depth buffer with the garbage w and h values I pass to it!

bool GraphicsDevice::Initialize(id<EAGLDrawable> eaglLayer)  
   EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
   if(context == nil)
      return false;

   [EAGLContext setCurrentContext:context];

   this->eaglContext = context;

   glGenFramebuffers(1, &frameBuffer);
   glBindBuffer(GL_FRAMEBUFFER, frameBuffer);
   glGenRenderbuffers(1, &renderBuffer);
   glBindBuffer(GL_RENDERBUFFER, renderBuffer);
   [eaglContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer];

   GLint w, h;
   glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &w);
   glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &h);

   SetWidth(static_cast<unsigned int>(w));
   SetHeight(static_cast<unsigned int>(h));

  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,    renderBuffer);

   glGenRenderbuffers(1, &depthBuffer);
   glBindBuffer(GL_RENDERBUFFER, depthBuffer);
   glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, w, h);

   glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);

   GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
      System::Log("Framebuffer not complete");
      return false;

   return true;

2 Answers 2


In the book "iPhone 3D Programming" there are examples of this. The author uses the OES extensions. Like

glGenRenderbuffersOES(1, &m_renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_renderbuffer);


glGenFramebuffersOES(1, &m_framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_framebuffer);

I've tested these commands:

GLint w, h;

and the width and height are correct.

You can download the book examples here

See the "HelloArrow" project. Within the class RenderingEngine1

  • \$\begingroup\$ Thanks for the reply, Those functions are ES1 only. I came back to my issue a couple of days ago and discovered that some legacy code was still trying to create a framebuffer with my UIView. \$\endgroup\$
    – Neil M
    Jun 12, 2011 at 15:01

I was trying to create a framebuffer from an EAGLLayer that already had a framebuffer created from it. I don't know why OpenGL ES was saying the framebuffer was complete and not setting an error right away, but there you have it.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .