Hi I am trying to draw a smooth anti alias line in this project I'm working on.
I've implemented a line smoothing algorithm that takes place after the line is drawn, view in simulator so far works great.
However on my ipod touch they still appear jaggy and aliased. What is the proper way to draw an antialias line in opengl-es ( whichever version the ipod touch has )
Is this correct:
-(void) draw
{
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// line stuff
glLineWidth(1.5);
glEnable (GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
int i = 0;
for (Boat* boat in _boats)
{
PointOnPath* firstPointOnPath = (PointOnPath*) [boat._path objectAtIndex:0];
CGPoint start = firstPointOnPath.position;
// Set the color and draw
glColor4f(0.784, 0.02f, 0.341f, 0.9f);
for(PointOnPath* path in boat._path)
{
CGPoint vertices[2];
vertices[0] = start;
vertices[1] = path.position;
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_LINES, 0, 2);
start = path.position;
}
i++;
}
// restore default GL states
glColor4f(1.0, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
Also just in case anyone wants to use it - this is the line smoothing algorithm in objective-c that i implemented (taken from an AS3 one) takes an array of points as the parameter
+(NSMutableArray*) smoothPoints:(NSMutableArray*)points
{
int len = [points count];
int minAmount = 5;
NSMutableArray* smoothedPoints = [NSMutableArray arrayWithCapacity: len];
if(len < minAmount) return points;
int j = 0;
int i = len;
int smoothingAverage = 5;
while (i--)
{
PointOnPath* currentPoint = [points objectAtIndex:i];
if( i == len - 1 || i == len - 2 || i == 1 || i == 0) {
[ smoothedPoints addObject: currentPoint ];
} else {
j = minAmount;
CGPoint average = ccp(0.0f, 0.0f);
while (j--)
{
PointOnPath* futurePoint = (PointOnPath*) [points objectAtIndex: i + 2 - j];
average.x += futurePoint.position.x;
average.y += futurePoint.position.y;
}
average.x /= (float) smoothingAverage;
average.y /= (float) smoothingAverage;
PointOnPath* clone = [[PointOnPath alloc] initWithCGPoint: ccp( (currentPoint.position.x + average.x) * 0.5f , (currentPoint.position.y + average.y) * 0.5f )
withTime:currentPoint.time];
[smoothedPoints addObject: clone];
[clone release];
}
}
return smoothedPoints;
}
As a final note, i just noticed i'm not calling '[super draw]' on my scene, yet it's still being drawn - which is what I want, but im wondering how its being drawn if i didn't call super.