PDA

View Full Version : Simple Sphere and Cube



Zath
06-09-2006, 10:25 AM
Ok, total newbie here (well, when it comes to openGL. But can code well in other languages.)

I've decided to expand my knowledge and want to simply draw a sphere and a cube.

As you can see with my code below, I have played around with the teapot :D

But, would like them to be speres.

void paint () {

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glTranslatef (0, 0, -5);
glRotatef (degree, 0, 1, 0);
brass(); //change color
glutSolidTeapot (1);

glPushMatrix();
glRotatef (degree, 0, 1, 0);
glTranslatef (0, 0, -5);
silver(); //change color
glutSolidTeapot (1);

glPushMatrix();
glRotatef (degree, 0, 1, 0);
glTranslatef (0, 0, -5);
glutSolidTeapot (1);
glPopMatrix();

glPopMatrix();

glPopMatrix();

glFlush();

glutSwapBuffers();
degree += 0.1f;
glutPostRedisplay();

}

For the sphere, I'm kinda stuck....

gluSphere(1,1,1,1);
// cannot convert parameter 1 from int to GLUquadric

Just want to change the teapots to spheres.
I have never come across the term GLUquadric and have tried to look it up.

Then maybe next change them to cubes?

Thanks all for your indulgence while I get going on this so cool technology.

Although it's been about 4 years since I did any C++.

BTW, I'm using VS.Net 2003 if that makes a difference.

Zath

Zath
06-09-2006, 01:10 PM
Nevermind everyone.

I found it.

glPushMatrix();
glDisable(GL_TEXTURE_2D); // Ballhack has no textures
glDisable(GL_DEPTH_TEST); // Makes the Balls visible through walls
GLUquadricObj *ball;
glColor3f(0.0f,0.0f,1.0f); // Set Ballhack Color
glTranslatef(0,0,-4); // insert coordinates here
ball=gluNewQuadric();
gluQuadricNormals(ball, GLU_SMOOTH);
gluSphere(ball,5.0f,32,32);
gluDeleteQuadric(ball);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glPopMatrix();

I had to add the include and understand a bit more about quadric.....

Sorry for the simple question....

Zath

06-11-2006, 09:31 PM
I'm sure you realized this, but it wasn't clear from your code. You can create a single sphere and reuse it repeatedly for rendering.

Also consider generating your own sphere, manually. It's a good exercise and it'll come in handy later for other things. Same for cylinders, boxes, tetrahedrons and so on. Know your solids, I always say. You can create a single unit scale version of each basic shape, then simply scale, rotate and translate it as needed for each actor in your scene.

Best of luck to you!