# HG changeset patch # User John Tsiombikas # Date 1408784609 -10800 # Node ID 778ed91cb7fdb02c29f686ada1958ff7ef239ba5 # Parent 5dc4e2b8f6f583bf7a37e6ec17c839f80e806a54 fullscreen to rift now works in extended mode with freeglut diff -r 5dc4e2b8f6f5 -r 778ed91cb7fd src/game.cc --- a/src/game.cc Sat Aug 23 00:24:20 2014 +0300 +++ b/src/game.cc Sat Aug 23 12:03:29 2014 +0300 @@ -22,11 +22,13 @@ bool game_init() { vr_init(); + //vr_use_module_named("null"); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); + glEnable(GL_NORMALIZE); glClearColor(0.1, 0.1, 0.1, 1); @@ -239,14 +241,33 @@ glLoadIdentity(); glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glTranslatef(0, 0.75, 0); - glFrontFace(GL_CW); - glutSolidTeapot(1.0); - glFrontFace(GL_CCW); + for(int i=0; i<4; i++) { + glPushMatrix(); + glTranslatef(i & 1 ? -10 : 10, 0, i & 2 ? -10 : 10); + glScalef(2.0, 2.0, 2.0); - glPopMatrix(); + glBegin(GL_TRIANGLES); + glNormal3f(0, 1, 1); + glVertex3f(-1, 0, 1); + glVertex3f(1, 0, 1); + glVertex3f(0, 1.2, 0); + glNormal3f(1, 1, 0); + glVertex3f(1, 0, 1); + glVertex3f(1, 0, -1); + glVertex3f(0, 1.2, 0); + glNormal3f(0, 1, -1); + glVertex3f(1, 0, -1); + glVertex3f(-1, 0, -1); + glVertex3f(0, 1.2, 0); + glNormal3f(-1, 1, 0); + glVertex3f(-1, 0, -1); + glVertex3f(-1, 0, 1); + glVertex3f(0, 1.2, 0); + glEnd(); + + glPopMatrix(); + } } static bool setup_rtarg(int x, int y) diff -r 5dc4e2b8f6f5 -r 778ed91cb7fd src/main.cc --- a/src/main.cc Sat Aug 23 00:24:20 2014 +0300 +++ b/src/main.cc Sat Aug 23 12:03:29 2014 +0300 @@ -17,6 +17,8 @@ static void sball_motion(int x, int y, int z); static void sball_rotate(int x, int y, int z); +static bool fullscreen_pending; + int main(int argc, char **argv) { glutInitWindowSize(1024, 600); @@ -74,6 +76,10 @@ static void idle() { + if(fullscreen_pending) { + glutFullScreen(); + } + glutPostRedisplay(); } @@ -85,6 +91,7 @@ static void keyb(unsigned char key, int x, int y) { static bool fullscr; + static int prev_xpos, prev_ypos; static int prev_xsz, prev_ysz; switch(key) { @@ -93,6 +100,8 @@ if(fullscr) { int xoffs, yoffs; + prev_xpos = glutGet(GLUT_WINDOW_X); + prev_ypos = glutGet(GLUT_WINDOW_Y); prev_xsz = glutGet(GLUT_WINDOW_WIDTH); prev_ysz = glutGet(GLUT_WINDOW_HEIGHT); @@ -100,10 +109,12 @@ yoffs = vr_get_opti(VR_OPT_WIN_YOFFS); if(xoffs || yoffs) { printf("repositioning: %d,%d\n", xoffs, yoffs); - glutPositionWindow(xoffs + 1, yoffs + 1); + glutPositionWindow(xoffs, yoffs); + fullscreen_pending = true; } - glutFullScreen(); } else { + fullscreen_pending = false; + glutPositionWindow(prev_xpos, prev_ypos); glutReshapeWindow(prev_xsz, prev_ysz); } break; diff -r 5dc4e2b8f6f5 -r 778ed91cb7fd src/vr/mathutil.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/vr/mathutil.c Sat Aug 23 12:03:29 2014 +0300 @@ -0,0 +1,78 @@ +#include +#include +#include "mathutil.h" + +#define M(i, j) ((i) * 4 + (j)) + +static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + +void rotation_matrix(const float *quat, float *matrix) +{ + matrix[0] = 1.0 - 2.0 * quat[1] * quat[1] - 2.0 * quat[2] * quat[2]; + matrix[1] = 2.0 * quat[0] * quat[1] + 2.0 * quat[3] * quat[2]; + matrix[2] = 2.0 * quat[2] * quat[0] - 2.0 * quat[3] * quat[1]; + matrix[3] = 0.0f; + + matrix[4] = 2.0 * quat[0] * quat[1] - 2.0 * quat[3] * quat[2]; + matrix[5] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[2]*quat[2]; + matrix[6] = 2.0 * quat[1] * quat[2] + 2.0 * quat[3] * quat[0]; + matrix[7] = 0.0f; + + matrix[8] = 2.0 * quat[2] * quat[0] + 2.0 * quat[3] * quat[1]; + matrix[9] = 2.0 * quat[1] * quat[2] - 2.0 * quat[3] * quat[0]; + matrix[10] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[1]*quat[1]; + matrix[11] = 0.0f; + + matrix[12] = matrix[13] = matrix[14] = 0.0f; + matrix[15] = 1.0f; + + transpose_matrix(matrix); +} + +void translation_matrix(const float *vec, float *matrix) +{ + memcpy(matrix, idmat, sizeof idmat); + matrix[12] = vec[0]; + matrix[13] = vec[1]; + matrix[14] = vec[2]; +} + +void mult_matrix(float *dest, const float *m1, const float *m2) +{ + int i, j; + float tmp[16]; + + for(i=0; i<4; i++) { + for(j=0; j<4; j++) { + tmp[M(i, j)] = m1[M(i, 0)] * m2[M(0, j)] + m1[M(i, 1)] * m2[M(1, j)] + + m1[M(i, 2)] * m2[M(2, j)] + m1[M(i, 3)] * m2[M(3, j)]; + } + } + memcpy(dest, tmp, sizeof tmp); +} + +void transpose_matrix(float *matrix) +{ + int i, j; + float tmp[16]; + + for(i=0; i<4; i++) { + for(j=0; j<4; j++) { + tmp[M(i, j)] = matrix[M(j, i)]; + } + } + memcpy(matrix, tmp, sizeof tmp); +} + +void print_matrix(const float *matrix) +{ + int i, j; + + for(i=0; i<4; i++) { + putchar('['); + for(j=0; j<4; j++) { + printf("%6.3f ", matrix[M(i, j)]); + } + printf("]\n"); + } +} \ No newline at end of file diff -r 5dc4e2b8f6f5 -r 778ed91cb7fd src/vr/mathutil.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/vr/mathutil.h Sat Aug 23 12:03:29 2014 +0300 @@ -0,0 +1,13 @@ +#ifndef MATHUTIL_H_ +#define MATHUTIL_H_ + +void rotation_matrix(const float *quat, float *matrix); +void translation_matrix(const float *vec, float *matrix); + +void mult_matrix(float *dest, const float *m1, const float *m2); + +void transpose_matrix(float *matrix); + +void print_matrix(const float *matrix); + +#endif /* MATHUTIL_H_ */ \ No newline at end of file diff -r 5dc4e2b8f6f5 -r 778ed91cb7fd vrchess.vcxproj --- a/vrchess.vcxproj Sat Aug 23 00:24:20 2014 +0300 +++ b/vrchess.vcxproj Sat Aug 23 12:03:29 2014 +0300 @@ -58,7 +58,7 @@ Console true - opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovrd.lib;ws2_32.lib;%(AdditionalDependencies) + opengl32.lib;freeglutd.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovrd.lib;ws2_32.lib;%(AdditionalDependencies) @@ -78,7 +78,7 @@ true true true - opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovr.lib;ws2_32.lib;%(AdditionalDependencies) + opengl32.lib;freeglut.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovr.lib;ws2_32.lib;%(AdditionalDependencies)