How to Render a Sphere With Glusphere

Shares & Saves

Open Graphics Library, or OpenGL, is a computer graphics application programming interface (API) used to render two-dimensional and three-dimensional computer graphic images. It can be implemented on a variety of computer platforms and programming languages. OpenGL is used for video game development and scientific visualization. OpenGL does not offer a direct method of sphere rendering, but it does offer the "Glusphere" function, which draws a sphere of the given radius centered around the origin. To create a sphere, you will code a series of lines, calculate the sin and cosine values necessary to create the sphere, and then implement glusphere in the code.


  1. Launch the OpenGL Viewport window.

  2. Type the following code to provide the sine and cosine functions needed to calculate the circle:

    include <math.h>
  3. Type the following code to render a sphere with glusphere:

    void renderSphere(float x, float y, float z, float radius,int subdivisions,GLUquadricObj *quadric)



    glTranslatef( x,y,z );

    gluSphere(quadric, radius, subdivisions,subdivisions);



    void renderSphere_convenient(float x, float y, float z, float radius,int subdivisions)


    //the same quadric can be re-used for drawing many spheres

    GLUquadricObj *quadric=gluNewQuadric();

    gluQuadricNormals(quadric, GLU_SMOOTH);






Read Article

8 iPhone Tips Everyone Should Know