Skip to content

Commit af6af4f

Browse files
authored
Add files via upload
1 parent aa616cd commit af6af4f

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

OpenGL/alphabet(E).cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.1, 0.3, 0.1},
42+
{0, 0.3, 0.1},
43+
{0, -0.3, 0.1},
44+
{-0.1, -0.3, 0.1},
45+
46+
{-0.1, 0.3, -0.1},
47+
{0, 0.3, -0.1},
48+
{0, -0.3, -0.1},
49+
{-0.1, -0.3, -0.1},
50+
};
51+
GLfloat V1[8][3] = {{0, 0.3, 0.1},
52+
{0.3, 0.3, 0.1},
53+
{0.3, 0.2, 0.1},
54+
{0, 0.2, 0.1},
55+
56+
{0, 0.3, -0.1},
57+
{0.3, 0.3, -0.1},
58+
{0.3, 0.2, -0.1},
59+
{0, 0.2, -0.1},
60+
};
61+
GLfloat V2[8][3] = {{-0.1, 0.05, 0.1},
62+
{0.3, 0.05, 0.1},
63+
{0.3, -0.05, 0.1},
64+
{-0.1, -0.05, 0.1},
65+
66+
{-0.1, 0.05, -0.1},
67+
{0.3, 0.05, -0.1},
68+
{0.3, -0.05, -0.1},
69+
{-0.1, -0.05, -0.1},
70+
};
71+
GLfloat V3[8][3] = {{0, -0.2, 0.1},
72+
{0.3, -0.2, 0.1},
73+
{0.3, -0.3, 0.1},
74+
{-0.1, -0.3, 0.1},
75+
76+
{-0.1, -0.2, -0.1},
77+
{0.3, -0.2, -0.1},
78+
{0.3, -0.3, -0.1},
79+
{-0.1, -0.3, -0.1},
80+
};
81+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
82+
83+
glLoadIdentity();
84+
//glRotatef(T,1,1,1);//for spinning
85+
glRotatef(-15,1,1,-1);//for stationary
86+
Cube(V[0],V[1],V[2],V[3],V[4],V[5],V[6],V[7]);
87+
Cube(V1[0],V1[1],V1[2],V1[3],V1[4],V1[5],V1[6],V1[7]);
88+
Cube(V2[0],V2[1],V2[2],V2[3],V2[4],V2[5],V2[6],V2[7]);
89+
Cube(V3[0],V3[1],V3[2],V3[3],V3[4],V3[5],V3[6],V3[7]);
90+
glutSwapBuffers();
91+
}
92+
93+
main(int C, char *V[])
94+
{
95+
glutInit(&C,V);
96+
97+
glutInitWindowPosition(250,50);
98+
glutInitWindowSize(600,600);
99+
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
100+
glutCreateWindow("E alphabet");
101+
MyInit();
102+
glutDisplayFunc(Draw);
103+
//glutIdleFunc(Spin); //spinning
104+
glutMainLoop();
105+
106+
return 0;
107+
}

0 commit comments

Comments
 (0)