libgoatvr

changeset 9:d12592558809

build on macosx
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 20 Sep 2014 16:52:42 +0300
parents 3d9ec6fe97d7
children 61feb3661397
files Makefile.in example/Makefile src/mesh.c src/opengl.c src/vr_libovr.c
diffstat 5 files changed, 51 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/Makefile.in	Sat Sep 20 13:22:53 2014 +0300
     1.2 +++ b/Makefile.in	Sat Sep 20 16:52:42 2014 +0300
     1.3 @@ -15,25 +15,31 @@
     1.4  endif
     1.5  
     1.6  CFLAGS = -pedantic -Wall $(dbg) $(opt) $(pic) $(mod_cflags)
     1.7 -LDFLAGS = $(mod_libs)
     1.8 +LDFLAGS = $(mod_libs) $(libgl)
     1.9  
    1.10  lib_a = lib$(name).a
    1.11  ifeq ($(shell uname -s), Darwin)
    1.12  	lib_so = lib$(name).dylib
    1.13  	shared = -dynamiclib
    1.14 +	libgl = -framework OpenGL
    1.15 +
    1.16 +	ifdef use_libovr
    1.17 +		mod_libs += -framework Cocoa -framework IOKit
    1.18 +	endif
    1.19  else
    1.20  	ldname = lib$(name).so
    1.21  	soname = lib$(name).so.$(so_major)
    1.22  	lib_so = lib$(name).so.$(so_major).$(so_minor)
    1.23  	shared = -shared -Wl,-soname=$(soname)
    1.24  	pic = -fPIC
    1.25 +	libgl = -lGL -lGLU
    1.26  endif
    1.27  
    1.28  .PHONY: all
    1.29  all: $(lib_so) $(lib_a) $(soname) $(ldname)
    1.30  
    1.31  $(lib_so): $(obj)
    1.32 -	$(CC) -o $@ $(shared) $(obj) $(LDFLAGS)
    1.33 +	$(CXX) -o $@ $(shared) $(obj) $(LDFLAGS)
    1.34  
    1.35  $(soname): $(lib_so)
    1.36  	ln -sf $< $@
     2.1 --- a/example/Makefile	Sat Sep 20 13:22:53 2014 +0300
     2.2 +++ b/example/Makefile	Sat Sep 20 16:52:42 2014 +0300
     2.3 @@ -5,11 +5,14 @@
     2.4  vrlib_root = ..
     2.5  vrlib = $(vrlib_root)/libgoatvr.so
     2.6  
     2.7 -CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl2` -I$(vrlib_root)/src
     2.8 -LDFLAGS = $(libgl) `pkg-config --libs sdl2` -L$(vrlib_root) -lgoatvr -Wl,-rpath=$(vrlib_root)
     2.9 +warn = -Wall
    2.10 +
    2.11 +CFLAGS = -pedantic $(warn) -g `pkg-config --cflags sdl2` -I$(vrlib_root)/src
    2.12 +LDFLAGS = $(libgl) `pkg-config --libs sdl2` -L$(vrlib_root) -lgoatvr -Wl,-rpath -Wl,$(vrlib_root)/
    2.13  
    2.14  ifeq ($(shell uname -s), Darwin)
    2.15  	libgl = -framework OpenGL -lGLEW
    2.16 +	warn += -Wno-deprecated-declarations
    2.17  else
    2.18  	libgl = -lGL -lGLU -lGLEW
    2.19  endif
     3.1 --- a/src/mesh.c	Sat Sep 20 13:22:53 2014 +0300
     3.2 +++ b/src/mesh.c	Sat Sep 20 16:52:42 2014 +0300
     3.3 @@ -1,6 +1,7 @@
     3.4  #include <stdio.h>
     3.5  #include <stdlib.h>
     3.6  #include <string.h>
     3.7 +#include <stddef.h>
     3.8  #include "opengl.h"
     3.9  #include "mesh.h"
    3.10  
    3.11 @@ -15,7 +16,7 @@
    3.12  #define GL_STATIC_DRAW			0x88E4
    3.13  #endif
    3.14  
    3.15 -#if !defined(GL_VERSION_1_5) || !defined(GL_GLEXT_PROTOTYPES)
    3.16 +#ifndef GL_VERSION_1_5
    3.17  static void (*glGenBuffers)(GLsizei, GLuint*);
    3.18  static void (*glDeleteBuffers)(GLsizei, GLuint*);
    3.19  static void (*glBufferData)(GLenum, unsigned int, const GLvoid*, GLenum);
    3.20 @@ -31,6 +32,7 @@
    3.21  	m->num_verts = m->num_faces = 0;
    3.22  	m->vbo = m->ibo = 0;
    3.23  
    3.24 +#ifndef GL_VERSION_1_5
    3.25  	if(!glGenBuffers) {
    3.26  		glGenBuffers = vrimp_glfunc("glGenBuffersARB");
    3.27  		glDeleteBuffers = vrimp_glfunc("glDeleteBuffersARB");
    3.28 @@ -42,6 +44,7 @@
    3.29  			return -1;
    3.30  		}
    3.31  	}
    3.32 +#endif
    3.33  
    3.34  	return 0;
    3.35  }
     4.1 --- a/src/opengl.c	Sat Sep 20 13:22:53 2014 +0300
     4.2 +++ b/src/opengl.c	Sat Sep 20 16:52:42 2014 +0300
     4.3 @@ -12,7 +12,7 @@
     4.4  {
     4.5  	return glXGetProcAddress((const unsigned char*)name);
     4.6  }
     4.7 -#endif
     4.8 +#endif	/* __unix__ */
     4.9  
    4.10  #ifdef WIN32
    4.11  void vrimp_swap_buffers(void)
    4.12 @@ -25,4 +25,20 @@
    4.13  {
    4.14  	return wglGetProcAddress(name);
    4.15  }
    4.16 -#endif
    4.17 +#endif	/* WIN32 */
    4.18 +
    4.19 +#ifdef __APPLE__
    4.20 +void vrimp_swap_buffers(void)
    4.21 +{
    4.22 +	/* TODO: I don't think this can even be done without obj-c and a pointer
    4.23 +	 * to a GLView class or whatever the fuck it's called... investigate further
    4.24 +	 */
    4.25 +}
    4.26 +
    4.27 +
    4.28 +void (*vrimp_glfunc(const char *name))()
    4.29 +{
    4.30 +	/* TODO: whatever */
    4.31 +	return 0;
    4.32 +}
    4.33 +#endif	/* __APPLE__ */
     5.1 --- a/src/vr_libovr.c	Sat Sep 20 13:22:53 2014 +0300
     5.2 +++ b/src/vr_libovr.c	Sat Sep 20 16:52:42 2014 +0300
     5.3 @@ -1,12 +1,16 @@
     5.4  #ifdef WIN32
     5.5  #define OVR_OS_WIN32
     5.6  #endif
     5.7 +#ifdef __APPLE__
     5.8 +#define OVR_OS_MAC
     5.9 +#endif
    5.10  
    5.11  #include "vr_impl.h"
    5.12  
    5.13  #ifdef USE_LIBOVR
    5.14  #include <stdio.h>
    5.15  #include <stdlib.h>
    5.16 +#include <string.h>
    5.17  #include <assert.h>
    5.18  #include "opt.h"
    5.19  
    5.20 @@ -30,6 +34,7 @@
    5.21  static int init(void)
    5.22  {
    5.23  	int i, num_hmds;
    5.24 +	int use_fake = 0;
    5.25  
    5.26  	if(!ovr_Initialize()) {
    5.27  		return -1;
    5.28 @@ -37,15 +42,20 @@
    5.29  	printf("initialized LibOVR %s\n", ovr_GetVersionString());
    5.30  
    5.31  	if(!(num_hmds = ovrHmd_Detect())) {
    5.32 -		ovr_Shutdown();
    5.33 -		return -1;
    5.34 +		if(getenv("VR_LIBOVR_FAKE")) {
    5.35 +			use_fake = 1;
    5.36 +			num_hmds = 1;
    5.37 +		} else {
    5.38 +			ovr_Shutdown();
    5.39 +			return -1;
    5.40 +		}
    5.41  	}
    5.42  	printf("%d Oculus HMD(s) found\n", num_hmds);
    5.43  
    5.44  	hmd = 0;
    5.45  	for(i=0; i<num_hmds; i++) {
    5.46 -		ovrHmd h;
    5.47 -		if(!(h = ovrHmd_Create(i))) {
    5.48 +		ovrHmd h = use_fake ? ovrHmd_CreateDebug(ovrHmd_DK2) : ovrHmd_Create(i);
    5.49 +		if(!h) {
    5.50  			break;
    5.51  		}
    5.52  		printf(" [%d]: %s - %s\n", i, h->Manufacturer, h->ProductName);
    5.53 @@ -166,15 +176,13 @@
    5.54  {
    5.55  	if(!hmd) {
    5.56  		vec[0] = vec[1] = vec[2] = 0;
    5.57 -		return 0;
    5.58 +		return;
    5.59  	}
    5.60  
    5.61  	pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
    5.62  	vec[0] = pose[eye].Position.x + eye_render_desc[eye].ViewAdjust.x;
    5.63  	vec[1] = pose[eye].Position.y + eye_render_desc[eye].ViewAdjust.y;
    5.64  	vec[2] = pose[eye].Position.z + eye_render_desc[eye].ViewAdjust.z;
    5.65 -
    5.66 -	return 1;
    5.67  }
    5.68  
    5.69  static void rotation(int eye, float *quat)
    5.70 @@ -182,7 +190,7 @@
    5.71  	if(!hmd) {
    5.72  		quat[0] = quat[1] = quat[2] = 0.0f;
    5.73  		quat[3] = 1.0f;
    5.74 -		return 0;
    5.75 +		return;
    5.76  	}
    5.77  
    5.78  	pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right);
    5.79 @@ -190,7 +198,6 @@
    5.80  	quat[1] = pose[eye].Orientation.y;
    5.81  	quat[2] = pose[eye].Orientation.z;
    5.82  	quat[3] = pose[eye].Orientation.w;
    5.83 -	return 1;
    5.84  }
    5.85  
    5.86  static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};