PDA

View Full Version : Sphere Question



newmannium
03-01-2001, 01:07 PM
Can someone tell me how to draw a sphere
if I have the data like this:

8 /* 8 triangles */

3 /* each has 3 points */
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
1.000000 0.000000 0.000000

...

Thank you very much!

Gavin
03-02-2001, 02:15 AM
Do you mean how to draw a geodesic type sphere using recursion?

gav

pleopard
03-02-2001, 07:15 AM
Use the GLU library, I don't have time to explain so here is some example code, good luck ... hope it helps...

#include <glu.h>
...

GLUquadricObj* p_Quadric = gluNewQuadric();

...

switch(drawMode)
{
case Points:
gluQuadricDrawStyle(p_Quadric,GLU_POINT);
break;
case Textured:
case Shaded:
gluQuadricDrawStyle(p_Quadric,GLU_FILL);
break;
case WireFrame:
gluQuadricDrawStyle(p_Quadric,GLU_LINE);
break;
}

...


if (drawMode==Textured)
{
glPushAttrib(GL_ENABLE_BIT);
glEnable(GL_TEXTURE_2D);
glPushMatrix();
gluQuadricDrawStyle(p_Quadric,GLU_FILL);
gluQuadricTexture(p_Quadric,GL_TRUE);
glPushAttrib(GL_TEXTURE_BIT);
m_Texture.bind();
gluSphere(p_Quadric,0.50f,m_NumSlices,m_NumStacks) ;
glPopAttrib();
glPopMatrix();
glPopAttrib();
}
else
{
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
gluSphere(p_Quadric,0.50f,m_NumSlices,m_NumStacks) ;
glPopAttrib();
}

pleopard
03-02-2001, 07:18 AM
Oops, add the following to cleanup ...

gluDeleteQuadric(p_Quadric);