Skip to content

Commit 1e1f732

Browse files
authored
Create Alphabet(Q).cpp
1 parent 1075a45 commit 1e1f732

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

OpenGL/Alphabet(Q).cpp

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

0 commit comments

Comments
 (0)