I want to draw a sphere, I know how to do it in OpenGL using calls such as glBegin() & glEnd().
But there is nothing in ES.
Suggestions/Tutorial links?
I want to draw a sphere, I know how to do it in OpenGL using calls such as glBegin() & glEnd().
But there is nothing in ES.
Suggestions/Tutorial links?
Since you've tagged this with OpenGL ES 2.0, let me suggest an alternative approach for creating smooth spheres, and that's to draw them as raytraced impostors. Rather than calculate the many vertices you'll need to replicate a smooth sphere, you can take advantage of the fact that a sphere looks pretty much the same from any angle.
To do this, you employ a process like the following:
You send four vertices that represent two triangles to a vertex shader, which then displaces them to create a square that always faces the user. Within that square, you use a fragment shader to raster over each pixel and provide the color that a sphere would have at that point if you were viewing it through this square window.
The advantage of this approach is that the sphere is as smooth as the resolution of your display supports, and the sphere will easily scale from small to large without requiring any recalculation of your geometry. It does shift the burden for rendering from the vertex processor to the fragment processor, but for a single sphere that's not much of a problem on the OpenGL ES 2.0 devices I've worked with.
I use this technique in this iOS application, for which the source code is available on that page, and talk about it a little more here. A simplified version of the vertex shader I use looks something like this:
and the simplified fragment shader is this:
The current optimized versions of these shaders are a little harder to follow, and I also use ambient occlusion lighting, which is not present with these. Also not shown is texturing of this sphere, which can be done with a proper mapping function to translate between sphere surface coordinates and a rectangular texture. This is how I provide precalculated ambient occlusion values for the surfaces of my spheres.
People visiting above thread can have a look at link provided bellow to create various kind of shapes including "Sphere" in OpenGLES2.0.
https://github.com/regar007/ShapesInOpenGLES2.0
The class implementation of shapes makes it very easy to integrates with your code.
Instantiate the object and use render function to draw the object.