PDA

View Full Version : how to smooth out a line in iphone openGL



jayanth
11-25-2009, 06:14 AM
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...

Mikael Korpela
11-25-2009, 07:31 AM
it is indeed GL_LINE_SMOOTH not SMOOTH_LINE as in your code box.

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

AdrianPi
11-25-2009, 09:30 PM
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

Pierre Boudier
11-26-2009, 02:14 PM
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)