perlin noise
This commit is contained in:
parent
48ecd8d9e8
commit
186ea5f204
7 changed files with 279 additions and 61 deletions
39
main.c
39
main.c
|
@ -1,6 +1,3 @@
|
|||
// adapted from
|
||||
// https://github.com/glfw/glfw/blob/master/examples/triangle-opengl.c
|
||||
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "gl.h"
|
||||
#define GLFW_INCLUDE_NONE
|
||||
|
@ -17,26 +14,26 @@
|
|||
|
||||
static const char *vertex_shader_text =
|
||||
"#version 330\n"
|
||||
"layout (location = 0) in vec3 vPos;"
|
||||
"layout (location = 1) in vec3 vOff;"
|
||||
"uniform mat4 MVP;\n"
|
||||
"out vec2 vTex;\n"
|
||||
"layout (location = 0) in vec3 v_pos;"
|
||||
"layout (location = 1) in vec3 v_off;"
|
||||
"uniform mat4 mvp;\n"
|
||||
"out vec2 v_tex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = MVP * vec4(vPos, 1.0);\n"
|
||||
" vTex=vec2(vOff);\n"
|
||||
" gl_Position = mvp * vec4(v_pos, 1.0);\n"
|
||||
" v_tex=vec2(v_off);\n"
|
||||
"}\n";
|
||||
|
||||
static const char *fragment_shader_text =
|
||||
"#version 330\n"
|
||||
"out vec4 color;\n"
|
||||
"in vec2 vTex;\n"
|
||||
"uniform sampler2D texSampler;\n"
|
||||
"in vec2 v_tex;\n"
|
||||
"uniform sampler2D sampler_tex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
//" color=vec4(vTex.rg,0.5,0.5);\n"
|
||||
" if (vTex.x < 0.0 || vTex.y < 0.0) { discard; }\n"
|
||||
" color=vec4(texture(texSampler, vTex).rgb,0.5);\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"
|
||||
"}\n";
|
||||
|
||||
int isCursor = 0;
|
||||
|
@ -87,9 +84,8 @@ int main(void) {
|
|||
|
||||
Vertex *cube = malloc(CTRI_ALL);
|
||||
Vertex *text = malloc(CTRI_ALL);
|
||||
gen_cubes(cube, 0, 0, 0, 0);
|
||||
gen_cubes(text, 0, 0, 0, 1);
|
||||
|
||||
gen_cubes(cube, 1024,0,1024, 0);
|
||||
gen_cubes(text, 1024,0,1024, 1);
|
||||
GLuint vertex_buffer[2];
|
||||
|
||||
GLuint vertex_array;
|
||||
|
@ -121,8 +117,8 @@ int main(void) {
|
|||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint tex_location = glGetUniformLocation(program, "texSampler");
|
||||
GLint mvp_location = glGetUniformLocation(program, "MVP");
|
||||
GLint tex_location = glGetUniformLocation(program, "sampler_tex");
|
||||
GLint mvp_location = glGetUniformLocation(program, "mvp");
|
||||
|
||||
unsigned char *pixels;
|
||||
|
||||
|
@ -136,7 +132,7 @@ int main(void) {
|
|||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
|
||||
vec3 pos = {0, 0, 0};
|
||||
vec3 pos = {1024*CHUNK_LENGTH, 0, 1024*CHUNK_LENGTH};
|
||||
|
||||
int x = 0, y = 25, z = 0;
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
@ -195,13 +191,14 @@ int main(void) {
|
|||
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat *)&mvp);
|
||||
glBindVertexArray(vertex_array);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, BLOCK_ALL * 18);
|
||||
glDrawArrays(GL_TRIANGLES, 0, CBLOCK_ALL * 18);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
free(cube);
|
||||
free(text);
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue