Subfolder for shaders
This commit is contained in:
parent
7d05cb46b3
commit
2844f9a71e
4 changed files with 37 additions and 14 deletions
2
Makefile
2
Makefile
|
|
@ -1,4 +1,4 @@
|
|||
CFLAGS=-Wall -Wextra -g -pedantic -fenable-matrix -Wno-gnu-zero-variadic-macro-arguments
|
||||
CFLAGS=-Wall -Wextra -g -pedantic -fenable-matrix -Wno-gnu-zero-variadic-macro-arguments -Wno-incompatible-pointer-types-discards-qualifiers
|
||||
LIBS=`pkg-config --libs glfw3 glew opengl` -lm
|
||||
|
||||
hexnando: main.c Makefile
|
||||
|
|
|
|||
37
main.c
37
main.c
|
|
@ -12,19 +12,26 @@
|
|||
#define log_err(str, ...) do { fprintf(stderr, "[ERROR] (%s:%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__); } while (0)
|
||||
#define log_debug(str, ...) do { fprintf(stderr, "[DEBUG] (%s:%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__); } while (0)
|
||||
|
||||
/* Globals */
|
||||
const char *vertexShaderSource = "#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||
"}\0";
|
||||
const char *fragmentShaderSource = "#version 330 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||
"}\n\0";
|
||||
|
||||
char *read_entire_file(char *path)
|
||||
{
|
||||
FILE *f = fopen(path, "rb");
|
||||
size_t length = 0;
|
||||
char *buf = NULL;
|
||||
if (f)
|
||||
{
|
||||
fseek(f, 0, SEEK_END);
|
||||
length = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (length)
|
||||
{
|
||||
buf = malloc(length + 1);
|
||||
fread(buf, 1, length, f);
|
||||
buf[length] = '\0';
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void glfw_error_callback(int errcode, const char *description)
|
||||
{
|
||||
|
|
@ -51,6 +58,10 @@ int main()
|
|||
|
||||
// build and compile our shader program
|
||||
// ------------------------------------
|
||||
|
||||
char * vertexShaderSource = read_entire_file("shaders/vertex.glsl");
|
||||
char *fragmentShaderSource = read_entire_file("shaders/fragment.glsl");
|
||||
|
||||
// vertex shader
|
||||
unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, &vertexShaderSource, NULL);
|
||||
|
|
|
|||
6
shaders/fragment.glsl
Normal file
6
shaders/fragment.glsl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#version 330 core
|
||||
out vec4 color;
|
||||
void main()
|
||||
{
|
||||
color = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
}
|
||||
6
shaders/vertex.glsl
Normal file
6
shaders/vertex.glsl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 pos;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(pos, 1.0f);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue