commit 92124a715e0401bb24eedd4cc6f307784393a3e9
parent 8e1c8a84373ae3e1caa080ebdac490df4b545e48
Author: Brian Swetland <swetland@frotz.net>
Date: Mon, 28 Jan 2013 23:57:43 -0800
support building on windows
- handle dynamic lookup of post 1.x gl methods
- handle missing unistd.h and M_PI
Diffstat:
5 files changed, 95 insertions(+), 3 deletions(-)
diff --git a/DebugText.cc b/DebugText.cc
@@ -16,8 +16,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <unistd.h>
#include <string.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include "util.h"
#include "glue.h"
diff --git a/glue.h b/glue.h
@@ -16,7 +16,9 @@
#ifndef _SDL_GLUE_H_
#define _SDL_GLUE_H_
+#ifndef _WIN32
#define GL_GLEXT_PROTOTYPES 1
+#endif
#include <SDL_opengl.h>
@@ -32,4 +34,50 @@ int scene_draw(struct ctxt *c);
int shader_compile(const char *vshader, const char *fshader,
GLuint *pgm, GLuint *vshd, GLuint *fshd);
+#ifdef _WIN32
+#ifndef GLUE_DEFINE_EXTENSIONS
+#define GLXTN extern
+#else
+#define GLXTN
+#endif
+
+GLXTN PFNGLACTIVETEXTUREPROC glActiveTexture;
+GLXTN PFNGLATTACHSHADERPROC glAttachShader;
+GLXTN PFNGLBINDBUFFERPROC glBindBuffer;
+GLXTN PFNGLBUFFERDATAPROC glBufferData;
+GLXTN PFNGLCOMPILESHADERPROC glCompileShader;
+GLXTN PFNGLCREATEPROGRAMPROC glCreateProgram;
+GLXTN PFNGLCREATESHADERPROC glCreateShader;
+GLXTN PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
+GLXTN PFNGLGENBUFFERSPROC glGenBuffers;
+GLXTN PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation;
+GLXTN PFNGLGETPROGRAMIVPROC glGetProgramiv;
+GLXTN PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
+GLXTN PFNGLGETSHADERIVPROC glGetShaderiv;
+GLXTN PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
+GLXTN PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
+GLXTN PFNGLLINKPROGRAMPROC glLinkProgram;
+GLXTN PFNGLSHADERSOURCEPROC glShaderSource;
+GLXTN PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
+GLXTN PFNGLUNIFORM1IPROC glUniform1i;
+GLXTN PFNGLUNIFORM4FVPROC glUniform4fv;
+GLXTN PFNGLUSEPROGRAMPROC glUseProgram;
+GLXTN PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
+
+#ifdef GLUE_DEFINE_EXTENSIONS
+#define EFUNC(n) { (void**) &n, #n }
+struct {
+ void **func;
+ const char *name;
+} fntb[] = {
+ EFUNC(glActiveTexture), EFUNC(glAttachShader), EFUNC(glBindBuffer), EFUNC(glBufferData),
+ EFUNC(glCompileShader), EFUNC(glCreateProgram), EFUNC(glCreateShader),
+ EFUNC(glEnableVertexAttribArray), EFUNC(glGenBuffers), EFUNC(glGetAttribLocation), EFUNC(glGetProgramiv),
+ EFUNC(glGetProgramInfoLog), EFUNC(glGetShaderiv), EFUNC(glGetShaderInfoLog),
+ EFUNC(glGetUniformLocation), EFUNC(glLinkProgram), EFUNC(glShaderSource),
+ EFUNC(glUniformMatrix4fv), EFUNC(glUseProgram), EFUNC(glUniform1i), EFUNC(glUniform4fv), EFUNC(glVertexAttribPointer),
+};
+#endif
+
+#endif
#endif
diff --git a/matrix.h b/matrix.h
@@ -20,6 +20,10 @@
#define D2R(d) (((d) * M_PI) / 180.0)
+#ifdef _WIN32
+#define M_PI 3.14159265358979323846
+#endif
+
/* low level operations */
void __mat4_mul_mat4(float m[16], const float a[16], const float b[16]);
void __mat4_mul_vec4(float o[4], const float m[16], const float v[4]);
diff --git a/sdlglue.cc b/sdlglue.cc
@@ -17,11 +17,18 @@
#include <stdio.h>
#include <stdlib.h>
+#ifndef _WIN32
#include <unistd.h>
+#endif
#include <time.h>
#include "util.h"
+
+#ifdef _WIN32
+#define GLUE_DEFINE_EXTENSIONS
+#endif
+
#include "glue.h"
void die(const char *fmt, ...) {
@@ -29,6 +36,33 @@ void die(const char *fmt, ...) {
exit(-1);
}
+#ifdef _WIN32
+#if !WITH_SDL2
+int SDL_GL_ExtensionSupported(const char *name) {
+ if (strstr((char*)glGetString(GL_EXTENSIONS), name))
+ return 1;
+ else
+ return 0;
+}
+#endif
+
+void glsl_init(void) {
+ int n;
+ if (!SDL_GL_ExtensionSupported("GL_ARB_shader_objects") ||
+ !SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") ||
+ !SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") ||
+ !SDL_GL_ExtensionSupported("GL_ARB_fragment_shader"))
+ die("missing glsl extensions");
+ for (n = 0; n < sizeof(fntb)/sizeof(fntb[0]); n++) {
+ *fntb[n].func = SDL_GL_GetProcAddress(fntb[n].name);
+ if (!(*fntb[n].func))
+ die("cannot find func '%s'", fntb[n].name);
+ }
+}
+#else
+void glsl_init(void) {}
+#endif
+
int check_compile_error(GLuint obj, const char *fn) {
GLint r, len;
char *buf;
@@ -175,6 +209,8 @@ int main(int argc, char **argv) {
die("sdl cannot set mode");
#endif
+ glsl_init();
+
if (scene_init(&c))
return -1;
diff --git a/test5.cc b/test5.cc
@@ -15,8 +15,10 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include "util.h"
#include "matrix.h"
@@ -37,7 +39,7 @@ float camx = 0, camy = 0, camz = -5;
float camrx = 0, camry = 0, camrz = 0;
extern unsigned char keystate[];
-#include <SDL/SDL_keysym.h>
+#include <SDL_keysym.h>
mat4 Projection;