0

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?

D.Cole
  • 27
  • 10

1 Answers1

0

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.
ClayMontgomery
  • 2,786
  • 1
  • 15
  • 14
  • thanks, I tried using the second method using texture coordinates. I copied the vertex and fragment shaders from Brad Larsons' answer found here: http://stackoverflow.com/questions/11452729/how-do-i-draw-a-filled-circle-with-opengl-es-on-iphone?answertab=votes#tab-top however the circle is only drawing in one of the triangles of my quad, any ideas? – D.Cole Jul 19 '13 at 09:49
  • There is probably an error in your vertices or texture coordinates. If you build the quad with a triangle fan, it should look like this: GLfloat Positions[] = {-1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f,}; GLfloat TexCoords[] = {0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f}; glDrawArrays(GL_TRIANGLE_FAN, 0, 4); – ClayMontgomery Jul 19 '13 at 16:11
  • Thankyou, it was a problem with my texture coordinates, its working fine now. – D.Cole Jul 21 '13 at 16:31