Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL ES iPhone - drawing anti aliased lines

Normally, you'd use something like:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH);  glLineWidth(2.0f);  glVertexPointer(2, GL_FLOAT, 0, points); glEnableClientState(GL_VERTEX_ARRAY);  glDrawArrays(GL_LINE_STRIP, 0, num_points);  glDisableClientState(GL_VERTEX_ARRAY); 

It looks good in the iPhone simulator, but on the iPhone the lines get extremely thin and w/o any anti aliasing.

How do you get AA on iPhone?

like image 558
quano Avatar asked Nov 28 '09 16:11

quano


2 Answers

One can achieve the effect of anti aliasing very cheaply using vertices with opacity 0. Here's an image example to explain:

alt text

Comparison with AA:

alt text

You can read a paper about this here:

http://research.microsoft.com/en-us/um/people/hoppe/overdraw.pdf

You could do something along this way:

// Colors is a pointer to unsigned bytes (4 per color). // Should alternate in opacity. glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors); glEnableClientState(GL_COLOR_ARRAY);  // points is a pointer to floats (2 per vertex) glVertexPointer(2, GL_FLOAT, 0, points); glEnableClientState(GL_VERTEX_ARRAY);  glDrawArrays(GL_TRIANGLE_STRIP, 0, points_count);  glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); 
like image 131
quano Avatar answered Oct 05 '22 12:10

quano


Starting in iOS Version 4.0 you have an easy solution, it's now possible to use Antialiasing for the whole OpenGL ES scene with just a few lines of added code. (And nearly no performance loss, at least on the SGX GPU).

For the code please read the following Apple Dev-Forum Thread. There are also some sample pictures how it looks for me on my blog.

like image 42
Bersaelor Avatar answered Oct 05 '22 14:10

Bersaelor