commit 5b9cecaf6d566ee3f2b0cb0684eec2ce247dbbca
parent fc0b2147c4df50a96dfced9f1e5b1e2625dfaeae
Author: William Casarin <jb55@jb55.com>
Date: Tue, 24 Apr 2018 17:05:47 -0700
WIP
Diffstat:
8 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/etc/shaders/test.f.glsl b/etc/shaders/test.f.glsl
@@ -1,9 +1,15 @@
+#version 320 es
+
+
+precision mediump float;
uniform float fade_factor;
-varying vec3 v_norm;
-out vec4 frag_color;
+flat in vec3 v_norm;
+flat in float v_dot;
+out vec4 fragmentColor;
+
void main() {
vec4 color = vec4(0.4, 0.4, 0.8, 0.5);
- frag_color = vec4(v_norm, 1);
+ fragmentColor = vec4(color.xyz * v_dot, 1.0);
}
diff --git a/etc/shaders/test.v.glsl b/etc/shaders/test.v.glsl
@@ -1,12 +1,13 @@
+#version 320 es
-attribute vec3 position;
-attribute vec3 normal;
+in vec3 position;
+in vec3 normal;
uniform mat4 mvp;
uniform mat4 normal_matrix;
-varying float v_dot;
-varying vec3 v_norm;
+flat out float v_dot;
+flat out vec3 v_norm;
uniform vec3 light_dir;
@@ -14,6 +15,6 @@ void main()
{
vec4 trans_normal = normal_matrix * vec4(normal, 1);
gl_Position = mvp * vec4(position.xyz, 1.0);
- v_dot = dot(normal, light_dir);
+ v_dot = dot(trans_normal.xyz, vec3(1,1,0));
v_norm = normal;
}
diff --git a/src/debug.c b/src/debug.c
@@ -4,5 +4,15 @@
#include <stdio.h>
void
-show_info_log() {
+show_info_log(GLuint shader) {
+ GLint msgLen = 0;
+ glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &msgLen);
+
+ // The maxLength includes the NULL character
+ char *buffer = malloc(msgLen);
+ glGetShaderInfoLog(shader, msgLen, &msgLen, buffer);
+
+ printf("shader error: %s\n", buffer);
+
+ free(buffer);
}
diff --git a/src/debug.h b/src/debug.h
@@ -4,7 +4,7 @@
#include "gl.h"
-void show_info_log(void);
+void show_info_log(GLuint shader);
#endif /* POLYADVENT_DEBUG_H */
diff --git a/src/main.c b/src/main.c
@@ -25,7 +25,6 @@ int main(void)
size_t length;
/* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_Window *window = SDL_CreateWindow(
"SDL2/OpenGL Demo", 0, 0, 640, 480,
diff --git a/src/render.c b/src/render.c
@@ -57,8 +57,8 @@ void
init_gl(struct resources *resources) {
float tmp_matrix[16];
glEnable(GL_DEPTH_TEST);
- /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */
- /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); */
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
// VBOs
make_vertex_buffer(
@@ -214,5 +214,8 @@ void render (struct resources * resources, struct geometry *geom) {
glUniformMatrix4fv(resources->uniforms.mvp, 1, 0, tmp_matrix);
/* render_cube(resources); */
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
render_geom(resources, geom, GL_TRIANGLES);
+ /* glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); */
+ /* render_geom(resources, geom, GL_TRIANGLES); */
}
diff --git a/src/shader.c b/src/shader.c
@@ -24,11 +24,11 @@ make_shader(GLenum type, const char *filename) {
free(source);
glCompileShader(shader);
- glGetShaderiv(shader, GL_COMPILE_STATUS, &shader_ok);
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &shader_ok);
if (!shader_ok) {
fprintf(stderr, "Failed to compile %s:\n", filename);
- //show_info_log(shader, glGetShaderiv, glGetShaderInfoLog);
+ show_info_log(shader);
glDeleteShader(shader);
return 0;
}
@@ -52,7 +52,7 @@ make_program(GLuint vertex_shader, GLuint fragment_shader) {
glGetProgramiv(program, GL_LINK_STATUS, &program_ok);
if (!program_ok) {
fprintf(stderr, "Failed to link shader program:\n");
- //show_info_log(program, glGetProgramiv, glGetProgramInfoLog);
+ show_info_log(program);
glDeleteProgram(program);
return 0;
}
diff --git a/src/terrain.c b/src/terrain.c
@@ -16,8 +16,10 @@ static const u32 plane_indices[] = {
};
-double old_noisy_boi(double x, double y) {
- return sin(x/5.0) * cos(y/5.0) * rand_0to1() * 10;
+double old_noisy_boi(double x, double y, double *dx, double *dy) {
+ double z = sin(x/5.0) * cos(y/5.0) * 5.0;
+ /* *dx = */
+ return z;
}
void
@@ -39,9 +41,10 @@ terrain_create(struct terrain *terrain) {
// 100 random samples from our noise function
for (i = 0; i < num_verts; i++) {
int n = i*3;
+ double dx, dy;
double x = rand_0to1() * 100.0;
double y = rand_0to1() * 100.0;
- double z = old_noisy_boi(x, y);
+ double z = old_noisy_boi(x, y, &dx, &dy);
points[i].x = x;
points[i].y = y;
@@ -121,12 +124,12 @@ terrain_create(struct terrain *terrain) {
make_buffer_geometry(&terrain->geom);
- /* delaunay2d_release(del); */
- /* tri_delaunay2d_release(tri); */
+ delaunay2d_release(del);
+ tri_delaunay2d_release(tri);
- /* free(points); */
- /* free(verts); */
- /* free(normals); */
+ free(points);
+ free(verts);
+ free(normals);
}
void