Skip to content

Commit a5623f7

Browse files
authored
Create Alphabet(M).cpp
1 parent 6bf9abc commit a5623f7

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

OpenGL/Alphabet(M).cpp

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

0 commit comments

Comments
 (0)