# HG changeset patch # User John Tsiombikas # Date 1391294122 -7200 # Node ID e7ca128b8713019ecfe8ceb274bdd08c2c5e2449 # Parent b2f14e5352531a891dbb5aabcc6f7e1fca686587 looks nice :) diff -r b2f14e535253 -r e7ca128b8713 sdr/level.p.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sdr/level.p.glsl Sun Feb 02 00:35:22 2014 +0200 @@ -0,0 +1,14 @@ +uniform sampler2D tex; + +varying vec3 vpos; +varying vec2 texcoord; + +void main() +{ + vec4 tex = texture2D(tex, texcoord.xy); + + float fog = clamp(40.0 / (vpos.z * vpos.z), 0.0, 1.0); + + gl_FragColor.rgb = tex.rgb * fog; + gl_FragColor.a = tex.a; +} diff -r b2f14e535253 -r e7ca128b8713 sdr/texmap.p.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sdr/texmap.p.glsl Sun Feb 02 00:35:22 2014 +0200 @@ -0,0 +1,20 @@ +uniform sampler2D tex; + +varying vec3 vpos, norm; +varying vec2 texcoord; + +void main() +{ + vec3 n = normalize(norm); + vec3 ldir = normalize(vec3(-0.5, 0.5, 2)); + + float ndotl = max(dot(n, ldir), 0.0); + + vec3 color = vec3(0.8, 0.8, 0.8) * ndotl; + + vec4 tex = texture2D(tex, texcoord.xy); + + + gl_FragColor.rgb = color * tex.rgb; + gl_FragColor.a = tex.a; +} diff -r b2f14e535253 -r e7ca128b8713 src/level.cc --- a/src/level.cc Sat Feb 01 19:58:19 2014 +0200 +++ b/src/level.cc Sun Feb 02 00:35:22 2014 +0200 @@ -1,17 +1,27 @@ +#include #include "level.h" #include "logger.h" +#include "texman.h" +#include "sdrman.h" static void gen_mesh(Mesh *mesh); +static ShaderProg *level_sdr; + Level::Level() { - dlimit_near = -2; - dlimit_far = 8; + dlimit_near = 0; + dlimit_far = 25; + + fly_speed = 3.0; gen_mesh(&tile_mesh); tile_obj = new Object; tile_obj->set_mesh(&tile_mesh); + tile_obj->material.tex[0] = texset.get("data/purple_grid.png"); + + level_sdr = get_sdrprog("sdr/default.v.glsl", "sdr/level.p.glsl"); } Level::~Level() @@ -25,58 +35,79 @@ dlimit_far = dfar; } -void Level::draw() const +void Level::draw(long msec) const { AABox bbox = tile_obj->get_aabbox(); float zsize = bbox.max.z - bbox.min.z; float zoffs = -zsize / 2.0; + float tm = (float)msec / 1000.0; + + level_sdr->bind(); + float z = dlimit_near; while(z < dlimit_far) { - tile_obj->set_position(Vector3(0, 0, -(z - zoffs))); + tile_obj->set_position(Vector3(0, 0, -(z - zoffs) + fmod(tm * fly_speed, zsize))); + + // draw mirrored + glFrontFace(GL_CW); + tile_obj->set_scaling(Vector3(-1, 1, 1)); tile_obj->draw(); + glFrontFace(GL_CCW); + tile_obj->set_scaling(Vector3(1, 1, 1)); + tile_obj->draw(); + z += zsize; } } +#define DEPTH 2.0 +#define POSTZ (0.8 * DEPTH) + static void gen_mesh(Mesh *mesh) { - /* left vertical side */ + // vertical side mesh->normal(1, 0, 0); - mesh->texcoord(0, 0); mesh->vertex(-2, 0, 1); - mesh->texcoord(1, 0); mesh->vertex(-2, 0, -1); - mesh->texcoord(1, 1); mesh->vertex(-2, 1, -1); - mesh->texcoord(0, 1); mesh->vertex(-2, 1, 1); + mesh->texcoord(0, 0); mesh->vertex(-2, 0, DEPTH); + mesh->texcoord(3, 0); mesh->vertex(-2, 0, -DEPTH); + mesh->texcoord(3, 2); mesh->vertex(-2, 1, -DEPTH); + mesh->texcoord(0, 2); mesh->vertex(-2, 1, DEPTH); - /* left diagonal */ + // left diagonal Vector3 dnorm = Vector3(0.5, 1, 0).normalized(); mesh->normal(dnorm.x, dnorm.y, dnorm.z); - mesh->texcoord(0, 0); mesh->vertex(-1, -0.5, 1); - mesh->texcoord(1, 0); mesh->vertex(-1, -0.5, -1); - mesh->texcoord(1, 1); mesh->vertex(-2, 0, -1); - mesh->texcoord(0, 1); mesh->vertex(-2, 0, 1); + mesh->texcoord(0, 0); mesh->vertex(-1, -0.5, DEPTH); + mesh->texcoord(3, 0); mesh->vertex(-1, -0.5, -DEPTH); + mesh->texcoord(3, 2); mesh->vertex(-2, 0, -DEPTH); + mesh->texcoord(0, 2); mesh->vertex(-2, 0, DEPTH); + + // vertical post front + mesh->normal(0, 0, 1); + mesh->texcoord(0, 0); mesh->vertex(-2, -0.5, -POSTZ); + mesh->texcoord(1, 0); mesh->vertex(-1.7, -0.5, -POSTZ); + mesh->texcoord(1, 3); mesh->vertex(-1.7, 1, -POSTZ); + mesh->texcoord(0, 3); mesh->vertex(-2, 1, -POSTZ); + + // vertical post side + mesh->normal(1, 0, 0); + mesh->texcoord(0, 0); mesh->vertex(-1.7, -0.5, -POSTZ); + mesh->texcoord(1, 0); mesh->vertex(-1.7, -0.5, -DEPTH); + mesh->texcoord(1, 3); mesh->vertex(-1.7, 1, -DEPTH); + mesh->texcoord(0, 3); mesh->vertex(-1.7, 1, -POSTZ); + + // vertical post top + mesh->normal(0, 1, 0); + mesh->texcoord(0, 0); mesh->vertex(-2, 1, -POSTZ); + mesh->texcoord(1, 0); mesh->vertex(-1.7, 1, -POSTZ); + mesh->texcoord(1, 1); mesh->vertex(-1.7, 1, -DEPTH); + mesh->texcoord(0, 1); mesh->vertex(-2, 1, -DEPTH); /* floor */ mesh->normal(0, 1, 0); - mesh->texcoord(0, 0); mesh->vertex(-1, -0.5, 1); - mesh->texcoord(1, 0); mesh->vertex(1, -0.5, 1); - mesh->texcoord(1, 1); mesh->vertex(1, -0.5, -1); - mesh->texcoord(0, 1); mesh->vertex(-1, -0.5, -1); - - /* right vertical side */ - mesh->normal(-1, 0, 0); - mesh->texcoord(0, 0); mesh->vertex(2, 0, -1); - mesh->texcoord(1, 0); mesh->vertex(2, 0, 1); - mesh->texcoord(1, 1); mesh->vertex(2, 1, 1); - mesh->texcoord(0, 1); mesh->vertex(2, 1, -1); - - /* right diagonal */ - dnorm = Vector3(-0.5, 1, 0).normalized(); - mesh->normal(dnorm.x, dnorm.y, dnorm.z); - mesh->texcoord(0, 0); mesh->vertex(1, -0.5, -1); - mesh->texcoord(1, 0); mesh->vertex(1, -0.5, 1); - mesh->texcoord(1, 1); mesh->vertex(2, 0, 1); - mesh->texcoord(0, 1); mesh->vertex(2, 0, -1); + mesh->texcoord(0, 0); mesh->vertex(-1, -0.5, DEPTH); + mesh->texcoord(1, 0); mesh->vertex(0, -0.5, DEPTH); + mesh->texcoord(1, 3); mesh->vertex(0, -0.5, -DEPTH); + mesh->texcoord(0, 3); mesh->vertex(-1, -0.5, -DEPTH); // quad face index buffer int nverts = mesh->get_attrib_count(MESH_ATTR_VERTEX); diff -r b2f14e535253 -r e7ca128b8713 src/level.h --- a/src/level.h Sat Feb 01 19:58:19 2014 +0200 +++ b/src/level.h Sun Feb 02 00:35:22 2014 +0200 @@ -13,6 +13,7 @@ std::list enemies; float dlimit_near, dlimit_far; + float fly_speed; public: Level(); @@ -20,7 +21,7 @@ void set_draw_limits(float dnear, float dfar); - void draw() const; + void draw(long msec) const; }; #endif // LEVEL_H_ diff -r b2f14e535253 -r e7ca128b8713 src/scr_game.cc --- a/src/scr_game.cc Sat Feb 01 19:58:19 2014 +0200 +++ b/src/scr_game.cc Sun Feb 02 00:35:22 2014 +0200 @@ -10,9 +10,10 @@ static int win_width, win_height; static bool bnstate[32]; static int prev_x, prev_y; -static float cam_theta, cam_phi = 20, cam_dist = 10; +static float cam_theta, cam_phi = 23, cam_dist = 0; static Object *floor_obj; static Level *level; +static unsigned long msec; const char *GameScreen::get_name() const { @@ -24,11 +25,6 @@ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); - floor_obj = new Object; - floor_obj->set_mesh(new Mesh); - gen_plane(floor_obj->get_mesh(), 10, 10, 4, 4); - floor_obj->set_rotation(Quaternion(Vector3(1, 0, 0), -DEG_TO_RAD(90))); - level = new Level; return true; @@ -40,6 +36,7 @@ void GameScreen::update(unsigned long tmsec) { + msec = tmsec; } void GameScreen::display() const @@ -48,14 +45,13 @@ matrix.translate(Vector3(0, 0, -cam_dist)); matrix.rotate(Vector3(1, 0, 0), DEG_TO_RAD(cam_phi)); matrix.rotate(Vector3(0, 1, 0), DEG_TO_RAD(cam_theta)); + matrix.translate(Vector3(0, -2, 0)); set_view_matrix(matrix); //glUseProgram(0); bind_shader(defsdr); - //floor_obj->draw(); - - level->draw(); + level->draw(msec); } void GameScreen::reshape(int x, int y) diff -r b2f14e535253 -r e7ca128b8713 src/texture.cc --- a/src/texture.cc Sat Feb 01 19:58:19 2014 +0200 +++ b/src/texture.cc Sun Feb 02 00:35:22 2014 +0200 @@ -307,7 +307,6 @@ return load_multi(img, hsix[0], hsix[1], ysz / 2); } - error_log("failed to load %s: unknown cubemap configuration\n", fname); return false; }