You are on page 1of 3

#include <GL\glut.

h>
static int c = 0, d = 0,s=0;
void init(void){
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void DrawCube(void)
{
glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( .5f, .5f,-.5f);
glVertex3f(-.5f, .5f,-.5f);
glVertex3f(-.5f, .5f, .5f);
glVertex3f( .5f, .5f, .5f);
glColor3f(1.0f,0.5f,0.0f);
glVertex3f( .5f,-.5f, .5f);
glVertex3f(-.5f,-.5f, .5f);
glVertex3f(-.5f,-.5f,-.5f);
glVertex3f( .5f,-.5f,-.5f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( .5f, .5f, .5f);
glVertex3f(-.5f, .5f, .5f);
glVertex3f(-.5f,-.5f, .5f);
glVertex3f( .5f,-.5f, .5f);
glColor3f(1.0f,1.0f,0.0f);
glVertex3f( .5f,-.5f,-.5f);
glVertex3f(-.5f,-.5f,-.5f);
glVertex3f(-.5f, .5f,-.5f);
glVertex3f( .5f, .5f,-.5f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-.5f, .5f, .5f);
glVertex3f(-.5f, .5f,-.5f);
glVertex3f(-.5f,-.5f,-.5f);
glVertex3f(-.5f,-.5f, .5f);
glColor3f(1.0f,0.0f,1.0f);
glVertex3f( .5f, .5f,-.5);
glVertex3f( .5f, .5f, .5f);
glVertex3f( .5f,-.5f, .5f);
glVertex3f( .5f,-.5f,-.5f);
glEnd();
}
void display(void){
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0);
glColor3f (1.0, 0.0, 0.0);
glPushMatrix();
glRotatef ((GLfloat) d, 0.0, 1.0, 0.0);
glColor3f (0.0, 0.0, 1.0);
glutSolidOctahedron();
glColor3f (0.0, 0.0, 0.5);
glutWireOctahedron();
/* Dibuja el dimante */
glRotatef (15, 0.0, 0.0, 1.0);
glRotatef ((GLfloat) c, 0.0, 1.0, 0.0);
glTranslatef (3.0, 0.0, 0.0);
glPushMatrix();
glRotatef ((GLfloat) d, 0.0, 1.0, 0.0);

glColor3f (0.0, 0.0, 1.0);


DrawCube();
//cubo
glPopMatrix();
glRotatef (-25, 0.0, 0.0, 1.0);
glRotatef ((GLfloat) s, 0.0, 1.0, 0.0);
glTranslatef (1.2, 0.0, 0.0);
glColor3f(1.0f,1.0f,0.0f);
glutWireSphere(0.1, 10, 8);
glColor3f (0.0, 0.0, 1.0);
glutSolidSphere(0.1, 10, 8);
//esfera
glPopMatrix();
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, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (0.0, 1.0, 6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'd':
d = (d + 10) % 360;
glutPostRedisplay();
break;
case 'D':
d = (d - 10) % 360;
glutPostRedisplay();
break;
case 'c':
c = (c + 5) % 360;
glutPostRedisplay();
break;
case 'C':
c = (c - 5) % 360;
glutPostRedisplay();
break;
case 's':
s = (s + 10) % 360;
glutPostRedisplay();
break;
case 'S':
s = (s- 10) % 360;
glutPostRedisplay();
break;
default:
break;
}
}
int main(int argc, char** argv)

{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

You might also like