|
| 1 | +#include <GL/glut.h> |
| 2 | +#include <stdlib.h> |
| 3 | +GLfloat T = 0; |
| 4 | + |
| 5 | +void MyInit() { |
| 6 | + glClearColor(0, 0, 0, 1); |
| 7 | + glColor3f(1, 0, 0); |
| 8 | + glEnable(GL_DEPTH_TEST); |
| 9 | +} |
| 10 | +void Face(GLfloat A[], GLfloat B[], GLfloat C[], GLfloat D[]) |
| 11 | +{ |
| 12 | + glBegin(GL_POLYGON); |
| 13 | + glVertex3fv(A); |
| 14 | + glVertex3fv(B); |
| 15 | + glVertex3fv(C); |
| 16 | + glVertex3fv(D); |
| 17 | + glEnd(); |
| 18 | +} |
| 19 | +void Cube(GLfloat V0[], GLfloat V1[], GLfloat V2[], GLfloat V3[], GLfloat V4[], GLfloat V5[], GLfloat V6[], GLfloat V7[]) |
| 20 | +{ |
| 21 | + glColor3f(0.6, 0, 0.6); |
| 22 | + Face(V0, V1, V2, V3);//back |
| 23 | + glColor3f(0.5, 0.9, 0.5); |
| 24 | + Face(V4, V5, V6, V7);//front |
| 25 | + glColor3f(1, 0.4, 0); |
| 26 | + Face(V0, V3, V7, V4);//left |
| 27 | + glColor3f(1, 0.5, 1); |
| 28 | + Face(V1, V2, V6, V5);//right |
| 29 | + glColor3f(0.5, 0.6, 1); |
| 30 | + Face(V0, V1, V5, V4);//top |
| 31 | + glColor3f(0.5, 0.4, 1); |
| 32 | + Face(V2, V3, V7, V6);//bottom |
| 33 | +} |
| 34 | +void Draw() { |
| 35 | + GLfloat V[8][3] = { {-0.2, 0.2, 0.3}, |
| 36 | + {0.2, 0.2, 0.3}, |
| 37 | + {0.2, 0.1, 0.3}, |
| 38 | + {-0.2, 0.1, 0.3}, |
| 39 | + |
| 40 | + {-0.2, 0.2, -0.3}, |
| 41 | + {0.2, 0.2, -0.3}, |
| 42 | + {0.2, 0.1, -0.3}, |
| 43 | + {-0.2, 0.1, -0.3}, |
| 44 | + }; |
| 45 | + GLfloat V1[8][3] = { {-0.2, -0.1, 0.3}, |
| 46 | + {0.2, -0.1, 0.3}, |
| 47 | + {0.2, -0.2, 0.3}, |
| 48 | + {-0.2, -0.2, 0.3}, |
| 49 | + |
| 50 | + {-0.2, -0.1, -0.3}, |
| 51 | + {0.2, -0.1, -0.3}, |
| 52 | + {0.2, -0.2, -0.3}, |
| 53 | + {-0.2, -0.2, -0.3}, |
| 54 | + }; |
| 55 | + GLfloat V2[8][3] = { {0.2, 0.2, 0.3}, |
| 56 | + {0.2, 0.1, 0.3}, |
| 57 | + {0, 0, 0.3}, |
| 58 | + {-0.1, 0, 0.3}, |
| 59 | + |
| 60 | + {0.2, 0.2, -0.3}, |
| 61 | + {0.2, 0.1, -0.3}, |
| 62 | + {0, 0, -0.3}, |
| 63 | + {-0.1, 0, -0.3}, |
| 64 | + }; |
| 65 | + |
| 66 | + GLfloat V3[8][3] = { {-0.1, -0, 0.3}, |
| 67 | + {0, 0, 0.3}, |
| 68 | + {0.2, -0.1, 0.3}, |
| 69 | + {0.2, -0.2, 0.3}, |
| 70 | + |
| 71 | + {-0.1, -0, -0.3}, |
| 72 | + {0, 0, -0.3}, |
| 73 | + {0.2, -0.1, -0.3}, |
| 74 | + {0.2, -0.2, -0.3}, |
| 75 | + }; |
| 76 | + |
| 77 | + |
| 78 | + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 79 | + |
| 80 | + glLoadIdentity(); |
| 81 | + glRotatef(3, 1, 1, -1); |
| 82 | + Cube(V[0], V[1], V[2], V[3], V[4], V[5], V[6], V[7]); |
| 83 | + Cube(V1[0], V1[1], V1[2], V1[3], V1[4], V1[5], V1[6], V1[7]); |
| 84 | + Cube(V2[0], V2[1], V2[2], V2[3], V2[4], V2[5], V2[6], V2[7]); |
| 85 | + Cube(V3[0], V3[1], V3[2], V3[3], V3[4], V3[5], V3[6], V3[7]); |
| 86 | + |
| 87 | + glutSwapBuffers(); |
| 88 | +} |
| 89 | + |
| 90 | +int main(int C, char* V[]) |
| 91 | +{ |
| 92 | + glutInit(&C, V); |
| 93 | + |
| 94 | + glutInitWindowPosition(250, 50); |
| 95 | + glutInitWindowSize(600, 600); |
| 96 | + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); |
| 97 | + glutCreateWindow("SURESH"); |
| 98 | + MyInit(); |
| 99 | + glutDisplayFunc(Draw); |
| 100 | + glutMainLoop(); |
| 101 | + |
| 102 | + return 0; |
| 103 | +} |
0 commit comments