-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHouse.cpp
More file actions
202 lines (175 loc) · 4.96 KB
/
House.cpp
File metadata and controls
202 lines (175 loc) · 4.96 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//--------------------------------------------------------------------------
// Eddie Gyger
// Computer Graphics
// My House - 10/5/2020
//
//--------------------------------------------------------------------------
#ifdef _WIN32
#include <GL/glut.h>
#elif __linux__
#include <GL/glut.h>
#elif __APPLE__
#define GL_SILENCE_DEPRECATION
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#endif
#include <cmath>
#include <cstdio>
const double PI = 3.141592653589793;
GLuint drawSun;
// Set up a display list for drawing the Sun.
void init()
{
drawSun = glGenLists(1);
glNewList(drawSun, GL_COMPILE);
glBegin(GL_TRIANGLE_FAN);
glColor3f(1.0f, 1.0f, 0.0f);
for (GLint degrees = 0; degrees <= 350; degrees += 10)
{
GLdouble radians, x, y;
radians = degrees * PI / 180;
x = cos(radians);
y = sin(radians);
glVertex2f(x-10, y+4.5f); //Translate
}
glEnd();
glEndList();
}
void display() {
glClearColor(.683f, .783f, .96f, 1.0f);//Sky
glClear(GL_COLOR_BUFFER_BIT);
// Enabling blending makes it possible to use the alpha component of the
// color to control opacity.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// These functions set the world coordinate system that will be used
// for drawing the figures in the code that follows.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-25.0f, 25.0f, -12.0f, 12.0f); //Arguments: xmin, xmax, ymin, ymax
// Grass
glBegin(GL_QUADS);
glColor3f(.25f, .535f, .065f);
glVertex2f(-25.0f, -6.0f);
glVertex2f(25.0f, -6.0f);
glVertex2f(25.0f, -12.0f);
glVertex2f(-25.0f, -12.0f);
//House Body
glColor3f(.8f, .216f, .1f);
glVertex2f(-10.0f, -5.0f);
glVertex2f(10.0f, -5.0f);
glVertex2f(10.0f, -10.0f);
glVertex2f(-10.0f, -10.0f);
//Overhang
glColor3f(.303f, .107f, .061f);
glVertex2f(-12.0f, -5.0f);
glVertex2f(12.0f, -5.0f);
glVertex2f(13.0f, -4.5f);
glVertex2f(-13.0f, -4.5f);
//Roof
glColor3f(.4f, .145f, .086f);
glVertex2f(-8.0f, 0.0f);
glVertex2f(8.0f, 0.0f);
glVertex2f(13.0f, -4.5f);
glVertex2f(-13.0f, -4.5f);
//Door
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(-2.0f, -6.0f);
glVertex2f(2.0f, -6.0f);
glVertex2f(2.0f, -9.0f);
glVertex2f(-2.0f, -9.0f);
//DoorKnob
glColor3f(1.0f, 1.0f, 0.0f);
glVertex2f(1.25f, -7.25f);
glVertex2f(1.75f, -7.25f);
glVertex2f(1.75f, -7.75f);
glVertex2f(1.25f, -7.75f);
//Window Left
glColor3f(1.0f, 1.0f, 1.0f);
glVertex2f(-8.0f, -6.0f);
glVertex2f(-4.0f, -6.0f);
glVertex2f(-4.0f, -8.0f);
glVertex2f(-8.0f, -8.0f);
//Window Right
glColor3f(1.0f, 1.0f, 1.0f);
glVertex2f(8.0f, -6.0f);
glVertex2f(4.0f, -6.0f);
glVertex2f(4.0f, -8.0f);
glVertex2f(8.0f, -8.0f);
glEnd();
//Window Lines
glBegin(GL_LINES);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2f(6.0f, -6.0f);
glVertex2f(6.0f, -8.0f);
glVertex2f(4.0f, -7.0f);
glVertex2f(8.0f, -7.0f);
glVertex2f(-6.0f, -6.0f);
glVertex2f(-6.0f, -8.0f);
glVertex2f(-4.0f, -7.0f);
glVertex2f(-8.0f, -7.0f);
glEnd();
//Step 1
glBegin(GL_QUADS);
glColor3f(.33f, .32f, 0.32f);
glVertex2f(-2.5f, -9.0f);
glVertex2f(2.5f, -9.0f);
glVertex2f(2.5f, -9.5f);
glVertex2f(-2.5f, -9.5f);
//Step 2
glColor3f(.33f, .32f, 0.32f);
glVertex2f(-3.0f, -9.5f);
glVertex2f(3.0f, -9.5f);
glVertex2f(3.0f, -10.0f);
glVertex2f(-3.0f, -10.0f);
glEnd();
//Step Line
glBegin(GL_LINES);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2f(2.5f, -9.5f);
glVertex2f(-2.5f, -9.5f);
glEnd();
//Berry Bush
glBegin(GL_TRIANGLE_FAN);
glColor4f(0.04f, 0.9f, 0.04f, 0.6f); // SOMETHING A LITTLE TRANSPARENT
glVertex2f(11.5f, -8.875f);
glVertex2f(10.375f, -7.750f);
glVertex2f(12.625f, -7.750f);
glVertex2f(13.750f, -8.875f);
glVertex2f(12.625f, -10.0f);
glVertex2f(10.375f, -10.0f);
glVertex2f(9.250f, -8.875f);
glVertex2f(10.375f, -7.750f);
glEnd();
//Berries
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 1.0f); //SOMETHING PURPLE
glVertex2f(11.35f, -9.3f);
glVertex2f(11.65f, -9.3f);
glVertex2f(11.65f, -9.4f);
glVertex2f(11.35f, -9.4f);
glVertex2f(10.55f, -8.5f);
glVertex2f(10.85f, -8.5f);
glVertex2f(10.85f, -8.6f);
glVertex2f(10.55f, -8.6f);
glVertex2f(12.15f, -8.5f);
glVertex2f(12.45f, -8.5f);
glVertex2f(12.45f, -8.6f);
glVertex2f(12.15f, -8.6f);
glEnd();
//Sun
glScalef(2.0f, 2.0f, 1.0f);
glCallList(drawSun);
glFlush(); // Render now
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutInitWindowSize(1000, 500); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutCreateWindow("My House"); // Create a window with the given title
glutDisplayFunc(display); // Register display callback handler for window re-paint
init();
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
}