Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-07-07 22:01:36 +0000
committerStijn Buys <ingar@osirion.org>2011-07-07 22:01:36 +0000
commit035c602e0afc659b344d685614ec7a2e334636b6 (patch)
tree50e5694005cdd4b10844129a29bea9dfa8350a57 /src/render
parent2c10d5b9b8a9f651006e4f7b376b21ee0713b398 (diff)
Disable mipmapping on skybox textures, provide an OpenGL texture id for the cubemap.
Diffstat (limited to 'src/render')
-rw-r--r--src/render/draw.cc53
-rw-r--r--src/render/textures.cc38
-rw-r--r--src/render/textures.h1
3 files changed, 47 insertions, 45 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 46f62ca..792969f 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -175,50 +175,53 @@ void draw_pass_sky()
return;
Textures::load_cubemap("textures/sky/" + core::localplayer()->zone()->sky());
+
+ gl::enable(GL_TEXTURE_CUBE_MAP);
gl::push();
gl::translate(Camera::eye());
gl::color(1.0f, 1.0f, 1.0f, 1.0f);
- gl::enable(GL_TEXTURE_CUBE_MAP);
+
+ const float r = 128.0f;
gl::begin((r_wireframe && r_wireframe->value()) ? gl::LineLoop : gl::Quads);
// front
- gl::texcoord(1, 1, 1); gl::vertex(1, 1, 1);
- gl::texcoord(1, -1, 1); gl::vertex(1, -1, 1);
- gl::texcoord(1, -1, -1); gl::vertex(1, -1, -1);
- gl::texcoord(1, 1, -1); gl::vertex(1, 1, -1);
+ gl::texcoord(1, 1, 1); gl::vertex(r, r, r);
+ gl::texcoord(1, -1, 1); gl::vertex(r, -r, r);
+ gl::texcoord(1, -1, -1); gl::vertex(r, -r, -r);
+ gl::texcoord(1, 1, -1); gl::vertex(r, r, -r);
// right
- gl::texcoord(1, -1, 1); gl::vertex(1, -1, 1);
- gl::texcoord(-1, -1, 1); gl::vertex(-1, -1, 1);
- gl::texcoord(-1, -1, -1); gl::vertex(-1, -1, -1);
- gl::texcoord(1, -1, -1); gl::vertex(1, -1, -1);
+ gl::texcoord(1, -1, 1); gl::vertex(r, -r, r);
+ gl::texcoord(-1, -1, 1); gl::vertex(-r, -r, r);
+ gl::texcoord(-1, -1, -1); gl::vertex(-r, -r, -r);
+ gl::texcoord(1, -1, -1); gl::vertex(r, -r, -r);
// back
- gl::texcoord(-1, -1, 1); gl::vertex(-1, -1, 1);
- gl::texcoord(-1, 1, 1); gl::vertex(-1, 1, 1);
- gl::texcoord(-1, 1, -1); gl::vertex(-1, 1, -1);
- gl::texcoord(-1, -1, -1); gl::vertex(-1, -1, -1);
+ gl::texcoord(-1, -1, 1); gl::vertex(-r, -r, r);
+ gl::texcoord(-1, 1, 1); gl::vertex(-r, r, r);
+ gl::texcoord(-1, 1, -1); gl::vertex(-r, r, -r);
+ gl::texcoord(-1, -1, -1); gl::vertex(-r, -r, -r);
// left
- gl::texcoord(-1, 1, 1); gl::vertex(-1, 1, 1);
- gl::texcoord(1, 1, 1); gl::vertex(1, 1, 1);
- gl::texcoord(1, 1, -1); gl::vertex(1, 1, -1);
- gl::texcoord(-1, 1, -1); gl::vertex(-1, 1, -1);
+ gl::texcoord(-1, 1, 1); gl::vertex(-r, r, r);
+ gl::texcoord(1, 1, 1); gl::vertex(r, r, r);
+ gl::texcoord(1, 1, -1); gl::vertex(r, r, -r);
+ gl::texcoord(-1, 1, -1); gl::vertex(-r, r, -r);
// up
- gl::texcoord(-1, 1, 1); gl::vertex(-1, 1, 1);
- gl::texcoord(-1, -1, 1); gl::vertex(-1, -1, 1);
- gl::texcoord(1, -1, 1); gl::vertex(1, -1, 1);
- gl::texcoord(1, 1, 1); gl::vertex(1, 1, 1);
+ gl::texcoord(-1, 1, 1); gl::vertex(-r, r, r);
+ gl::texcoord(-1, -1, 1); gl::vertex(-r, -r, r);
+ gl::texcoord(1, -1, 1); gl::vertex(r, -r, r);
+ gl::texcoord(1, 1, 1); gl::vertex(r, r, r);
// down
- gl::texcoord(1, 1, -1); gl::vertex(1, 1, -1);
- gl::texcoord(1, -1, -1); gl::vertex(1, -1, -1);
- gl::texcoord(-1, -1, -1); gl::vertex(-1, -1, -1);
- gl::texcoord(-1, 1, -1); gl::vertex(-1, 1, -1);
+ gl::texcoord(1, 1, -1); gl::vertex(r, r, -r);
+ gl::texcoord(1, -1, -1); gl::vertex(r, -r, -r);
+ gl::texcoord(-1, -1, -1); gl::vertex(-r, -r, -r);
+ gl::texcoord(-1, 1, -1); gl::vertex(-r, r, -r);
gl::end();
diff --git a/src/render/textures.cc b/src/render/textures.cc
index ad1d8d1..687d245 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -20,6 +20,7 @@ namespace render
std::map<std::string, size_t> Textures::registry;
GLuint Textures::textures[MAXTEXTURES];
+GLuint Textures::textures_cubemap_id;
math::Vector2f Textures::texture_size[MAXTEXTURES];
std::string textures_cubemapname;
@@ -32,6 +33,8 @@ void Textures::init()
{
con_print << "^BLoading textures..." << std::endl;
+ glGenTextures(1, &textures_cubemap_id);
+
if (registry.size()) {
clear();
} else {
@@ -83,6 +86,9 @@ void Textures::clear()
registry.clear();
memset(textures, 0, sizeof(textures));
+ // clear cubemap
+ glDeleteTextures(1, &textures_cubemap_id);
+ textures_cubemap_id = 0;
textures_cubemapname.clear();
}
@@ -127,7 +133,7 @@ void Textures::load_cubemap(const std::string & name)
textures_cubemapname.assign(name);
-const GLenum cube_map[6] = {
+ const GLenum cube_map[6] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
@@ -147,6 +153,8 @@ const GLenum cube_map[6] = {
};
+ // load six skybox images and apply the necessary transformations
+
if (cube_texture[0]) {
Image *image = cube_texture[0];
@@ -238,20 +246,17 @@ const GLenum cube_map[6] = {
}
}
}
+
+ glBindTexture(GL_TEXTURE_CUBE_MAP, textures_cubemap_id);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
- // 4 levels of mipmaps
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 4);
-
- if (r_mipmap->value()) {
- // hardware generated mipmaps (requires OpenGL 1.4)
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
- }
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0);
for (size_t i = 0; i < 6; i++) {
if (cube_texture[i]) {
@@ -264,18 +269,11 @@ const GLenum cube_map[6] = {
} else {
texture_format = GL_RGB;
texture_internalformat = GL_RGB8;
- }
+ }
+ glTexImage2D(cube_map[i], 0,
+ texture_internalformat, cube_texture[i]->width(), cube_texture[i]->height(), 0,
+ texture_format, GL_UNSIGNED_BYTE, cube_texture[i]->ptr());
- if (r_mipmap->value() <= 0) {
- gluBuild2DMipmaps(cube_map[i],
- texture_internalformat, cube_texture[i]->width(), cube_texture[i]->height(),
- texture_format, GL_UNSIGNED_BYTE, cube_texture[i]->ptr());
- } else {
- glTexImage2D(cube_map[i], 0,
- texture_internalformat, cube_texture[i]->width(), cube_texture[i]->height(), 0,
- texture_format, GL_UNSIGNED_BYTE, cube_texture[i]->ptr());
- }
-
delete cube_texture[i];
}
}
diff --git a/src/render/textures.h b/src/render/textures.h
index 90b26b1..69442e8 100644
--- a/src/render/textures.h
+++ b/src/render/textures.h
@@ -71,6 +71,7 @@ private:
static math::Vector2f texture_size[MAXTEXTURES];
static std::map<std::string, size_t> registry;
static GLuint textures[MAXTEXTURES];
+ static GLuint textures_cubemap_id;
};
}