From ef0629edf3b2d1e61e5b3a9f96b896f161b7c802 Mon Sep 17 00:00:00 2001 From: Joshua Ng Date: Thu, 10 Aug 2023 04:31:01 +0800 Subject: [PATCH 1/2] Implemented window specific calls and fixed shader load Implemented type_of_file for windows and fixed shader bug when it fails to compile on load --- src/common.c | 12 ++++++++++-- src/simple_renderer.c | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/common.c b/src/common.c index 46bcfc50..93d07d5a 100644 --- a/src/common.c +++ b/src/common.c @@ -94,7 +94,7 @@ Errno read_entire_file(const char *file_path, String_Builder *sb) Errno result = 0; FILE *f = NULL; - f = fopen(file_path, "r"); + f = fopen(file_path, "rb"); if (f == NULL) return_defer(errno); size_t size; @@ -133,7 +133,15 @@ Vec4f hex_to_vec4f(uint32_t color) Errno type_of_file(const char *file_path, File_Type *ft) { #ifdef _WIN32 -#error "TODO: type_of_file() is not implemented for Windows" + DWORD file_obj_type = GetFileAttributesA(file_path); + if (file_obj_type == FILE_ATTRIBUTE_DIRECTORY) + { + *ft = FT_DIRECTORY; + } + else + { + *ft = FT_OTHER; + } #else struct stat sb = {0}; if (stat(file_path, &sb) < 0) return errno; diff --git a/src/simple_renderer.c b/src/simple_renderer.c index 546678b7..249f2c1c 100644 --- a/src/simple_renderer.c +++ b/src/simple_renderer.c @@ -29,10 +29,11 @@ static const char *shader_type_as_cstr(GLuint shader) } } -static bool compile_shader_source(const GLchar *source, GLenum shader_type, GLuint *shader) +static bool compile_shader_source(const String_Builder source, GLenum shader_type, GLuint *shader) { *shader = glCreateShader(shader_type); - glShaderSource(*shader, 1, &source, NULL); + GLint source_count=(GLint)source.count; + glShaderSource(*shader, 1, &source.items, &source_count); glCompileShader(*shader); GLint compiled = 0; @@ -62,7 +63,7 @@ static bool compile_shader_file(const char *file_path, GLenum shader_type, GLuin } sb_append_null(&source); - if (!compile_shader_source(source.items, shader_type, shader)) { + if (!compile_shader_source(source, shader_type, shader)) { fprintf(stderr, "ERROR: failed to compile `%s` shader file\n", file_path); return_defer(false); } From 8e339ec726fdb68a594d73bd94350d75b3f70bd5 Mon Sep 17 00:00:00 2001 From: Joshua Ng Date: Thu, 10 Aug 2023 06:09:10 +0800 Subject: [PATCH 2/2] Fixed type_of_file Fixed file opening for 'normal' files in type_of_file --- src/common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index 93d07d5a..3963c30c 100644 --- a/src/common.c +++ b/src/common.c @@ -134,10 +134,15 @@ Errno type_of_file(const char *file_path, File_Type *ft) { #ifdef _WIN32 DWORD file_obj_type = GetFileAttributesA(file_path); - if (file_obj_type == FILE_ATTRIBUTE_DIRECTORY) + if (file_obj_type & FILE_ATTRIBUTE_DIRECTORY) { *ft = FT_DIRECTORY; } + // I have no idea why, but a 'normal' file is considered an archive file? + else if (file_obj_type & FILE_ATTRIBUTE_ARCHIVE) + { + *ft = FT_REGULAR; + } else { *ft = FT_OTHER;