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
|
/*
render/sky.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "render/camera.h"
#include "render/sky.h"
#include "render/textures.h"
namespace render
{
size_t Sky::sky_texture_up = 0;
size_t Sky::sky_texture_down = 0;
size_t Sky::sky_texture_left = 0;
size_t Sky::sky_texture_right = 0;
size_t Sky::sky_texture_front = 0;
size_t Sky::sky_texture_back = 0;
std::string Sky::sky_name;
void Sky::draw(const std::string & name)
{
if (sky_name.compare(name) != 0) {
unload();
}
if (!sky_name.size()) {
if (name.size()) {
const std::string basename("textures/sky/" + name);
sky_texture_up = Textures::load(basename + "_up");
sky_texture_down = Textures::load(basename + "_down");
sky_texture_left = Textures::load(basename + "_left");
sky_texture_right = Textures::load(basename + "_right");
sky_texture_front = Textures::load(basename + "_front");
sky_texture_back = Textures::load(basename + "_back");
}
sky_name.assign(name);
}
/*
* NOTE
* for quake3 skyboxes: the _left texture is actually the right side of the skybox
*/
gl::push();
gl::translate(Camera::eye());
gl::enable(GL_TEXTURE_2D);
gl::color(1.0f, 1.0f, 1.0f, 1.0f);
// front
Textures::bind(sky_texture_front);
gl::begin(gl::Quads);
gl::texcoord(0, 0); gl::vertex(1, 1, 1);
gl::texcoord(1, 0); gl::vertex(1, -1, 1);
gl::texcoord(1, 1); gl::vertex(1, -1, -1);
gl::texcoord(0, 1); gl::vertex(1, 1, -1);
gl::end();
// right
Textures::bind(sky_texture_right);
gl::begin(gl::Quads);
gl::texcoord(0, 0); gl::vertex(1, -1, 1);
gl::texcoord(1, 0); gl::vertex(-1, -1, 1);
gl::texcoord(1, 1); gl::vertex(-1, -1, -1);
gl::texcoord(0, 1); gl::vertex(1, -1, -1);
gl::end();
// back
Textures::bind(sky_texture_back);
gl::begin(gl::Quads);
gl::texcoord(0, 0); gl::vertex(-1, -1, 1);
gl::texcoord(1, 0); gl::vertex(-1, 1, 1);
gl::texcoord(1, 1); gl::vertex(-1, 1, -1);
gl::texcoord(0, 1); gl::vertex(-1, -1, -1);
gl::end();
// left
Textures::bind(sky_texture_left);
gl::begin(gl::Quads);
gl::texcoord(0, 0); gl::vertex(-1, 1, 1);
gl::texcoord(1, 0); gl::vertex(1, 1, 1);
gl::texcoord(1, 1); gl::vertex(1, 1, -1);
gl::texcoord(0, 1); gl::vertex(-1, 1, -1);
gl::end();
// up
Textures::bind(sky_texture_up);
gl::begin(gl::Quads);
gl::texcoord(0, 0); gl::vertex(-1, 1, 1);
gl::texcoord(1, 0); gl::vertex(-1, -1, 1);
gl::texcoord(1, 1); gl::vertex(1, -1, 1);
gl::texcoord(0, 1); gl::vertex(1, 1, 1);
gl::end();
// down
Textures::bind(sky_texture_down);
gl::begin(gl::Quads);
gl::texcoord(0, 0); gl::vertex(1, 1, -1);
gl::texcoord(1, 0); gl::vertex(1, -1, -1);
gl::texcoord(1, 1); gl::vertex(-1, -1, -1);
gl::texcoord(0, 1); gl::vertex(-1, 1, -1);
gl::end();
gl::pop();
gl::disable(GL_TEXTURE_2D);
}
void Sky::unload()
{
if (sky_texture_up) {
Textures::unload(sky_texture_up);
sky_texture_up = 0;
}
if (sky_texture_down) {
Textures::unload(sky_texture_down);
sky_texture_down = 0;
}
if (sky_texture_left) {
Textures::unload(sky_texture_left);
sky_texture_left = 0;
}
if (sky_texture_right) {
Textures::unload(sky_texture_right);
sky_texture_right = 0;
}
if (sky_texture_front) {
Textures::unload(sky_texture_front);
sky_texture_front = 0;
}
if (sky_texture_back) {
Textures::unload(sky_texture_back);
sky_texture_back = 0;
}
sky_name.clear();
}
} // namespace render
|