diff --git a/main.c b/main.c index 7a80cab..9d08c01 100644 --- a/main.c +++ b/main.c @@ -56,11 +56,9 @@ int main(void) { int w, h, c; unsigned char *terrain_img = stbi_load("terrain.png", &w, &h, &c, 0); - w = 100; - h = 100; int vcount = w * h * 3; float *verts = malloc(vcount * sizeof(float)); - float scale_y = 0.3f; + float scale_y = 1.0f; float shift_y = 16.0f; for (int row = 0; row < h; row++) { for (int col = 0; col < w; col++) { @@ -137,17 +135,18 @@ int main(void) { quit = true; } else { char key = e.key.keysym.sym; + float speed = 1.1f; if (key == 'w') { - y += 0.01f; + y += speed; } if (key == 's') { - y -= 0.01f; + y -= speed; } if (key == 'a') { - x += 0.01f; + x += speed; } if (key == 'd') { - x -= 0.01f; + x -= speed; } } } @@ -156,7 +155,7 @@ int main(void) { glm_mat4_identity(model); mat4 view; glm_mat4_identity(view); - glm_translate(model, (vec3){0.0f, x, y}); + glm_translate(model, (vec3){x, y, 0.0f}); // glm_translate(model, (vec3){10.0f, -10.0f, 0.0f}); // glm_rotate(model, now * 0.0000000001f, (vec3){0.0f, 0.0f, 1.0f}); diff --git a/shaders/main.frag b/shaders/main.frag index ac2d868..43e2fe5 100644 --- a/shaders/main.frag +++ b/shaders/main.frag @@ -1,7 +1,8 @@ #version 330 core - +in float Height; out vec4 FragColor; void main() { - FragColor = vec4(1, 1, 1, 1); + float h = (Height + 16)/32.0f; // shift and scale the height into a grayscale value + FragColor = vec4(h, h, h, 1.0); } diff --git a/shaders/main.vert b/shaders/main.vert index 5a1d8f0..4fce656 100644 --- a/shaders/main.vert +++ b/shaders/main.vert @@ -1,10 +1,11 @@ #version 330 core layout (location = 0) in vec3 pos; - +out float Height; uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { + Height = pos.y; gl_Position = projection * view * model * vec4(pos, 1.0); }