Better Windows and Linux compatibility
This commit is contained in:
parent
3d8e22ed50
commit
600f0eadd9
1
Makefile
1
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
|
||||
|
34
SDL/opengl_compat.c
Normal file
34
SDL/opengl_compat.c
Normal file
@ -0,0 +1,34 @@
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
|
||||
#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
|
45
SDL/opengl_compat.h
Normal file
45
SDL/opengl_compat.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef opengl_compat_h
|
||||
#define opengl_compat_h
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
#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 */
|
@ -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");
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef shader_h
|
||||
#define shader_h
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include "opengl_compat.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct shader_s {
|
||||
|
1
Windows/inttypes.h
Executable file
1
Windows/inttypes.h
Executable file
@ -0,0 +1 @@
|
||||
#include <stdint.h>
|
Loading…
Reference in New Issue
Block a user