think this solves stupid

This commit is contained in:
Rakarake 2026-01-03 18:38:22 +01:00
parent fc0bb752f7
commit 502f584fbf
3 changed files with 120 additions and 26 deletions

View file

@ -63,29 +63,31 @@ GLuint load_shader(const char *path) {
fseek(handle, 0L, SEEK_END);
long length = ftell(handle);
fseek(handle, 0L, SEEK_SET);
char *string = malloc(length * sizeof(char));
char *string = malloc((length + 1) * sizeof(char));
if (!fread(string, sizeof(char), length, handle)) {
printf("failed to read shader file\n");
exit(1);
}
// I love C
string[length] = '\0';
fclose(handle);
GLuint shader = create_shader(string);
//if (shader == 0) {
// // print file
// int line_count = 1;
// printf("%i\t", line_count);
// line_count++;
// for (int i = 0; i < length; i++) {
// printf("%c", string[i]);
// if (string[i] == '\n') {
// printf("%i\t", line_count);
// line_count++;
// }
// }
// printf("\n");
//}
if (shader == 0) {
// print file
int line_count = 1;
printf("%i\t", line_count);
line_count++;
for (int i = 0; i < length; i++) {
printf("%c", string[i]);
if (string[i] == '\n') {
printf("%i\t", line_count);
line_count++;
}
}
printf("\n");
}
free(string);
return shader;
@ -147,11 +149,8 @@ int shader_file_was_modified(Renderer *state) {
/// shader_path cannot be NULL.
void render(Renderer *state, int w, int h, double time, char *shader_path, int reload_shader) {
int m = shader_file_was_modified(state);
if (m) {
printf("AWOOGA\n");
}
if (m || reload_shader || strcmp(state->shader_path, shader_path)) {
printf("reloading!\n");
state->shader = load_shader(shader_path);
state->shader_path = shader_path;
}