How to draw circle on OpenGL ES 2.0 cross platform

2019-09-16 22:06发布

问题:

Ive been teaching myself to program on openGL ES 2.0 for the past 2 weeks however I am struggling to draw certain objects. I am using Mosync to do my coding in as I can programme for all platforms. So far I have written a programme to draw a triangle and another to draw a square. Im looking for a way to draw a circle, I know I have do define the centre, radius, angle and resolution but I dont know how to go about making it work.

Can I draw the circle straight from draw() or do I have to define the vertices of a square and use the fragment shader to only colour the pixels in a circle shape?

回答1:

There are 3 common ways to draw a circle in OpenGL ES:

  1. Use a single Triangle Fan, where the first vertex is at the center of your circle. The more points you supply, the higher quality the circle will be (tessellation level).
  2. Use a texture which contains an image of a circle and map that to a pair of triangles (a quad).
  3. Use a point sprite.