Tony, here is an updated code, thought I would post it here also. I will also e-mail this newest version to you.
Has a wire cube, inside the wire cube is a solid cube, colid cone. No cylinder at this time ,just wanted to use glut. later can replace all with glu privitive.
keyboard commands:
[ESC] key quits program
“W” stop/starts wire cube
“S” stop/starts solid cube
“C” stop/starts solid cone
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
GLfloat wire_cube, solid_cube, solid_cone; // store objects current rotation
static int wire_cube_rotate = 1, solid_cube_rotate = 1, solid_cone_rotate = 1; // store state; 0= no rotation, 1 = rotation
void Sprint( int x, int y, char *st)
{
int l,i;
l=strlen( st );
glRasterPos2i( x, y);
for( i=0; i < l; i++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, st[i]);
}
}
static void TimeEvent(int te)
{
int timent;
int i;
glutPostRedisplay();
glutTimerFunc( 100, TimeEvent, 1);
}
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1, 1.0, 50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();// Draw small solid cube
glColor3f(0.0, 1.0, 1.0); // give it a color
glTranslatef( -3.0, 0.0, -20.0); //move it into our our view.
if (solid_cube_rotate == 1) solid_cube++;
if (solid_cube > 360) solid_cube = 0; // check for rotation pass 360, and reset if above.
glRotatef(solid_cube, 0.0, 0.0, 1.0); // rotate on z-axis
glutSolidCube(2.0);
glPopMatrix();
glPushMatrix(); // Draw small solid cone…I stuck with all glut primitives, but later we can replace all with glu primitives.
glColor3f(1.0, 0.0, 1.0);
glTranslatef( 3.0, -1.0, -20.0);
if (solid_cone_rotate == 1) solid_cone++;
if (solid_cone > 360) solid_cone = 0;
glRotatef(solid_cone, 0.0, 0.0, 1.0);
glRotatef(90.0, 0.0, 1.0, 0.0);
glutSolidCone(2.0, 2, 8, 8);
glPopMatrix();
glPushMatrix(); // Draw large wire cube
glColor3f(1.0, 1.0, 1.0);
glTranslatef( 0.0, 0.0, -20.0);
if (wire_cube_rotate == 1) wire_cube++;
if (wire_cube > 360) wire_cube = 0;
glRotatef(wire_cube, 0.0, 0.0, 1.0);
glRotatef(wire_cube, 0.0, 1.0, 0.0);
glutWireCube(10.0);
glPopMatrix();
// easy way to put text on the screen.
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5.0, 5.0, 5.0, -5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0, 0.5, 0.5);
Sprint(-1, -1, “OpenGL” );
glutSwapBuffers();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(60.0,(GLfloat) w/(GLfloat) h, 1.0, 50.0);
}
void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case ‘W’:
wire_cube_rotate = abs( wire_cube_rotate - 1); // Toggle rotate on off.
break;
case ‘S’:
solid_cube_rotate = abs( solid_cube_rotate - 1); // Toggle rotate on off.
break;
case ‘C’:
solid_cone_rotate = abs( solid_cone_rotate - 1); // Toggle rotate on off.
break;
case 27:
exit(0); // exit program when [ESC] key presseed
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (10, 10);
glutCreateWindow (argv[0]);
glutSetWindowTitle(“Mike”);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutTimerFunc( 10, TimeEvent, 1);
glutMainLoop();
return 0;
}