This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects.cpp
234 lines (204 loc) · 6.94 KB
/
objects.cpp
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include <GL/glut.h>
#include <stdio.h>
#include "gimTruckHeader.h"
using namespace std;
GLuint _textureBatu1;
GLuint _textureGedung1;
GLuint _textureGedung2;
GLuint _texturePasir;
GLuint _textureJalan;
GLuint loadTexture(Image* image)
{
GLuint textureId;
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image->pixels);
return textureId;
}
void initRendering()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
Image* image1 = loadBMP("textures/rock1.bmp");
_textureBatu1 = loadTexture(image1);
Image* image2 = loadBMP("textures/city1.bmp");
_textureGedung1 = loadTexture(image2);
Image* image3 = loadBMP("textures/city2.bmp");
_textureGedung2 = loadTexture(image3);
Image* image4 = loadBMP("textures/sand.bmp");
_texturePasir = loadTexture(image4);
Image* image5 = loadBMP("textures/road.bmp");
_textureJalan = loadTexture(image5);
delete image1, image2, image3, image4, image5;
}
void batu1(float size)
{
glTranslatef(0.0f, size / 2, 0.0f);
kubusTekstur(size, _textureBatu1);
}
void gedung1(float size)
{
glTranslatef(-size*1.75, size / 2, -960.0f);
kubusTekstur(size, _textureGedung1);
glTranslatef(0.0f, size, 0.0f);
kubusTekstur(size, _textureGedung1);
}
void gedung2(float size)
{
glTranslatef(size*1.75, size / 2, -1000.0f);
kubusTekstur(size, _textureGedung2);
glTranslatef(0.0f, size, 0.0f);
kubusTekstur(size, _textureGedung2);
}
void tanahTekstur()
{
const float BOX_SIZE = 50.0f;
GLuint _namaTekstur = _texturePasir;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(-1000, 0.0, -1000);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-BOX_SIZE, 0.0, -BOX_SIZE);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-BOX_SIZE, 0.0, BOX_SIZE);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(BOX_SIZE, 0.0, BOX_SIZE);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(BOX_SIZE, 0.0, -BOX_SIZE);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void jalanTekstur()
{
const float BOX_SIZE = 20.0f;
GLuint _namaTekstur = _textureJalan;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(0.0, 0.1, -1000.0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-BOX_SIZE, 0.0, -BOX_SIZE);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-BOX_SIZE, 0.0, BOX_SIZE);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(BOX_SIZE, 0.0, BOX_SIZE);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(BOX_SIZE, 0.0, -BOX_SIZE);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void kubusTekstur(float size, GLuint _namaTekstur)
{
const float BOX_SIZE = size;
//Sisi atas
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
glEnd();
//Sisi bawah
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glNormal3f(0.0, -1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
glEnd();
//Sisi kiri
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
glEnd();
//Sisi kanan
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glNormal3f(1.0, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
glEnd();
//Sisi depan
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
glEnd();
//Sisi belakang
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _namaTekstur);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
glEnd();
glDisable(GL_TEXTURE_2D);
}