Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented window specific behavior and fixed shader load #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,7 +133,20 @@ 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;
}
// 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;
}
#else
struct stat sb = {0};
if (stat(file_path, &sb) < 0) return errno;
Expand Down
7 changes: 4 additions & 3 deletions src/simple_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down