how to smooth out a line in iphone openGL

Hi all,

I am an absolute openGL beginner. I am learning iphone game programming using cocoa and openGL . Using the below function I did draw a slanted line successfully.
static const GLfloat squareVertices[] = {
        -0.50f, -0.33f,
		-0.55f, -0.38f,
    };
.....
.....
.....

glLineWidth(2.0);
    // Draw
glDrawArrays(GL_LINE_STRIP, 0, 2);

I did draw a line successfully. But it is not smooth. I tried some google and got the following antialiasing methods and inserted the below given line before glDrawArray() in the code above.

glEnable(GL_SMOOTH_LINE)

But when I tried to build I am getting an error.

error : GL_LINE_SMOOTH undeclared.

Can anyone help me…

it is indeed GL_LINE_SMOOTH not SMOOTH_LINE as in your code box.

I take it you are using opengl es 1.x ?

Not sure how is on iPhone, but traditionally you also need to enable blending and set it to alpha blending to use line smoothing.

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);

Same for point smoothing

hi,

I think that you need to emulate this feature:

  • draw two triangles (a quad) instead of a line
  • make sure that your quad has the correct end cap (perpandicular to line)
  • compute texture coordinate to generate s orthogonal to the line direction
  • make sure that your texture coordinate is correctly interpolated (linear, not perspective correct).
  • bind a ramp texture to emulate the smooth in alpha
  • fetch that texture in your shader (or setup fixed function state)