title: OpenGL ES 2.0 lines appear more jagged than Core Animation. Is anti-aliasing possible in iOS 4?
body: <p>Is there a relatively simple way to implement anti-aliasing on <strong>iOS 4</strong> using <strong>OpenGL ES 2.0</strong>?</p>
  
  <p>Had a situation where I needed to abandon <strong>Core Animation</strong> in favor of <strong>OpenGL ES 2.0</strong> to get true <strong>3d</strong> graphics.</p>
  
  <p>Things work but I've noticed that simple <strong>3d</strong> cubes rendered using <strong>Core Animation</strong> are much crisper than those produced with <strong>OpenGL</strong> which have more jagged lines.</p>
  
  <p>I read that <strong>iOS 4.0</strong> supports <strong>anti-aliasing</strong> for <strong>GL_TRIANGLE_STRIP</strong>, and I found an <strong><a href="http://www.gandogames.com/2010/07/tutorial-using-anti-aliasing-msaa-in-the-iphone/" rel="nofollow">online tutorial</a></strong> (see below for code from link) that looked promising, but I have not been able to get it working.</p>
  
  <p>First thing I noticed was all the <strong>OES</strong> suffixes which appear to be a remnant of <strong>Open GL ES 1.0</strong>.</p>
  
  <p>Since everything I've done is for <strong>OpenGL ES 2.0</strong>, I tried removing every <strong>OES</strong> just to see what happened. Things compiled and built with zero errors or warnings but my graphics were no longer rendering.</p>
  
  <p>If I keep the <strong>OES</strong> suffixes I get several errors and warnings of the following types:</p>
  
  <pre><code>Error - Use of undeclared identifier ''
  Warning - Implicit declaration of function '' is invalid in C99
  </code></pre>
  
  <p>Including the <strong>ES1</strong> header files resulted in a clean build but still nothing got rendered. Doesn't seem like I should need to include <strong>ES 1.0</strong> header files to implement this functionality anyways.</p>
  
  <p><strong>So my question is how do I get this to work, and will it actually address my issue?</strong></p>
  
  <p>Does the approach in the online tutorial I linked have the right idea, and I just messed up the implementation, or is there a better method?</p>
  
  <p><strong>Any guidance or details would be greatly appreciated.</strong></p>
  
  <hr>
  
  <p>Code from link above:</p>
  
  <pre><code>GLint backingWidth, backingHeight;
  
  //Buffer definitions for the view.
  GLuint viewRenderbuffer, viewFramebuffer;
  
  //Buffer definitions for the MSAA
  GLuint msaaFramebuffer, msaaRenderBuffer, msaaDepthBuffer;
  
  
  
  //Create our viewFrame and render Buffers.
  glGenFramebuffersOES(1, &amp;amp;viewFramebuffer);
  glGenRenderbuffersOES(1, &amp;amp;viewRenderbuffer);
  
  //Bind the buffers.
  glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
  glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
  [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
  glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
  glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &amp;amp;backingWidth);
  glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &amp;amp;backingHeight);
  
  
  
  //Generate our MSAA Frame and Render buffers
  glGenFramebuffersOES(1, &amp;amp;msaaFramebuffer);
  glGenRenderbuffersOES(1, &amp;amp;msaaRenderBuffer);
  
  //Bind our MSAA buffers
  glBindFramebufferOES(GL_FRAMEBUFFER_OES, msaaFramebuffer);
  glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaRenderBuffer);
  
  // Generate the msaaDepthBuffer.
  // 4 will be the number of pixels that the MSAA buffer will use in order to make one pixel on the render buffer.
  glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, 4, GL_RGB5_A1_OES, backingWidth, backingHeight);
  glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, msaaRenderBuffer);
  glGenRenderbuffersOES(1, &amp;amp;msaaDepthBuffer);
  
  //Bind the msaa depth buffer.
  glBindRenderbufferOES(GL_RENDERBUFFER_OES, msaaDepthBuffer);
  glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, 4, GL_DEPTH_COMPONENT16_OES, backingWidth , backingHeight);
  glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, msaaDepthBuffer);
  
  
  
  - (void) draw
  {
      [EAGLContext setCurrentContext:context];
      //
      // Do your drawing here
      //
      // Apple (and the khronos group) encourages you to discard depth
      // render buffer contents whenever is possible
      GLenum attachments[] = {GL_DEPTH_ATTACHMENT_OES};
      glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 1, attachments);
  
      //Bind both MSAA and View FrameBuffers.
      glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, msaaFramebuffer);
      glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, viewFramebuffer);
  
      // Call a resolve to combine both buffers
      glResolveMultisampleFramebufferAPPLE();
  
      // Present final image to screen
      glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
      [context presentRenderbuffer:GL_RENDERBUFFER_OES];
  }
  </code></pre>