-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path06.TeaPot.cpp
More file actions
140 lines (122 loc) · 2.78 KB
/
06.TeaPot.cpp
File metadata and controls
140 lines (122 loc) · 2.78 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
6. To draw a simple shaded scene consisting of a tea pot on a table. Define suitably
the position and properties of the light source along with the properties of the
surfaces of the solid object used in the scene.
*/
#include<stdio.h>
#include<math.h>
#include<glut.h>
void myInit();
void drawTable();
void display();
void myInit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100, 200, -100, 200, -200, 200);
glMatrixMode(GL_MODELVIEW);
}
void drawTable()
{
// Table Top
glPushMatrix();
glColor3f(0, 1, 0);
glTranslatef(50, 40, -50);
glScalef(50, 5, 50);
glutSolidCube(1);
glPopMatrix();
// 1st leg
glPushMatrix();
glColor3f(1, 1, 0);
glTranslatef(30, 20, -30);
glScalef(5, 35, 5);
glutSolidCube(1);
glPopMatrix();
// 2nd leg
glPushMatrix();
glColor3f(1, 1, 0);
glTranslatef(70, 20, -30);
glScalef(5, 35, 5);
glutSolidCube(1);
glPopMatrix();
// 3rd leg
glPushMatrix();
glColor3f(1, 1, 0);
glTranslatef(30, 20, -70);
glScalef(5, 35, 5);
glutSolidCube(1);
glPopMatrix();
// 4th leg
glPushMatrix();
glColor3f(1, 1, 0);
glTranslatef(70, 20, -70);
glScalef(5, 35, 5);
glutSolidCube(1);
glPopMatrix();
// Floor
glPushMatrix();
glColor3f(1, 0, 1);
glTranslatef(50, 0, -50);
glScalef(100, 5, 100);
glutSolidCube(1);
glPopMatrix();
// Left wall
glPushMatrix();
glColor3f(1, 0, 0);
glRotatef(90, 0, 0, 1);
glTranslatef(50, 0, -50);
glScalef(100, 5, 100);
glutSolidCube(1);
glPopMatrix();
// Backside wall
glPushMatrix();
glColor3f(1, 0, 0);
glTranslatef(50, 50, -100);
glScalef(100, 100, 5);
glutSolidCube(1);
glPopMatrix();
// Tea pot
glPushMatrix();
glTranslatef(50, 50, -50);
glRotatef(30, 0, 1, 0);
glutSolidTeapot(10);
glPopMatrix();
}
void display()
{
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat mat_ambient[] = { .7,.7,.7,1 };
GLfloat mat_diffuse[] = { .5,.5,.5,1 };
GLfloat mat_spec[] = { 1,1,1,1 };
GLfloat mat_shininess[] = { 50 };
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_spec);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
GLfloat light_int[] = { .7,.7,.7,1 };
GLfloat lightpos[] = { 100,100,100 };
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_int);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(25, 25, 50, 0, 0, -25, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
drawTable();
glFlush();
}
int main()
{
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tea Pot");
myInit();
glutDisplayFunc(display);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}