Results 1 to 4 of 4

Thread: OpenGL es sphere tutorial

  1. #1
    Junior Member
    Join Date
    Oct 2011

    OpenGL es sphere tutorial


    I am pretty new to opengl es. Recently, I figured out how to create a circle in opengl-es 1.x. I really wnat to create sphere, but I am not really sure how to. Is there any tutorial out there that anyone could point me to?

    Would you make a sphere using only triangle_strips, or triangle strips and triangle_fans for the poles?

    Also, I am trying to make this for android.

    Many thanks in advance.


  2. #2

    Re: OpenGL es sphere tutorial

    I wanted to try this openGL, It will be great if there is no more need of plug ins. Hoping to find tutorials on this too. Thanks.

  3. #3

    Re: OpenGL es sphere tutorial

    There is no specific API for this. You have to draw using existing calls only.
    However, You can draw sphere by using polar coordinates of circle.

    GLfloat vertices[720];
    for (int i = 0; i < 720; i += 2) {
    // x value
    vertices[i] = (cos(DEGREES_TO_RADIANS(i/2)) * 0.4); // x=r *cos(theta)
    // y value
    vertices[i+1] = (sin(DEGREES_TO_RADIANS(i/2)) * 0.6);// y= r*sin(theta)
    glVertexAttribPointer(0,2, GL_FLOAT, GL_FALSE, 0, vertices);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 360);

  4. #4

    Re: OpenGL es sphere tutorial

    Drawing a sphere in opengl es 1/2 is quite difficult . First of all there is no built in function for this and secondly you have to draw using basic primitives only viz. triangle,point,line.

    Method mentioned by debinair is applicable for circles only. Sphere being a 3D object you need Z component as well.

    So you will need polar co-ordinates of sphere first of all. They are :

    Vertices[0]= r* sin(thita)*cos(fy);
    Vertices[1]= r*sin(thita)*sin(fy);
    Vertices[2]= r*cos(thita);

    Just like we had thita for a circle we have an additional "fy" here. It goes from 0 to pi radians. (And thita from 0 to 2*pi).

    Consider your sphere to be made up of slices , you have to draw each slice using above mentioned formula.
    Give it a shot I have already done it successfully.

Similar Threads

  1. A good to tutorial about OpenGL ES 2.0
    By VansFannel in forum OpenGL ES
    Replies: 0
    Last Post: 11-17-2010, 11:25 AM
  2. Problem with a sphere
    By Giacomo in forum OpenGL ES
    Replies: 11
    Last Post: 12-17-2005, 09:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean