# HG changeset patch # User John Tsiombikas # Date 1414472251 -7200 # Node ID 4c08bc24ef0ac67c24b7f5adc4864da79c1d0a88 # Parent 92acd335620ea50197c34729cea5d8293a512267# Parent 256d8fcf02f1d2ae796e45bb13e433c7ba330148 merged diff -r 92acd335620e -r 4c08bc24ef0a Makefile --- a/Makefile Tue Oct 28 06:57:06 2014 +0200 +++ b/Makefile Tue Oct 28 06:57:31 2014 +0200 @@ -3,7 +3,7 @@ bin = oculus2 CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl2` -LDFLAGS = $(libgl) `pkg-config --libs sdl2` +LDFLAGS = $(libgl) `pkg-config --libs sdl2` -lovr -lX11 ifeq ($(shell uname -s), Darwin) libgl = -framework OpenGL -lGLEW diff -r 92acd335620e -r 4c08bc24ef0a src/main.c --- a/src/main.c Tue Oct 28 06:57:06 2014 +0200 +++ b/src/main.c Tue Oct 28 06:57:31 2014 +0200 @@ -11,12 +11,15 @@ #include #include #include +#include +#include #ifdef WIN32 #define OVR_OS_WIN32 -#endif -#ifdef __APPLE__ +#elif defined(__APPLE__) #define OVR_OS_MAC +#else +#define OVR_OS_LINUX #endif #include @@ -116,8 +119,8 @@ win_width = hmd->Resolution.w; win_height = hmd->Resolution.h; - /* enable position and rotation tracking (and anything else they might add in the future) */ - ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0); + /* enable position and rotation tracking */ + ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0); /* retrieve the optimal render target resolution for each eye */ eyeres[0] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, hmd->DefaultEyeFov[0], 1.0); eyeres[1] = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, hmd->DefaultEyeFov[1], 1.0); @@ -148,6 +151,14 @@ glcfg.OGL.Header.RTSize = hmd->Resolution; glcfg.OGL.Header.Multisample = 1; +#ifdef WIN32 + glcfg.OGL.Window = GetActiveWindow(); + glcfg.OGL.DC = wglGetCurrentDC(); +#else + glcfg.OGL.Disp = glXGetCurrentDisplay(); + glcfg.OGL.Win = glXGetCurrentDrawable(); +#endif + if(hmd->HmdCaps & ovrHmdCap_ExtendDesktop) { printf("running in \"extended desktop\" mode\n"); } else { @@ -156,10 +167,9 @@ * XXX: this doesn't work properly yet due to bugs in the oculus 0.4.1 sdk/driver */ #ifdef WIN32 - HWND sys_win = GetActiveWindow(); - glcfg.OGL.Window = sys_win; - glcfg.OGL.DC = wglGetCurrentDC(); - ovrHmd_AttachToWindow(hmd, sys_win, 0, 0); + ovrHmd_AttachToWindow(hmd, glcfg.OGL.Window, 0, 0); +#else + ovrHmd_AttachToWindow(hmd, (void*)glcfg.OGL.Win, 0, 0); #endif printf("running in \"direct-hmd\" mode\n"); } @@ -260,10 +270,13 @@ * we need to construct a view matrix by combining all the information provided by the oculus * SDK, about the position and orientation of the user's head in the world. */ - pose[eye] = ovrHmd_GetEyePose(hmd, eye); + /* TODO: use ovrHmd_GetEyePoses out of the loop instead */ + pose[eye] = ovrHmd_GetHmdPosePerEye(hmd, eye); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(eye_rdesc[eye].ViewAdjust.x, eye_rdesc[eye].ViewAdjust.y, eye_rdesc[eye].ViewAdjust.z); + glTranslatef(eye_rdesc[eye].HmdToEyeViewOffset.x, + eye_rdesc[eye].HmdToEyeViewOffset.y, + eye_rdesc[eye].HmdToEyeViewOffset.z); /* retrieve the orientation quaternion and convert it to a rotation matrix */ quat_to_matrix(&pose[eye].Orientation.x, rot_mat); glMultMatrixf(rot_mat); @@ -552,4 +565,4 @@ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, img); return tex; -} \ No newline at end of file +}