Merge: roberto -> main

This commit is contained in:
PedroEdiaz
2024-11-16 13:12:16 -06:00
5 changed files with 29 additions and 22 deletions

View File

@@ -1,7 +1,7 @@
#include "main.h"
#ifdef GLAD
#include <glad.h>
#include <GLFW/glfw3.h>
#include <glad.h>
#else
#include <GL/glew.h>
#endif
@@ -19,9 +19,8 @@ int init_context(void)
return gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
#else
return glewInit() == GLEW_OK;
return glewInit();
#endif
}
void clean_context(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }

View File

@@ -46,27 +46,32 @@ const char * fs_plain =
" FragColor = texture( palette, vec3( 0, 0, index ) ).rgba;"
"}";
const char * fs =
"#version 330 core\n"
"#version 330 core\n"
"uniform sampler2DArray palette;"
"uniform sampler2DArray palette;"
"in float index;"
"out vec4 FragColor;"
"in vec3 Normal;"
"in vec3 FragPos;"
"in float index;"
"in vec3 Normal;"
"in vec3 FragPos;"
"void main()"
"{"
"out vec4 FragColor;"
" vec4 color = texture( palette, vec3( 0, 0, index ) ).rgba;"
" vec3 lightPos = vec3(0,0,-15);"
" vec3 lightDir = normalize(lightPos - FragPos);"
"void main()"
"{"
" vec4 color = texture(palette, vec3(0, 0, index));\n"
" float diffuse = abs(dot(Normal, lightDir)); "
" vec3 viewPos = vec3(0, 0, -15);\n"
" vec3 viewDir = normalize(viewPos - FragPos);\n"
" FragColor = (0.5 + 0.5*diffuse)*color;"
"}";
" vec3 lightPos = viewPos;\n"
" vec3 lightDir = normalize(lightPos - FragPos);\n"
" vec3 halfwayDir = normalize(lightDir + viewDir);\n"
" float specular = pow(max(dot(normalize(Normal), halfwayDir), 0.0), 16.0);\n"
" float diffuse = max(dot(normalize(Normal), lightDir), 0.0);\n"
" vec3 result = (0.5 + 0.5 * diffuse + specular) * color.rgb;\n"
" FragColor = vec4(result, color.a);\n"
"}";

0
src/main.c Normal file → Executable file
View File

View File

@@ -68,8 +68,8 @@ mesh_t create_mesh(float *d, float *n, unsigned char m)
{
glGenBuffers(1, &p->n_vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p->n_vbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, p->vertex * m * sizeof(float), n + 1,
GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, p->vertex * m * sizeof(float),
n + 1, GL_STATIC_DRAW);
}
for (i = 0; i < 4; ++i)