Hi!
I am using the following code to rotate a cube:
#include <gl/glut.h>
GLfloat angle1 = 0.0;
GLfloat angle2 = 0.0;
void display(void) {
GLfloat x1[] = {-0.5, 0.5, -0.5};
GLfloat x2[] = {-0.5, 0.5, 0.5};
GLfloat x3[] = {0.5, 0.5, 0.5};
GLfloat x4[] = {0.5, 0.5, -0.5};
GLfloat x5[] = {-0.5, -0.5, -0.5};
GLfloat x6[] = {-0.5, -0.5, 0.5};
GLfloat x7[] = {0.5, -0.5, 0.5};
GLfloat x8[] = {0.5, -0.5, -0.5};
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle1, 0.0, 1.0, 0.0);
glRotatef(angle2, 1.0, 0.0, 0.0);
glBegin(GL_QUADS);
//top
glColor3f(1.0, 1.0, 1.0);
glVertex3fv(x1);
glVertex3fv(x2);
glVertex3fv(x3);
glVertex3fv(x4);
//bottom
glColor3f(0.0, 1.0, 0.0);
glVertex3fv(x5);
glVertex3fv(x6);
glVertex3fv(x7);
glVertex3fv(x8);
//front
glColor3f(1.0, 1.0, 0.0);
glVertex3fv(x1);
glVertex3fv(x4);
glVertex3fv(x8);
glVertex3fv(x5);
//back
glColor3f(0.0, 0.0, 1.0);
glVertex3fv(x2);
glVertex3fv(x3);
glVertex3fv(x7);
glVertex3fv(x6);
//left
glColor3f(1.0, 0.0, 1.0);
glVertex3fv(x2);
glVertex3fv(x1);
glVertex3fv(x5);
glVertex3fv(x6);
//right
glColor3f(0.0, 1.0, 1.0);
glVertex3fv(x4);
glVertex3fv(x3);
glVertex3fv(x7);
glVertex3fv(x8);
glEnd();//GL_QUADS
glutSwapBuffers();
glPopMatrix();
}
void keyboard(unsigned char key, int x, int y) {
switch(key) {
case 27: exit(0);
break;
}
}
void rotate(int key, int x, int y) {
switch(key) {
case GLUT_KEY_LEFT: angle1++;break;
case GLUT_KEY_RIGHT: angle1--;break;
case GLUT_KEY_UP: angle2++;break;
case GLUT_KEY_DOWN: angle2--;break;
}
}
int main(int argc, char * argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutGameModeString(“800x600:32”);
glutEnterGameMode();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(rotate);
glutIdleFunc(display);
glutMainLoop();
return 0;
}
but there is no red(allthough the top face must be red) and some faces become transparent when rotating the cube.How can I change my code to draw a solid cube with a red in it?