ShaderTool  0.1
Live tool for developing OpenGL shaders interactively
Functions
shaders.c File Reference
#include <GL/glew.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/inotify.h>
#include "log.h"
#include "renderer.h"
#include "shaders.h"
Include dependency graph for shaders.c:

Functions

int initialize_shaders (struct renderer_state *state, const char *shader_file, const char *buffer_file)
 Initialize shaders and setup inotify if required. More...
 
int compile_shaders (unsigned int *shader_program, const char *const fragment_shader_file)
 Compile shaders from source files. More...
 
char * read_file (const char *const filename)
 Reads a file in a heap-allocated buffer. More...
 

Function Documentation

◆ compile_shaders()

int compile_shaders ( unsigned int *  shader_program,
const char *const  fragment_shader_file 
)

Compile shaders from source files.

This function reads the source files of the vertex and fragment shaders, compiles them, and links them together in a shader program.

Parameters
shader_programPointer to the ID of the shader program where the shaders will be stored.
fragment_shader_fileFile name of the fragment shader.
Returns
0 on success, 1 on error.

◆ initialize_shaders()

int initialize_shaders ( struct renderer_state state,
const char *  shader_file,
const char *  buffer_file 
)

Initialize shaders and setup inotify if required.

Parameters
stateThe target renderer state.
shader_fileThe file name of the screen shader.
buffer_fileThe file name of the buffer shader, or NULL if no buffer shader.
Returns
0 on success, 1 on error.

◆ read_file()

char* read_file ( const char *const  filename)

Reads a file in a heap-allocated buffer.

This function computes the length of the file, allocate a buffer of the correct size, and reads the file in the buffer. Returns NULL on error.

Parameters
filenameThe file to read.
Returns
A buffer containing the contents of the file, or NULL if there was an error.