-
Notifications
You must be signed in to change notification settings - Fork 0
/
skybox.cpp
157 lines (122 loc) · 4.02 KB
/
skybox.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
#include "skybox.h"
#include "config.h"
#include "constant.h"
#include <windows.h>
#include <GL/glut.h>
#include <GL/glext.h>
#include "vendor/SOIL/src/SOIL.h"
/**
* Texture Skybox
**/
int textureSkybox[] = {0, 0, 0, 0, 0, 0};
float sizeSkybox = 100.0f;
/**
* Penggambaran Skybox
**/
namespace SkyboxGL
{
/**
* Mengubah Size Skybox
**/
void setSize(int size)
{
sizeSkybox = (float) size;
}
/**
* Membaca Skybox
**/
void initSkybox(const char * dfile, const int type)
{
if(strlen(dfile) > 0)
{
textureSkybox[type] = SOIL_load_OGL_texture
(
dfile,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS
);
glBindTexture(GL_TEXTURE_2D, textureSkybox[type]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
}
/**
* Membaca Texture Skybox
**/
void loadTexture()
{
Model::Skybox skybox;
skybox = Config::getSkybox();
initSkybox(skybox.top, SKYBOX_TOP);
initSkybox(skybox.down, SKYBOX_DOWN);
initSkybox(skybox.front, SKYBOX_FRONT);
initSkybox(skybox.back, SKYBOX_BACK);
initSkybox(skybox.left, SKYBOX_LEFT);
initSkybox(skybox.right, SKYBOX_RIGHT);
glBindTexture(GL_TEXTURE_2D, 0);
}
/**
* Penggambaran Skybox
**/
void draw()
{
glDepthMask(GL_FALSE);
glColor3f(0.9f, 0.9f, 1.0f);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, textureSkybox[SKYBOX_RIGHT]);
glBegin(GL_QUADS);
// Kanan
glTexCoord2i(0, 0); glVertex3f(sizeSkybox, sizeSkybox, 0.0f);
glTexCoord2i(1, 0); glVertex3f(sizeSkybox, sizeSkybox, sizeSkybox);
glTexCoord2i(1, 1); glVertex3f(sizeSkybox, 0.0f, sizeSkybox);
glTexCoord2i(0, 1); glVertex3f(sizeSkybox, 0.0f, 0.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D, textureSkybox[SKYBOX_LEFT]);
glBegin(GL_QUADS);
// Kiri
glTexCoord2i(0, 0); glVertex3f(0.0f, sizeSkybox, sizeSkybox);
glTexCoord2i(1, 0); glVertex3f(0.0f, sizeSkybox, 0.0f);
glTexCoord2i(1, 1); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2i(0, 1); glVertex3f(0.0f, 0.0f, sizeSkybox);
glEnd();
glBindTexture(GL_TEXTURE_2D, textureSkybox[SKYBOX_TOP]);
glBegin(GL_QUADS);
// Atas
glTexCoord2i(0, 0); glVertex3f( 0.0f, sizeSkybox, sizeSkybox);
glTexCoord2i(1, 0); glVertex3f(sizeSkybox, sizeSkybox, sizeSkybox);
glTexCoord2i(1, 1); glVertex3f(sizeSkybox, sizeSkybox, 0.0f);
glTexCoord2i(0, 1); glVertex3f( 0.0f, sizeSkybox, 0.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D, textureSkybox[SKYBOX_DOWN]);
glBegin(GL_QUADS);
// Bawah
glTexCoord2i(0, 0); glVertex3f( 0.0f, 0.0f, 0.0f);
glTexCoord2i(1, 0); glVertex3f(sizeSkybox, 0.0f, 0.0f);
glTexCoord2i(1, 1); glVertex3f(sizeSkybox, 0.0f, sizeSkybox);
glTexCoord2i(0, 1); glVertex3f( 0.0f, 0.0f, sizeSkybox);
glEnd();
glBindTexture(GL_TEXTURE_2D, textureSkybox[SKYBOX_FRONT]);
glBegin(GL_QUADS);
// Depan
glTexCoord2i(0, 0); glVertex3f( 0.0f, sizeSkybox, 0.0f);
glTexCoord2i(1, 0); glVertex3f(sizeSkybox, sizeSkybox, 0.0f);
glTexCoord2i(1, 1); glVertex3f(sizeSkybox, 0.0f, 0.0f);
glTexCoord2i(0, 1); glVertex3f( 0.0f, 0.0f, 0.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D, textureSkybox[SKYBOX_BACK]);
glBegin(GL_QUADS);
// Belakang
glTexCoord2i(0, 0); glVertex3f(sizeSkybox, sizeSkybox, sizeSkybox);
glTexCoord2i(1, 0); glVertex3f( 0.0f, sizeSkybox, sizeSkybox);
glTexCoord2i(1, 1); glVertex3f( 0.0f, 0.0f, sizeSkybox);
glTexCoord2i(0, 1); glVertex3f(sizeSkybox, 0.0f, sizeSkybox);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glPopMatrix();
glDepthMask(GL_TRUE);
}
}