3

I'm using drawing a glDrawArrays to draw a GL_LINE_STRIP and want to make them smooth. I've seen on a couple questions here people recommend using glEnable(GL_LINE_SMOOTH) and glHint(GL_LINE_SMOOTH_HINT, GL_NICEST), but when I do so, I'm getting an error. Here's my code:

- (void)setupGL
{
    [EAGLContext setCurrentContext:self.context];

    self.effect = [[[GLKBaseEffect alloc] init] autorelease];
    self.effect.light0.enabled = GL_FALSE;
    self.effect.light1.enabled = GL_FALSE;
    self.effect.light2.enabled = GL_FALSE;
    self.effect.lightModelAmbientColor = GLKVector4Make(0.0f, 0.0f, 0.0f, 1.0f);

    glDisable(GL_DEPTH_TEST);
//    glEnable(GL_LINE_SMOOTH);
//    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glGenVertexArraysOES(1, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);

    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_DYNAMIC_DRAW);

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, VERTEX_POS_DATA_SIZE, GL_FLOAT, GL_FALSE, VERTEX_DATA_SIZE * sizeof(GLfloat), BUFFER_OFFSET(0));

    glEnableVertexAttribArray(GLKVertexAttribColor);
    glVertexAttribPointer(GLKVertexAttribColor, VERTEX_COLOR_DATA_SIZE, GL_FLOAT, GL_FLOAT, VERTEX_DATA_SIZE * sizeof(GLfloat), BUFFER_OFFSET(VERTEX_POS_DATA_SIZE * sizeof(GLfloat)));    

    glLineWidth(10.0);
}

If I uncomment either (or both) of those lines, I get a GL ERROR. Any thoughts?

prplehaze
  • 459
  • 4
  • 15
  • 4
    I'm pretty sure `GL_LINE_SMOOTH` is not supported on the iOS OpenGL ES implementation. You might have to find another way to do antialiasing for your lines. – Brad Larson May 18 '12 at 22:26

1 Answers1

0

I had that working (well!) with an ES1.1 context, i.e.

self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

I'm writing new code and trying to ride the wave of the future (or at least, the now-recent past) and jump to ES2.0. In the 2.0 universe, I have had moderate success with

view.drawableMultisample = GLKViewDrawableMultisample4X;

set in my GLKViewController's -viewDidLoad override, set on my GLKView. YMMV.

Ben Mosher
  • 13,251
  • 7
  • 69
  • 80