fog
This commit is contained in:
parent
887dfbe5c4
commit
5ff44a7335
5 changed files with 115 additions and 39 deletions
29
main.c
29
main.c
|
@ -15,28 +15,37 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gen.h"
|
||||
|
||||
static const char *vertex_shader_text =
|
||||
"#version 330\n"
|
||||
"layout (location = 0) in vec3 v_pos;"
|
||||
"layout (location = 1) in vec3 v_off;"
|
||||
"uniform mat4 mvp;\n"
|
||||
"out vec2 v_tex;\n"
|
||||
"out vec3 v_pos_out;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = mvp * vec4(v_pos, 1.0);\n"
|
||||
" v_tex=vec2(v_off);\n"
|
||||
" v_pos_out=v_pos;\n"
|
||||
"}\n";
|
||||
|
||||
static const char *fragment_shader_text =
|
||||
"#version 330\n"
|
||||
"out vec4 color;\n"
|
||||
"in vec2 v_tex;\n"
|
||||
"in vec3 v_pos_out;\n"
|
||||
"uniform sampler2D sampler_tex;\n"
|
||||
"uniform vec3 center;\n"
|
||||
"float dist;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
//" color=vec4(v_tex.rg,0.5,0.5);\n"
|
||||
" if (v_tex.x < 0.0 || v_tex.y < 0.0) { discard; }\n"
|
||||
" color=vec4(texture(sampler_tex, v_tex).rgb,0.5);\n"
|
||||
" dist = distance(v_pos_out, center)/65;\n"
|
||||
" if (dist > 1.0) { dist = 1.0; }\n"
|
||||
" color=vec4(texture(sampler_tex, v_tex).rgb,1.0)*(1.0-(dist*dist)) + vec4(0.2,0.5,0.7,1.0)*(dist*dist);\n"
|
||||
"}\n";
|
||||
|
||||
int isCursor = 0;
|
||||
|
@ -117,8 +126,8 @@ int main(void) {
|
|||
Vertex *cube = malloc(CTRI_ALL);
|
||||
Vertex *text = malloc(CTRI_ALL);
|
||||
|
||||
int cube_count = gen_cubes(cube, text, 1024 / CHUNK_LENGTH, 64 / CHUNK_LENGTH,
|
||||
1024 / CHUNK_LENGTH, 0, 1);
|
||||
int cube_count = gen_cubes(cube, text, 10240 / CHUNK_LENGTH, 64 / CHUNK_LENGTH,
|
||||
10240 / CHUNK_LENGTH, 0, 1);
|
||||
GLuint vertex_buffer[2];
|
||||
|
||||
GLuint vertex_array;
|
||||
|
@ -152,6 +161,7 @@ int main(void) {
|
|||
|
||||
GLint tex_location = glGetUniformLocation(program, "sampler_tex");
|
||||
GLint mvp_location = glGetUniformLocation(program, "mvp");
|
||||
GLint center_location = glGetUniformLocation(program, "center");
|
||||
|
||||
unsigned char *pixels;
|
||||
|
||||
|
@ -165,7 +175,16 @@ int main(void) {
|
|||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
|
||||
vec3 pos = {1024, 64, 1024};
|
||||
vec3 pos = {10240, 48, 10240};
|
||||
vec3 oldPos = {0,0,0};
|
||||
Chunk ch7;
|
||||
ch7.exists = 0;
|
||||
int state = cube_exists(pos[0], pos[1], pos[2], ch7, 0, 0);
|
||||
|
||||
while (1) {
|
||||
if (state != cube_exists(pos[0], pos[1], pos[2], ch7, 0, 0)) break;
|
||||
pos[1] += (state ? 1 : -1);
|
||||
}
|
||||
|
||||
// int x = 0, y = 25, z = 0;
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
@ -175,7 +194,6 @@ int main(void) {
|
|||
int is_render = 1;
|
||||
|
||||
int last_render = 0;
|
||||
vec3 oldPos = {pos[0], pos[1], pos[2]};
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
|
||||
|
@ -220,6 +238,7 @@ int main(void) {
|
|||
mat4x4_mul(mvp, mvp, m);
|
||||
|
||||
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat *)&mvp);
|
||||
glUniform3fv(center_location, 1, (const GLfloat *)(&(oldPos[0])));
|
||||
|
||||
int ax = (int)(oldPos[0] / CHUNK_LENGTH) - (int)(pos[0] / CHUNK_LENGTH);
|
||||
int ay = (int)(oldPos[1] / CHUNK_LENGTH) - (int)(pos[1] / CHUNK_LENGTH);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue