summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-05-10 15:40:02 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-05-10 15:40:02 +0200
commit7d93cab1eb1629b068858a68ac5e5840fe84a83a (patch)
treefc90eaecc54a03943e4114443ad3d6ad111b9b9a
parent0073f833c88f4a25dadc777495639069ba9d7bed (diff)
Added fog and implemented a simple skybox.
-rw-r--r--.gitignore2
-rw-r--r--scene.cpp31
-rw-r--r--shaders/terrain_fragment.glsl3
-rw-r--r--terrain.cpp17
-rw-r--r--video.cpp2
5 files changed, 41 insertions, 14 deletions
diff --git a/.gitignore b/.gitignore
index c21971d..30475e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@
/textures/unused/
/CEGUI.log
/dist
+/Session.vim
+/map
diff --git a/scene.cpp b/scene.cpp
index b8f7268..bf49c57 100644
--- a/scene.cpp
+++ b/scene.cpp
@@ -316,15 +316,18 @@ void Scene::render() {
//glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
if(render_terrain) {
+ const float fog_color[4] = {1, 1, 1, 0};
+ glFogfv(GL_FOG_COLOR, fog_color);
terrain_program.use();
GLint show_sel = glGetUniformLocation(terrain_program.get_program(), "show_sel");
glUniform1i(show_sel, show_selection ? 1 : 0);
- GLint chunk_pos;
if(show_selection) {
GLint selpos = glGetUniformLocation(terrain_program.get_program(), "selpos");
glUniform3f(selpos, selected.x, selected.y, selected.z);
- chunk_pos = glGetUniformLocation(terrain_program.get_program(), "chunk_pos");
}
+ GLint chunk_pos = glGetUniformLocation(terrain_program.get_program(), "chunk_pos");
+ GLint player_pos = glGetUniformLocation(terrain_program.get_program(), "player_pos");
+ glUniform3f(player_pos, pos.x, pos.y, pos.z);
glEnable(GL_TEXTURE_2D);
@@ -355,8 +358,7 @@ void Scene::render() {
continue;*/
glPushMatrix();
glTranslatef(-pos.x + chunk->x, -pos.y, -pos.z + chunk->y);
- if(show_selection)
- glUniform2f(chunk_pos, chunk->x, chunk->y);
+ glUniform2f(chunk_pos, chunk->x, chunk->y);
glBindBuffer(GL_ARRAY_BUFFER, chunk->vbo_object);
glVertexPointer(3, GL_FLOAT, 0, NULL);
@@ -423,6 +425,27 @@ void Scene::render() {
show_selection = true;
}
+ glDisable(GL_TEXTURE_2D);
+
+ glPushMatrix();
+ glTranslatef(700*cosf(yaw), 0, 700*sinf(yaw));
+ glRotatef(-yaw*180/M_PI+180, 0, 1, 0);
+ glBegin(GL_QUADS);
+ glColor3f(1, 1, 1);
+ glVertex3f(0, 0, -700);
+ glVertex3f(0, 0, 700);
+ glColor3f(.5, .5, 1);
+ glVertex3f(0, 550, 700);
+ glVertex3f(0, 550, -700);
+
+ glVertex3f(0, 550, -700);
+ glVertex3f(0, 550, 700);
+ glColor3f(0, 0, .3);
+ glVertex3f(1000, 550, 700);
+ glVertex3f(1000, 550, -700);
+ glEnd();
+ glPopMatrix();
+
video::ortho();
float height = font->LineHeight();
glColor3f(1, 1, 1);
diff --git a/shaders/terrain_fragment.glsl b/shaders/terrain_fragment.glsl
index 0925c6b..c3f0d46 100644
--- a/shaders/terrain_fragment.glsl
+++ b/shaders/terrain_fragment.glsl
@@ -4,7 +4,7 @@ varying vec3 normal, light_pos, pos;
uniform sampler2D tex[3];
uniform sampler2D marktex;
-uniform vec3 selpos;
+uniform vec3 selpos, player_pos;
uniform bool show_sel;
void main() {
@@ -27,6 +27,7 @@ void main() {
vec2 st = vec2((pos.x + 1 - selpos.x) / 2, (pos.z + 1 - selpos.z) / 2);
gl_FragColor += texture2D(marktex, st);
}
+ gl_FragColor = mix(gl_FragColor, gl_Fog.color, pow(length(player_pos - pos), 2) / 10000);
}
/* vim: set syn=glsl: */
diff --git a/terrain.cpp b/terrain.cpp
index 359cb84..35aef58 100644
--- a/terrain.cpp
+++ b/terrain.cpp
@@ -507,16 +507,17 @@ void Terrain::raise(float x, float z, float radius, float focus, float strength,
}
void Terrain::update(float x, float z) {
+ const int chunk_dist_threshold = chunk_size*4;
std::set<std::pair<int, int> > chunk_indices;
- int i = x - 100;
+ int i = x - chunk_dist_threshold;
i -= i % chunk_size;
- for(; i < x + 100; i += chunk_size) {
- int j = z - 100;
+ for(; i < x + chunk_dist_threshold; i += chunk_size) {
+ int j = z - chunk_dist_threshold;
j -= j % chunk_size;
- for(; j < z + 100; j += chunk_size) {
- float a = i - x;
- float b = j - z;
- if(sqrtf(a*a + b*b) < 100)
+ for(; j < z + chunk_dist_threshold; j += chunk_size) {
+ float a = i - x + chunk_size/2;
+ float b = j - z + chunk_size/2;
+ if(sqrtf(a*a + b*b) < chunk_dist_threshold)
chunk_indices.insert(std::pair<int, int>(i, j));
}
}
@@ -525,7 +526,7 @@ void Terrain::update(float x, float z) {
if(ind_it != chunk_indices.end()) {
chunk_indices.erase(ind_it);
}
- if((*it)->distance(x, z) > 100) {
+ if((*it)->distance(x, z) > chunk_dist_threshold) {
it = chunks.erase(it);
}
}
diff --git a/video.cpp b/video.cpp
index ab9b9d3..29b5bcf 100644
--- a/video.cpp
+++ b/video.cpp
@@ -11,7 +11,7 @@ void video::init() {
surface = SDL_SetVideoMode(width, height, 32, SDL_OPENGL);
- glClearColor(0, 0, 0, 0);
+ glClearColor(1, 1, 1, 0);
glClearDepth(1);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);