27 #define STB_IMAGE_IMPLEMENTATION
33 unsigned char *
pixels =
stbi_load(filename, &width, &height, &channels, 4);
36 LOGE(
"Failed to load texture %s\n", filename);
42 LOGE(
"Cubemap dimensions must match %s\n", filename);
55 glActiveTexture(GL_TEXTURE0);
56 glGenTextures(1, &texture);
57 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
59 glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
61 glPixelStorei(GL_UNPACK_SKIP_PIXELS, s*0);
62 glPixelStorei(GL_UNPACK_SKIP_ROWS, s*2);
63 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA8, s, s, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
65 glPixelStorei(GL_UNPACK_SKIP_PIXELS, s*2);
66 glPixelStorei(GL_UNPACK_SKIP_ROWS, s*2);
67 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA8, s, s, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
69 glPixelStorei(GL_UNPACK_SKIP_PIXELS, s*1);
70 glPixelStorei(GL_UNPACK_SKIP_ROWS, s*3);
71 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, s, s, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
73 glPixelStorei(GL_UNPACK_SKIP_PIXELS, s*1);
74 glPixelStorei(GL_UNPACK_SKIP_ROWS, s*1);
75 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA8, s, s, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
77 glPixelStorei(GL_UNPACK_SKIP_PIXELS, s*3);
78 glPixelStorei(GL_UNPACK_SKIP_ROWS, s*2);
79 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA8, s, s, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
81 glPixelStorei(GL_UNPACK_SKIP_PIXELS, s*1);
82 glPixelStorei(GL_UNPACK_SKIP_ROWS, s*2);
83 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA8, s, s, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
85 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
86 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
87 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
88 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
89 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
90 glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
98 FILE *file = fopen(filename,
"rb");
101 LOGE(
"Failed to open file %s\n", filename);
104 fseek(file, 0, SEEK_END);
105 long length = ftell(file);
106 fseek(file, 0, SEEK_SET);
107 char *
data = (
char *)calloc(length + 1,
sizeof(
char));
110 LOGE(
"Failed to allocate memory for file data %s\n", filename);
113 size_t read = fread(data,
sizeof(
char), length, file);
116 LOGE(
"Failed to read whole file %s\n", filename);
126 GLuint result = glCreateShader(type);
127 glShaderSource(result, 1, (
const GLchar**)&source, NULL);
128 glCompileShader(result);
130 glGetShaderiv(result, GL_COMPILE_STATUS, &status);
131 if (status == GL_FALSE) {
133 glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length);
134 GLchar *info =
new GLchar[
length];
135 glGetShaderInfoLog(result, length, NULL, info);
136 LOGE(
"[COMPILE] %s\n", info);
146 for (
int i = 0; i <
count; ++i)
147 glAttachShader(program, shaders[i]);
149 glLinkProgram(program);
151 for (
int i = 0; i <
count; ++i)
152 glDetachShader(program, shaders[i]);
155 glGetProgramiv(program, GL_LINK_STATUS, &status);
156 if (status == GL_FALSE) {
158 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
159 GLchar *info =
new GLchar[
length];
160 glGetProgramInfoLog(program, length, NULL, info);
161 LOGE(
"[LINK] %s\n", info);
void load_assets(App *app)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const void * pixels
#define DIFFUSEMAP_PATH(name)
#define SHADER_PATH(name)
char * read_file(const char *filename)
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei count
void load_backdrop_shader(App *app)
static vec3 normalize(const vec3 &v)
GLsizei GLsizei GLchar * source
#define GL_TESS_EVALUATION_SHADER
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)
GLuint load_packed_cubemap(const char *filename)
STBIDEF void stbi_image_free(void *retval_from_stbi_load)
GLenum GLuint GLenum GLsizei length
#define GL_TESS_CONTROL_SHADER
#define HEIGHTMAP_PATH(name)
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
void load_mapping_shader(App *app)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count