21 #define STB_IMAGE_IMPLEMENTATION
27 unsigned char *
pixels =
stbi_load(filename, &width, &height, &channels, 4);
31 LOGE(
"Failed to load texture %s\n", filename);
36 glGenTextures(1, &result);
37 glBindTexture(GL_TEXTURE_2D, result);
38 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
39 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
40 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
41 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
43 glBindTexture(GL_TEXTURE_2D, 0);
50 FILE *file = fopen(filename,
"rb");
53 LOGE(
"Failed to open file %s\n", filename);
56 fseek(file, 0, SEEK_END);
58 fseek(file, 0, SEEK_SET);
59 char *
data = (
char *)calloc(length + 1,
sizeof(
char));
62 LOGE(
"Failed to allocate memory for file data %s\n", filename);
65 size_t read = fread(data,
sizeof(
char), length, file);
68 LOGE(
"Failed to read whole file %s\n", filename);
78 GLuint result = glCreateShader(type);
79 glShaderSource(result, 1, (
const GLchar**)&source, NULL);
80 glCompileShader(result);
82 glGetShaderiv(result, GL_COMPILE_STATUS, &status);
83 if (status == GL_FALSE) {
85 glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length);
86 GLchar *info =
new GLchar[
length];
87 glGetShaderInfoLog(result, length, NULL, info);
88 LOGE(
"[COMPILE] %s\n%s\n", source, info);
98 for (
int i = 0; i <
count; ++i)
99 glAttachShader(program, shaders[i]);
101 glLinkProgram(program);
103 for (
int i = 0; i <
count; ++i)
104 glDetachShader(program, shaders[i]);
107 glGetProgramiv(program, GL_LINK_STATUS, &status);
108 if (status == GL_FALSE) {
110 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
111 GLchar *info =
new GLchar[
length];
112 glGetProgramInfoLog(program, length, NULL, info);
113 LOGE(
"[LINK] %s\n", info);
130 LOGD(
"%s\n", vs_src);
131 LOGD(
"%s\n", fs_src);
void load_assets(App *app)
GLuint load_texture(const char *filename)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const void * pixels
void load_centroid_shader(App *app)
#define SHADER_PATH(name)
char * read_file(const char *filename)
GLint GLsizei GLsizei height
void load_generate_shader(App *app)
#define TEXTURE_PATH(name)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei count
void load_backdrop_shader(App *app)
GLsizei GLsizei GLchar * source
GLuint compile_shader(const char *source, GLenum type)
STBIDEF stbi_uc * stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp)
GLuint link_program(GLuint *shaders, int count)
STBIDEF void stbi_image_free(void *retval_from_stbi_load)
GLenum GLuint GLenum GLsizei length
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
void load_geometry_shader(App *app)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
#define GL_GEOMETRY_SHADER