1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| # include <gl/GLUT.H>
# include <gl/GLU.H>
# include <gl/GL.H>
# include <gl/GLAUX.H>
# include <windows.h>
# include "stdio.h"
# include "stdafx.h"
//-----------------------------------
// GLOBAL VARIABLES
//----------------------------------
int i, j, k,a;
float f;
//------------------------------------
// DRAWING FUNCTIONS
//------------------------------------
GLfloat vertices[][3] =
{
{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0},
{1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0},
{1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}
};
GLfloat colors[][3] = {{0.0,0.5,0.5},{1.0,0.0,0.0},
{1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0},
{1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};
void polygon(int a, int b, int c , int d)
{
// draw a polygon using colour of first vertex
glBegin(GL_POLYGON);
glColor3fv(colors[a]);
glVertex3fv(vertices[a]);
glVertex3fv(vertices[b]);
glVertex3fv(vertices[c]);
glVertex3fv(vertices[d]);
glEnd();
}
void cube(void)
{
/* map vertices to faces */
polygon(0,3,2,1);
polygon(2,3,7,6);
polygon(4,7,3,0);
polygon(1,2,6,5);
polygon(7,4,5,6);
polygon(5,4,0,1);
}
void draw_cuboid(GLfloat x,GLfloat y,GLfloat z)
{
glPushMatrix();
glScalef(x,y,z);
cube();
glPopMatrix();
}
[.....]
int main(int argc, char **argv)
{
glutInit(&argc, argv);
/* need double buffering */
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Emile");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
//glutIdleFunc(spinCube);
//glutMouseFunc(mouse);
glEnable(GL_DEPTH_TEST); /* Enable hidden--surface--removal */
glutMainLoop();
} |