Fixed the thing a little

This commit is contained in:
Joseph Ferano 2023-10-30 18:03:51 +07:00
parent d24c35c167
commit b6110e3c73
3 changed files with 12 additions and 11 deletions

15
main.c
View File

@ -56,11 +56,9 @@ int main(void) {
int w, h, c; int w, h, c;
unsigned char *terrain_img = stbi_load("terrain.png", &w, &h, &c, 0); unsigned char *terrain_img = stbi_load("terrain.png", &w, &h, &c, 0);
w = 100;
h = 100;
int vcount = w * h * 3; int vcount = w * h * 3;
float *verts = malloc(vcount * sizeof(float)); float *verts = malloc(vcount * sizeof(float));
float scale_y = 0.3f; float scale_y = 1.0f;
float shift_y = 16.0f; float shift_y = 16.0f;
for (int row = 0; row < h; row++) { for (int row = 0; row < h; row++) {
for (int col = 0; col < w; col++) { for (int col = 0; col < w; col++) {
@ -137,17 +135,18 @@ int main(void) {
quit = true; quit = true;
} else { } else {
char key = e.key.keysym.sym; char key = e.key.keysym.sym;
float speed = 1.1f;
if (key == 'w') { if (key == 'w') {
y += 0.01f; y += speed;
} }
if (key == 's') { if (key == 's') {
y -= 0.01f; y -= speed;
} }
if (key == 'a') { if (key == 'a') {
x += 0.01f; x += speed;
} }
if (key == 'd') { if (key == 'd') {
x -= 0.01f; x -= speed;
} }
} }
} }
@ -156,7 +155,7 @@ int main(void) {
glm_mat4_identity(model); glm_mat4_identity(model);
mat4 view; mat4 view;
glm_mat4_identity(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_translate(model, (vec3){10.0f, -10.0f, 0.0f});
// glm_rotate(model, now * 0.0000000001f, (vec3){0.0f, 0.0f, 1.0f}); // glm_rotate(model, now * 0.0000000001f, (vec3){0.0f, 0.0f, 1.0f});

View File

@ -1,7 +1,8 @@
#version 330 core #version 330 core
in float Height;
out vec4 FragColor; out vec4 FragColor;
void main() { 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);
} }

View File

@ -1,10 +1,11 @@
#version 330 core #version 330 core
layout (location = 0) in vec3 pos; layout (location = 0) in vec3 pos;
out float Height;
uniform mat4 model; uniform mat4 model;
uniform mat4 view; uniform mat4 view;
uniform mat4 projection; uniform mat4 projection;
void main() { void main() {
Height = pos.y;
gl_Position = projection * view * model * vec4(pos, 1.0); gl_Position = projection * view * model * vec4(pos, 1.0);
} }