Reputation: 135
What is the best way to draw circles with OpenGL ES 2.0?
I am working on an iPad/iPhone project using cocos2d 2.0 (currently beta) which uses OpenGL ES 2.0 and shaders instead of OpenGL ES 1.0.
In my former projects I used that handy class ColoredCircleSprite that is included in the SneakyInput package. But now with OpenGL ES 2.0 that code is not working anymore and to be honest I am a little lost here in writing my own solution from scratch. I need a CCSprite subclass that draws smooth circles. (Perhaps with a little shadow shader...)
Should I build a rectangular shape in the vertex shader and then discard every pixel outside the circle radius in the fragment shader? Or should I build the circle vertices inside the vertex shader?
Are there any good tutorials about this topic on the net? As OpenGL-n00b I would appreciate every kind of help!
Upvotes: 2
Views: 2386
Reputation: 64477
Use ccDrawCircle:
ccDrawCircle(CGPoint center, float radius, float angle,
NSUInteger segments, BOOL drawLineToCenter);
Increase the number of segments to make the circle smoother. Have a look at the implementation of ccDrawCircle in CCDrawingPrimitives.h if you want to learn from the code.
Upvotes: 2