From 600f0eadd96adf47756a5144037d2d4cb48b7dd5 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 29 Dec 2017 13:06:38 +0200 Subject: [PATCH] Better Windows and Linux compatibility --- Makefile | 1 + SDL/opengl_compat.c | 34 ++++++++++++++++++++++++++++++++++ SDL/opengl_compat.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ SDL/shader.c | 2 +- SDL/shader.h | 3 +-- Windows/inttypes.h | 1 + 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 SDL/opengl_compat.c create mode 100644 SDL/opengl_compat.h create mode 100755 Windows/inttypes.h diff --git a/Makefile b/Makefile index dde767d..36fa1ec 100755 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ SDL_LDFLAGS := -lSDL2 -lGL ifeq ($(PLATFORM),windows32) CFLAGS += -IWindows LDFLAGS += -lmsvcrt -lSDL2main -Wl,/MANIFESTFILE:NUL +SDL_LDFLAGS := -lSDL2 -lopengl32 else LDFLAGS += -lc -lm endif diff --git a/SDL/opengl_compat.c b/SDL/opengl_compat.c new file mode 100644 index 0000000..aed2a76 --- /dev/null +++ b/SDL/opengl_compat.c @@ -0,0 +1,34 @@ +#define GL_GLEXT_PROTOTYPES +#include + +#ifndef __APPLE__ +#define GL_COMPAT_NAME(func) gl_compat_##func +#define GL_COMPAT_VAR(func) typeof(func) *GL_COMPAT_NAME(func) + +GL_COMPAT_VAR(glCreateShader); +GL_COMPAT_VAR(glGetAttribLocation); +GL_COMPAT_VAR(glGetUniformLocation); +GL_COMPAT_VAR(glUseProgram); +GL_COMPAT_VAR(glGenVertexArrays); +GL_COMPAT_VAR(glBindVertexArray); +GL_COMPAT_VAR(glGenBuffers); +GL_COMPAT_VAR(glBindBuffer); +GL_COMPAT_VAR(glBufferData); +GL_COMPAT_VAR(glEnableVertexAttribArray); +GL_COMPAT_VAR(glVertexAttribPointer); +GL_COMPAT_VAR(glCreateProgram); +GL_COMPAT_VAR(glAttachShader); +GL_COMPAT_VAR(glLinkProgram); +GL_COMPAT_VAR(glGetProgramiv); +GL_COMPAT_VAR(glGetProgramInfoLog); +GL_COMPAT_VAR(glDeleteShader); +GL_COMPAT_VAR(glUniform2f); +GL_COMPAT_VAR(glActiveTexture); +GL_COMPAT_VAR(glUniform1i); +GL_COMPAT_VAR(glBindFragDataLocation); +GL_COMPAT_VAR(glDeleteProgram); +GL_COMPAT_VAR(glShaderSource); +GL_COMPAT_VAR(glCompileShader); +GL_COMPAT_VAR(glGetShaderiv); +GL_COMPAT_VAR(glGetShaderInfoLog); +#endif diff --git a/SDL/opengl_compat.h b/SDL/opengl_compat.h new file mode 100644 index 0000000..9fd1ca9 --- /dev/null +++ b/SDL/opengl_compat.h @@ -0,0 +1,45 @@ +#ifndef opengl_compat_h +#define opengl_compat_h + +#define GL_GLEXT_PROTOTYPES +#include +#include + +#ifndef __APPLE__ +#define GL_COMPAT_NAME(func) gl_compat_##func + +#define GL_COMPAT_WRAPPER(func) \ +({ extern typeof(func) *GL_COMPAT_NAME(func); \ +if(!GL_COMPAT_NAME(func)) GL_COMPAT_NAME(func) = SDL_GL_GetProcAddress(#func); \ + GL_COMPAT_NAME(func); \ +}) + +#define glCreateShader GL_COMPAT_WRAPPER(glCreateShader) +#define glGetAttribLocation GL_COMPAT_WRAPPER(glGetAttribLocation) +#define glGetUniformLocation GL_COMPAT_WRAPPER(glGetUniformLocation) +#define glUseProgram GL_COMPAT_WRAPPER(glUseProgram) +#define glGenVertexArrays GL_COMPAT_WRAPPER(glGenVertexArrays) +#define glBindVertexArray GL_COMPAT_WRAPPER(glBindVertexArray) +#define glGenBuffers GL_COMPAT_WRAPPER(glGenBuffers) +#define glBindBuffer GL_COMPAT_WRAPPER(glBindBuffer) +#define glBufferData GL_COMPAT_WRAPPER(glBufferData) +#define glEnableVertexAttribArray GL_COMPAT_WRAPPER(glEnableVertexAttribArray) +#define glVertexAttribPointer GL_COMPAT_WRAPPER(glVertexAttribPointer) +#define glCreateProgram GL_COMPAT_WRAPPER(glCreateProgram) +#define glAttachShader GL_COMPAT_WRAPPER(glAttachShader) +#define glLinkProgram GL_COMPAT_WRAPPER(glLinkProgram) +#define glGetProgramiv GL_COMPAT_WRAPPER(glGetProgramiv) +#define glGetProgramInfoLog GL_COMPAT_WRAPPER(glGetProgramInfoLog) +#define glDeleteShader GL_COMPAT_WRAPPER(glDeleteShader) +#define glUniform2f GL_COMPAT_WRAPPER(glUniform2f) +#define glActiveTexture GL_COMPAT_WRAPPER(glActiveTexture) +#define glUniform1i GL_COMPAT_WRAPPER(glUniform1i) +#define glBindFragDataLocation GL_COMPAT_WRAPPER(glBindFragDataLocation) +#define glDeleteProgram GL_COMPAT_WRAPPER(glDeleteProgram) +#define glShaderSource GL_COMPAT_WRAPPER(glShaderSource) +#define glCompileShader GL_COMPAT_WRAPPER(glCompileShader) +#define glGetShaderiv GL_COMPAT_WRAPPER(glGetShaderiv) +#define glGetShaderInfoLog GL_COMPAT_WRAPPER(glGetShaderInfoLog) +#endif + +#endif /* opengl_compat_h */ diff --git a/SDL/shader.c b/SDL/shader.c index 013eeab..7aebc88 100644 --- a/SDL/shader.c +++ b/SDL/shader.c @@ -75,7 +75,7 @@ bool init_shader_with_name(shader_t *shader, const char *name) static char master_shader_code[0x801] = {0,}; static char shader_code[0x10001] = {0,}; static char final_shader_code[0x10801] = {0,}; - static ssize_t filter_token_location = 0; + static signed long filter_token_location = 0; if (!master_shader_code[0]) { FILE *master_shader_f = fopen(executable_relative_path("Shaders/MasterShader.fsh"), "r"); diff --git a/SDL/shader.h b/SDL/shader.h index baad223..20baf76 100644 --- a/SDL/shader.h +++ b/SDL/shader.h @@ -1,7 +1,6 @@ #ifndef shader_h #define shader_h -#define GL_GLEXT_PROTOTYPES -#include +#include "opengl_compat.h" #include typedef struct shader_s { diff --git a/Windows/inttypes.h b/Windows/inttypes.h new file mode 100755 index 0000000..9a6118b --- /dev/null +++ b/Windows/inttypes.h @@ -0,0 +1 @@ +#include