-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
84 lines (71 loc) · 2.24 KB
/
Main.cpp
File metadata and controls
84 lines (71 loc) · 2.24 KB
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
#include <GL\glut.h>
GLfloat xRotated, yRotated, zRotated;
GLdouble size = 1;
void display(void)
{
glMatrixMode(GL_MODELVIEW);
// clear the drawing buffer.
glClear(GL_COLOR_BUFFER_BIT);
// clear the identity matrix.
glLoadIdentity();
// traslate the draw by z = -4.0
// Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
glTranslatef(0.0, 0.0, -4.5);
// Red color used to draw.
glColor3f(0.8, 0.2, 0.1);
// changing in transformation matrix.
// rotation about X axis
glRotatef(xRotated, 1.0, 0.0, 0.0);
// rotation about Y axis
glRotatef(yRotated, 0.0, 1.0, 0.0);
// rotation about Z axis
glRotatef(zRotated, 0.0, 0.0, 1.0);
// scaling transfomation
glScalef(1.0, 1.0, 1.0);
// built-in (glut library) function , draw you a Teapot.
glutSolidTeapot(size);
// Flush buffers to screen
glFlush();
// sawp buffers called because we are using double buffering
// glutSwapBuffers();
}
void reshapeFunc(int x, int y)
{
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Angle of view:40 degrees
//Near clipping plane distance: 0.5
//Far clipping plane distance: 20.0
gluPerspective(40.0, (GLdouble)x / (GLdouble)y, 0.5, 20.0);
glViewport(0, 0, x, y); //Use the whole window for rendering
}
void idleFunc(void)
{
yRotated += 0.01;
display();
}
int main(int argc, char** argv)
{
//Initialize GLUT
glutInit(&argc, argv);
//double buffering used to avoid flickering problem in animation
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// window size
glutInitWindowSize(400, 350);
// create the window
glutCreateWindow("Teapot Rotating Animation");
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
xRotated = yRotated = zRotated = 30.0;
xRotated = 33;
yRotated = 40;
glClearColor(0.0, 0.0, 0.0, 0.0);
//Assign the function used in events
glutDisplayFunc(display);
glutReshapeFunc(reshapeFunc);
glutIdleFunc(idleFunc);
//Let start glut loop
glutMainLoop();
return 0;
}