- 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)
{
glPushMatrix();
glTranslatef( x,y,z );
gluSphere(quadric, radius, subdivisions,subdivisions);
glPopMatrix();
}
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);
renderSphere(x,y,z,radius,subdivisions,quadric);
gluDeleteQuadric(quadric);
}
SHARE