problem with 2 rotating cubes

hello,
i am new hear. my name is michael and i am programming visual feedback for a neurofeedback (braintraining) software. brainwaves are measured with an eeg machine, the software ( bioexplorer) sends the values via tcp/ip to my little programm. i am still beginner, especially with opengl. the first version had two rotating cubes and it worked fine. now i want to have more rotating cubes and problems start. i can draw them and they turn, but if there are more then 2 cubes the lower two cubes turn always in the same direction and at the same speed, although they should turn seperately. any help would be appreciated, here the code:
rquad1 += rot1;
rquad2 -= rot2;
rquad3 += rot3;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-10.0f);	                    // Move Right 1.5 Units And Into The Screen 7.0
    glRotatef(rquad1,0.0f,1.0f,0.0f);					// Rotate The Quad On The X axis ( NEW )
    glBegin(GL_QUADS);									// Draw A Quad

	glColor3f(col1*1.0f, col1*1.0f, col1*1.0f);
	glVertex3f( 6.0f, 4.0f,-1.0f);					// Top Right Of The Quad (Top)
	glVertex3f(-6.0f, 4.0f,-1.0f);					// Top Left Of The Quad (Top)
	glVertex3f(-6.0f, 4.0f, 1.0f);					// Bottom Left Of The Quad (Top)
	glVertex3f( 6.0f, 4.0f, 1.0f);					// Bottom Right Of The Quad (Top)
	glColor3f(col1 * 1.0f, col1 * 1.0f, col1 * 1.0f);						// Set The Color To Orange
	glVertex3f( 6.0f, 3.0f, 1.0f);					// Top Right Of The Quad (Bottom)
	glVertex3f(-6.0f, 3.0f, 1.0f);					// Top Left Of The Quad (Bottom)
	glVertex3f(-6.0f, 3.0f,-1.0f);					// Bottom Left Of The Quad (Bottom)
	glVertex3f( 6.0f, 3.0f,-1.0f);					// Bottom Right Of The Quad (Bottom)
	glColor3f(col1 * 1.0f, col1 * 1.0f, col1 * 1.0f);						// Set The Color To Red
	glVertex3f( 6.0f, 4.0f, 1.0f);					// Top Right Of The Quad (Front)
	glVertex3f(-6.0f, 4.0f, 1.0f);					// Top Left Of The Quad (Front)
	glVertex3f(-6.0f,3.0f, 1.0f);					// Bottom Left Of The Quad (Front)
	glVertex3f( 6.0f,3.0f, 1.0f);					// Bottom Right Of The Quad (Front)
	glColor3f(col1 * 1.0f, col1 * 1.0f, col1 * 1.0f);						// Set The Color To Yellow
	glVertex3f( 6.0f,3.0f,-1.0f);					// Top Right Of The Quad (Back)
	glVertex3f(-6.0f,3.0f,-1.0f);					// Top Left Of The Quad (Back)
	glVertex3f(-6.0f, 3.0f,-1.0f);					// Bottom Left Of The Quad (Back)
	glVertex3f( 6.0f, 3.0f,-1.0f);					// Bottom Right Of The Quad (Back)
	glColor3f(col1 * 1.0f, col1 * 1.0f, col1 * 1.0f);						// Set The Color To Blue
	glVertex3f(-6.0f, 4.0f, 1.0f);					// Top Right Of The Quad (Left)
	glVertex3f(-6.0f, 4.0f,-1.0f);					// Top Left Of The Quad (Left)
	glVertex3f(-6.0f,3.0f,-1.0f);					// Bottom Left Of The Quad (Left)
	glVertex3f(-6.0f,3.0f, 1.0f);					// Bottom Right Of The Quad (Left)
	glColor3f(col1 * 1.0f, col1 * 1.0f, col1 * 1.0f);					// Set The Color To Violet
	glVertex3f( 6.0f, 4.0f,-1.0f);					// Top Right Of The Quad (Right)
	glVertex3f( 6.0f, 4.0f, 1.0f);					// Top Left Of The Quad (Right)
	glVertex3f( 6.0f,3.0f, 1.0f);					// Bottom Left Of The Quad (Right)
	glVertex3f( 6.0f,3.0f,-1.0f);					// Bottom Right Of The Quad (Right)
    glEnd();
  


	//second quad:
glLoadIdentity();									// Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-10.0f);	                    // Move Right 1.5 Units And Into The Screen 7.0
glRotatef(rquad2,0.0f,1.0f,0.0f);					// Rotate The Quad On The X axis ( NEW )
glBegin(GL_QUADS);									// Draw A Quad

	glColor3f(col2*1.0f, col2*1.0f, col2*1.0f);
	glVertex3f( 6.0f, 0.5f,-1.0f);					// Top Right Of The Quad (Top)
	glVertex3f(-6.0f, 0.5f,-1.0f);					// Top Left Of The Quad (Top)
	glVertex3f(-6.0f, 0.5f, 1.0f);					// Bottom Left Of The Quad (Top)
	glVertex3f( 6.0f, 0.5f, 1.0f);					// Bottom Right Of The Quad (Top)
	glColor3f(col2 * 1.0f, col2 * 1.0f, col2 * 1.0f);						// Set The Color To Orange
	glVertex3f( 6.0f, -0.5f, 1.0f);					// Top Right Of The Quad (Bottom)
	glVertex3f(-6.0f, -0.5f, 1.0f);					// Top Left Of The Quad (Bottom)
	glVertex3f(-6.0f, -0.5f,-1.0f);					// Bottom Left Of The Quad (Bottom)
	glVertex3f( 6.0f, -0.5f,-1.0f);					// Bottom Right Of The Quad (Bottom)
	glColor3f(col2 * 1.0f, col2 * 1.0f, col2 * 1.0f);						// Set The Color To Red
	glVertex3f( 6.0f, 0.5f, 1.0f);					// Top Right Of The Quad (Front)
	glVertex3f(-6.0f, 0.5f, 1.0f);					// Top Left Of The Quad (Front)
	glVertex3f(-6.0f,-0.5f, 1.0f);					// Bottom Left Of The Quad (Front)
	glVertex3f( 6.0f,-0.5f, 1.0f);					// Bottom Right Of The Quad (Front)
	glColor3f(col2 * 1.0f, col2 * 1.0f, col2 * 1.0f);						// Set The Color To Yellow
	glVertex3f( 6.0f,-0.5f,-1.0f);					// Top Right Of The Quad (Back)
	glVertex3f(-6.0f,-0.5f,-1.0f);					// Top Left Of The Quad (Back)
	glVertex3f(-6.0f, -0.5f,-1.0f);					// Bottom Left Of The Quad (Back)
	glVertex3f( 6.0f, -0.5f,-1.0f);					// Bottom Right Of The Quad (Back)
	glColor3f(col2 * 1.0f, col2 * 1.0f, col2 * 1.0f);						// Set The Color To Blue
	glVertex3f(-6.0f, 0.5f, 1.0f);					// Top Right Of The Quad (Left)
	glVertex3f(-6.0f, 0.5f,-1.0f);					// Top Left Of The Quad (Left)
	glVertex3f(-6.0f,-0.5f,-1.0f);					// Bottom Left Of The Quad (Left)
	glVertex3f(-6.0f,-0.5f, 1.0f);					// Bottom Right Of The Quad (Left)
	glColor3f(col2 * 1.0f, col2 * 1.0f, col2 * 1.0f);					// Set The Color To Violet
	glVertex3f( 6.0f, 0.5f,-1.0f);					// Top Right Of The Quad (Right)
	glVertex3f( 6.0f, 0.5f, 1.0f);					// Top Left Of The Quad (Right)
	glVertex3f( 6.0f,-0.5f, 1.0f);					// Bottom Left Of The Quad (Right)
	glVertex3f( 6.0f,-0.5f,-1.0f);					// Bottom Right Of The Quad (Right)

	//third quad:
glLoadIdentity();									// Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-10.0f);	                    // Move Right 1.5 Units And Into The Screen 7.0
glRotatef(rquad3,0.0f,1.0f,0.0f);					// Rotate The Quad On The X axis ( NEW )
glBegin(GL_QUADS);									// Draw A Quad

	glColor3f(col3*1.0f, col3*1.0f, col3*1.0f);
	glVertex3f( 6.0f, -4.0f,-1.0f);					// Top Right Of The Quad (Top)
	glVertex3f(-6.0f, -4.0f,-1.0f);					// Top Left Of The Quad (Top)
	glVertex3f(-6.0f, -4.0f, 1.0f);					// Bottom Left Of The Quad (Top)
	glVertex3f( 6.0f, -4.0f, 1.0f);					// Bottom Right Of The Quad (Top)
	glColor3f(col3 * 1.0f, col3 * 1.0f, col3 * 1.0f);						// Set The Color To Orange
	glVertex3f( 6.0f, -3.0f, 1.0f);					// Top Right Of The Quad (Bottom)
	glVertex3f(-6.0f, -3.0f, 1.0f);					// Top Left Of The Quad (Bottom)
	glVertex3f(-6.0f, -3.0f,-1.0f);					// Bottom Left Of The Quad (Bottom)
	glVertex3f( 6.0f, -3.0f,-1.0f);					// Bottom Right Of The Quad (Bottom)
	glColor3f(col3 * 1.0f, col3 * 1.0f, col3 * 1.0f);						// Set The Color To Red
	glVertex3f( 6.0f, -4.0f, 1.0f);					// Top Right Of The Quad (Front)
	glVertex3f(-6.0f, -4.0f, 1.0f);					// Top Left Of The Quad (Front)
	glVertex3f(-6.0f,-3.0f, 1.0f);					// Bottom Left Of The Quad (Front)
	glVertex3f( 6.0f,-3.0f, 1.0f);					// Bottom Right Of The Quad (Front)
	glColor3f(col3 * 1.0f, col3 * 1.0f, col3 * 1.0f);						// Set The Color To Yellow
	glVertex3f( 6.0f,-3.0f,-1.0f);					// Top Right Of The Quad (Back)
	glVertex3f(-6.0f,-3.0f,-1.0f);					// Top Left Of The Quad (Back)
	glVertex3f(-6.0f, -4.0f,-1.0f);					// Bottom Left Of The Quad (Back)
	glVertex3f( 6.0f, -4.0f,-1.0f);					// Bottom Right Of The Quad (Back)
	glColor3f(col3 * 1.0f, col3 * 1.0f, col3 * 1.0f);						// Set The Color To Blue
	glVertex3f(-6.0f, -4.0f, 1.0f);					// Top Right Of The Quad (Left)
	glVertex3f(-6.0f, -4.0f,-1.0f);					// Top Left Of The Quad (Left)
	glVertex3f(-6.0f,-3.0f,-1.0f);					// Bottom Left Of The Quad (Left)
	glVertex3f(-6.0f,-3.0f, 1.0f);					// Bottom Right Of The Quad (Left)
	glColor3f(col3 * 1.0f, col3 * 1.0f, col3 * 1.0f);					// Set The Color To Violet
	glVertex3f( 6.0f, -4.0f,-1.0f);					// Top Right Of The Quad (Right)
	glVertex3f( 6.0f, -4.0f, 1.0f);					// Top Left Of The Quad (Right)
	glVertex3f( 6.0f,-3.0f, 1.0f);					// Bottom Left Of The Quad (Right)
	glVertex3f( 6.0f,-3.0f,-1.0f);					// Bottom Right Of The Quad (Right)
    glEnd();

   

	win1->display();

the window is done with sfml library. the variables rot1, rot2 and rot3 i get from the neurofeedback software, they are between 0 and +6. if i uncomment one of the cubes it works fine.

thanks, michael

One issue with your code is that the second cube is missing a glEnd() call.

hello gclements,
thank you, that was it. somehow i did not see it.
michael

Here’s a slightly different way to structure your code which you might find cleaner in some ways.
Use ‘a’ and ‘z’ to start and stop animation. Sorry, my indentation scheme gets royally screwed up when and cut and paste from Visual C++. My biggest suggestion is to only define the faces of the cube once, put that in a subroutine which you then call 3 times with various modeling transformations applied. Good luck.



//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\

#include <windows.h>
#include <stdio.h>
#include <gl.h>         // The GL Header File
#include <glut.h>       // The GL Utility Toolkit (Glut) Header


float  xs = 0.0, ys = 0.0, tip = -10.0, trn = 0.0,  zum = 1.0,
	   rquad1 = 0.0, rquad2 = 0.0, rquad3 = 0.0;

int cube[8][3] = {{-1,-1,+1}, {+1,-1,+1}, {+1,+1,+1}, {-1,+1,+1}, 
                  {-1,-1,-1}, {+1,-1,-1}, {+1,+1,-1}, {-1,+1,-1}};


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//----------------------------------------   Arrow_Keys   ------------------------------------------

void Arrow_Keys (int s_keys, int x, int y)
{
    switch (s_keys)  {

       case  GLUT_KEY_RIGHT:  xs += 0.01;  break;
       case  GLUT_KEY_LEFT :  xs -= 0.01;  break;
       case  GLUT_KEY_UP   :  ys += 0.01;  break;
       case  GLUT_KEY_DOWN :  ys -= 0.01;  break;

       default:  printf ("   Keyboard -> key = %d, key = %c
", s_keys, s_keys);   break;
    }

    glutPostRedisplay ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//---------------------------------------   Rotate_Cubes   -----------------------------------------

// Animate rotation of cubes.

void Rotate_Cubes (void)
{
	static float  rot1 = 3.0, rot2 = 5.0, rot3 = 8.0;

	rquad1 += rot1;
    rquad2 -= rot2;
    rquad3 += rot3;

	glutPostRedisplay ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-----------------------------------------   Keyboard   -------------------------------------------

void Keyboard (unsigned char key, int x, int y)
{
    switch (key)  {

	   case 'a':  glutIdleFunc (Rotate_Cubes);  break;
	   case 'z':  glutIdleFunc (    NULL    );  break;

	   case 'x':  tip += 3.0;  break;
	   case 'X':  tip -= 3.0;  break;
	   case 'y':  trn += 3.0;  break;
	   case 'Y':  trn -= 3.0;  break;
	   case 's':  zum *= 1.1;  break;
	   case 'S':  zum *= 0.9;  break;

	   case 'r':  tip = 0.0; trn = 0.0; zum = 1.0;  break;

       case  27:  exit(0);  break;      // Quit program with 'esc' key.

       default :  printf ("   Keyboard -> key = %d, key = %c
", key, key);   break;
    }

    glutPostRedisplay ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-----------------------------------------   One_Cube   ------------------------------------------

void One_Cube (void)
{
    glBegin (GL_QUADS);
	   glColor3f (1.0, 0.6, 0.3);
       glVertex3iv (cube[0]); glVertex3iv (cube[1]); glVertex3iv (cube[2]); glVertex3iv (cube[3]); // front
	   glColor3f (0.3, 1.0, 0.6);
	   glVertex3iv (cube[1]); glVertex3iv (cube[5]); glVertex3iv (cube[6]); glVertex3iv (cube[2]); // right
	   glColor3f (0.3, 0.6, 1.0);
       glVertex3iv (cube[6]); glVertex3iv (cube[5]); glVertex3iv (cube[4]); glVertex3iv (cube[7]); // back
	   glColor3f (0.6, 0.3, 1.0);
       glVertex3iv (cube[7]); glVertex3iv (cube[4]); glVertex3iv (cube[0]); glVertex3iv (cube[3]); // left
	   glColor3f (0.8, 0.8, 0.2);
       glVertex3iv (cube[3]); glVertex3iv (cube[2]); glVertex3iv (cube[6]); glVertex3iv (cube[7]); // top
       glVertex3iv (cube[5]); glVertex3iv (cube[1]); glVertex3iv (cube[0]); glVertex3iv (cube[4]); // bottom
	glEnd ();

}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//----------------------------------------   Draw_Cubes   ------------------------------------------

void Draw_Cubes (void)
{
	glPushMatrix ();
	   glRotatef (rquad1, 0,1,0);
	   One_Cube ();
	glPopMatrix ();

	glPushMatrix ();
	   glTranslatef (5.0, 0.0, 0.0);
	   glRotatef    (rquad2, 0,1,0);
	   glScalef     (2.0, 1.0, 1.0);
	   One_Cube ();
	glPopMatrix ();

	glPushMatrix ();
	   glTranslatef (-5.0, 0.0, 0.0);
	   glRotatef    (rquad3, 0,1,0 );
	   glScalef     (1.0, 2.0, 1.0);
	   One_Cube ();
	glPopMatrix ();
}

//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-----------------------------------------   Display   --------------------------------------------


void Display (void)
{
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode (GL_MODELVIEW);   // Perform operations on the Modeling matrix.
	glLoadIdentity ();             // Clears Model transformation stack to the identity matrix.


	// Modeling transformations used here to change view of teapot and axes.

    glTranslatef (xs, ys, 0 );    // Use arrow keys to move scene up-down, right-left.
	glRotatef (tip, 1, 0, 0 );    // Use 'x' key to rotate around X axis (tipping)
    glRotatef (trn, 0, 1, 0 );    // Use 'y' key to rotate around Y axis (turning)
	glScalef  (zum, zum, zum);    // Use 's' key to scale objects in scene.

    glScalef (0.1, 0.1, 0.1);

	Draw_Cubes ();

    glutSwapBuffers ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-------------------------------------------   main   ---------------------------------------------

void main (int argc, char** argv) 
{
    glutInit (&argc, argv);

    glutInitDisplayMode    (GLUT_RGB | GLUT_DOUBLE); 
    glutInitWindowSize     (800, 800); 
    glutInitWindowPosition (300, 150);
    glutCreateWindow       ("Spinning Cubes");

    glutKeyboardFunc ( Keyboard );
    glutDisplayFunc  ( Display  );
	glutSpecialFunc  (Arrow_Keys);

    glClearColor (0.0, 0.1, 0.2, 0.0);    // Clear screen to dark blue.
	glEnable (GL_DEPTH_TEST);

    glutMainLoop ();
}


thanks carmine, that is mucher nicer, just more complicated for a beginner.

michael

[QUOTE=Carmine;1252126]Here’s a slightly different way to structure your code which you might find cleaner in some ways.
Use ‘a’ and ‘z’ to start and stop animation. Sorry, my indentation scheme gets royally screwed up when and cut and paste from Visual C++. My biggest suggestion is to only define the faces of the cube once, put that in a subroutine which you then call 3 times with various modeling transformations applied. Good luck.



//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\

#include <windows.h>
#include <stdio.h>
#include <gl.h>         // The GL Header File
#include <glut.h>       // The GL Utility Toolkit (Glut) Header


float  xs = 0.0, ys = 0.0, tip = -10.0, trn = 0.0,  zum = 1.0,
	   rquad1 = 0.0, rquad2 = 0.0, rquad3 = 0.0;

int cube[8][3] = {{-1,-1,+1}, {+1,-1,+1}, {+1,+1,+1}, {-1,+1,+1}, 
                  {-1,-1,-1}, {+1,-1,-1}, {+1,+1,-1}, {-1,+1,-1}};


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//----------------------------------------   Arrow_Keys   ------------------------------------------

void Arrow_Keys (int s_keys, int x, int y)
{
    switch (s_keys)  {

       case  GLUT_KEY_RIGHT:  xs += 0.01;  break;
       case  GLUT_KEY_LEFT :  xs -= 0.01;  break;
       case  GLUT_KEY_UP   :  ys += 0.01;  break;
       case  GLUT_KEY_DOWN :  ys -= 0.01;  break;

       default:  printf ("   Keyboard -> key = %d, key = %c
", s_keys, s_keys);   break;
    }

    glutPostRedisplay ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//---------------------------------------   Rotate_Cubes   -----------------------------------------

// Animate rotation of cubes.

void Rotate_Cubes (void)
{
	static float  rot1 = 3.0, rot2 = 5.0, rot3 = 8.0;

	rquad1 += rot1;
       rquad2 -= rot2;
       rquad3 += rot3;

	glutPostRedisplay ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-----------------------------------------   Keyboard   -------------------------------------------

void Keyboard (unsigned char key, int x, int y)
{
    switch (key)  {

	   case 'a':  glutIdleFunc (Rotate_Cubes);  break;
	   case 'z':  glutIdleFunc (    NULL    );  break;

	   case 'x':  tip += 3.0;  break;
	   case 'X':  tip -= 3.0;  break;
	   case 'y':  trn += 3.0;  break;
	   case 'Y':  trn -= 3.0;  break;
	   case 's':  zum *= 1.1;  break;
	   case 'S':  zum *= 0.9;  break;

	   case 'r':  tip = 0.0; trn = 0.0; zum = 1.0;  break;

       case  27:  exit(0);  break;      // Quit program with 'esc' key.

       default :  printf ("   Keyboard -> key = %d, key = %c
", key, key);   break;
    }

    glutPostRedisplay ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-----------------------------------------   One_Cube   ------------------------------------------

void One_Cube (void)
{
    glBegin (GL_QUADS);
	   glColor3f (1.0, 0.6, 0.3);
       glVertex3iv (cube[0]); glVertex3iv (cube[1]); glVertex3iv (cube[2]); glVertex3iv (cube[3]); // front
	   glColor3f (0.3, 1.0, 0.6);
	   glVertex3iv (cube[1]); glVertex3iv (cube[5]); glVertex3iv (cube[6]); glVertex3iv (cube[2]); // right
	   glColor3f (0.3, 0.6, 1.0);
       glVertex3iv (cube[6]); glVertex3iv (cube[5]); glVertex3iv (cube[4]); glVertex3iv (cube[7]); // back
	   glColor3f (0.6, 0.3, 1.0);
       glVertex3iv (cube[7]); glVertex3iv (cube[4]); glVertex3iv (cube[0]); glVertex3iv (cube[3]); // left
	   glColor3f (0.8, 0.8, 0.2);
       glVertex3iv (cube[3]); glVertex3iv (cube[2]); glVertex3iv (cube[6]); glVertex3iv (cube[7]); // top
       glVertex3iv (cube[5]); glVertex3iv (cube[1]); glVertex3iv (cube[0]); glVertex3iv (cube[4]); // bottom
	glEnd ();

}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//----------------------------------------   Draw_Cubes   ------------------------------------------

void Draw_Cubes (void)
{
	glPushMatrix ();
	   glRotatef (rquad1, 0,1,0);
	   One_Cube ();
	glPopMatrix ();

	glPushMatrix ();
	   glTranslatef (5.0, 0.0, 0.0);
	   glRotatef    (rquad2, 0,1,0);
	   One_Cube ();
	glPopMatrix ();

	glPushMatrix ();
	   glTranslatef (-5.0, 0.0, 0.0);
	   glRotatef    (rquad3, 0,1,0 );
	   One_Cube ();
	glPopMatrix ();
}

//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-----------------------------------------   Display   --------------------------------------------


void Display (void)
{
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode (GL_MODELVIEW);   // Perform operations on the Modeling matrix.
    glLoadIdentity ();             // Clears Model transformation stack to the identity matrix.


	// Modeling transformations used here to change view of teapot and axes.

    glTranslatef (xs, ys, 0 );    // Use arrow keys to move scene up-down, right-left.
    glRotatef (tip, 1, 0, 0 );    // Use 'x' key to rotate around X axis (tipping)
    glRotatef (trn, 0, 1, 0 );    // Use 'y' key to rotate around Y axis (turning)
    glScalef  (zum, zum, zum);    // Use 's' key to scale objects in scene.

    glScalef (0.1, 0.1, 0.1);

    Draw_Cubes ();

    glutSwapBuffers ();
}


//---+----4----+----3----+----2----+----1----+---/\---+----1----+----2----+----3----+----4----+---\\
//-------------------------------------------   main   ---------------------------------------------

void main (int argc, char** argv) 
{
    glutInit (&argc, argv);

    glutInitDisplayMode    (GLUT_RGB | GLUT_DOUBLE); 
    glutInitWindowSize     (800, 800); 
    glutInitWindowPosition (300, 150);
    glutCreateWindow       ("Spinning Cubes");

    glutKeyboardFunc ( Keyboard );
    glutDisplayFunc  ( Display  );
    glutSpecialFunc  (Arrow_Keys);

    glClearColor (0.0, 0.1, 0.2, 0.0);    // Clear screen to dark blue.
    glEnable (GL_DEPTH_TEST);

    glutMainLoop ();
}


[/QUOTE]

Hopefully, not too complicated. It’s organized a little differently and shows you how to do interactive viewing transformations and animation. Note I made a small enhancement giving each cube a different size using the glScale command.