vrchess

changeset 12:778ed91cb7fd tip

fullscreen to rift now works in extended mode with freeglut
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 23 Aug 2014 12:03:29 +0300
parents 5dc4e2b8f6f5
children
files src/game.cc src/main.cc src/vr/mathutil.c src/vr/mathutil.h vrchess.vcxproj
diffstat 5 files changed, 133 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/src/game.cc	Sat Aug 23 00:24:20 2014 +0300
     1.2 +++ b/src/game.cc	Sat Aug 23 12:03:29 2014 +0300
     1.3 @@ -22,11 +22,13 @@
     1.4  bool game_init()
     1.5  {
     1.6  	vr_init();
     1.7 +	//vr_use_module_named("null");
     1.8  
     1.9  	glEnable(GL_DEPTH_TEST);
    1.10  	glEnable(GL_CULL_FACE);
    1.11  	glEnable(GL_LIGHTING);
    1.12  	glEnable(GL_LIGHT0);
    1.13 +	glEnable(GL_NORMALIZE);
    1.14  
    1.15  	glClearColor(0.1, 0.1, 0.1, 1);
    1.16  
    1.17 @@ -239,14 +241,33 @@
    1.18  	glLoadIdentity();
    1.19  
    1.20  	glMatrixMode(GL_MODELVIEW);
    1.21 -	glPushMatrix();
    1.22 -	glTranslatef(0, 0.75, 0);
    1.23  
    1.24 -	glFrontFace(GL_CW);
    1.25 -	glutSolidTeapot(1.0);
    1.26 -	glFrontFace(GL_CCW);
    1.27 +	for(int i=0; i<4; i++) {
    1.28 +		glPushMatrix();
    1.29 +		glTranslatef(i & 1 ? -10 : 10, 0, i & 2 ? -10 : 10);
    1.30 +		glScalef(2.0, 2.0, 2.0);
    1.31  
    1.32 -	glPopMatrix();
    1.33 +		glBegin(GL_TRIANGLES);
    1.34 +		glNormal3f(0, 1, 1);
    1.35 +		glVertex3f(-1, 0, 1);
    1.36 +		glVertex3f(1, 0, 1);
    1.37 +		glVertex3f(0, 1.2, 0);
    1.38 +		glNormal3f(1, 1, 0);
    1.39 +		glVertex3f(1, 0, 1);
    1.40 +		glVertex3f(1, 0, -1);
    1.41 +		glVertex3f(0, 1.2, 0);
    1.42 +		glNormal3f(0, 1, -1);
    1.43 +		glVertex3f(1, 0, -1);
    1.44 +		glVertex3f(-1, 0, -1);
    1.45 +		glVertex3f(0, 1.2, 0);
    1.46 +		glNormal3f(-1, 1, 0);
    1.47 +		glVertex3f(-1, 0, -1);
    1.48 +		glVertex3f(-1, 0, 1);
    1.49 +		glVertex3f(0, 1.2, 0);
    1.50 +		glEnd();
    1.51 +
    1.52 +		glPopMatrix();
    1.53 +	}
    1.54  }
    1.55  
    1.56  static bool setup_rtarg(int x, int y)
     2.1 --- a/src/main.cc	Sat Aug 23 00:24:20 2014 +0300
     2.2 +++ b/src/main.cc	Sat Aug 23 12:03:29 2014 +0300
     2.3 @@ -17,6 +17,8 @@
     2.4  static void sball_motion(int x, int y, int z);
     2.5  static void sball_rotate(int x, int y, int z);
     2.6  
     2.7 +static bool fullscreen_pending;
     2.8 +
     2.9  int main(int argc, char **argv)
    2.10  {
    2.11  	glutInitWindowSize(1024, 600);
    2.12 @@ -74,6 +76,10 @@
    2.13  
    2.14  static void idle()
    2.15  {
    2.16 +	if(fullscreen_pending) {
    2.17 +		glutFullScreen();
    2.18 +	}
    2.19 +
    2.20  	glutPostRedisplay();
    2.21  }
    2.22  
    2.23 @@ -85,6 +91,7 @@
    2.24  static void keyb(unsigned char key, int x, int y)
    2.25  {
    2.26  	static bool fullscr;
    2.27 +	static int prev_xpos, prev_ypos;
    2.28  	static int prev_xsz, prev_ysz;
    2.29  
    2.30  	switch(key) {
    2.31 @@ -93,6 +100,8 @@
    2.32  		if(fullscr) {
    2.33  			int xoffs, yoffs;
    2.34  
    2.35 +			prev_xpos = glutGet(GLUT_WINDOW_X);
    2.36 +			prev_ypos = glutGet(GLUT_WINDOW_Y);
    2.37  			prev_xsz = glutGet(GLUT_WINDOW_WIDTH);
    2.38  			prev_ysz = glutGet(GLUT_WINDOW_HEIGHT);
    2.39  
    2.40 @@ -100,10 +109,12 @@
    2.41  			yoffs = vr_get_opti(VR_OPT_WIN_YOFFS);
    2.42  			if(xoffs || yoffs) {
    2.43  				printf("repositioning: %d,%d\n", xoffs, yoffs);
    2.44 -				glutPositionWindow(xoffs + 1, yoffs + 1);
    2.45 +				glutPositionWindow(xoffs, yoffs);
    2.46 +				fullscreen_pending = true;
    2.47  			}
    2.48 -			glutFullScreen();
    2.49  		} else {
    2.50 +			fullscreen_pending = false;
    2.51 +			glutPositionWindow(prev_xpos, prev_ypos);
    2.52  			glutReshapeWindow(prev_xsz, prev_ysz);
    2.53  		}
    2.54  		break;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/vr/mathutil.c	Sat Aug 23 12:03:29 2014 +0300
     3.3 @@ -0,0 +1,78 @@
     3.4 +#include <stdio.h>
     3.5 +#include <string.h>
     3.6 +#include "mathutil.h"
     3.7 +
     3.8 +#define M(i, j)	((i) * 4 + (j))
     3.9 +
    3.10 +static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
    3.11 +
    3.12 +void rotation_matrix(const float *quat, float *matrix)
    3.13 +{
    3.14 +	matrix[0] = 1.0 - 2.0 * quat[1] * quat[1] - 2.0 * quat[2] * quat[2];
    3.15 +	matrix[1] = 2.0 * quat[0] * quat[1] + 2.0 * quat[3] * quat[2];
    3.16 +	matrix[2] = 2.0 * quat[2] * quat[0] - 2.0 * quat[3] * quat[1];
    3.17 +	matrix[3] = 0.0f;
    3.18 +
    3.19 +	matrix[4] = 2.0 * quat[0] * quat[1] - 2.0 * quat[3] * quat[2];
    3.20 +	matrix[5] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[2]*quat[2];
    3.21 +	matrix[6] = 2.0 * quat[1] * quat[2] + 2.0 * quat[3] * quat[0];
    3.22 +	matrix[7] = 0.0f;
    3.23 +
    3.24 +	matrix[8] = 2.0 * quat[2] * quat[0] + 2.0 * quat[3] * quat[1];
    3.25 +	matrix[9] = 2.0 * quat[1] * quat[2] - 2.0 * quat[3] * quat[0];
    3.26 +	matrix[10] = 1.0 - 2.0 * quat[0]*quat[0] - 2.0 * quat[1]*quat[1];
    3.27 +	matrix[11] = 0.0f;
    3.28 +
    3.29 +	matrix[12] = matrix[13] = matrix[14] = 0.0f;
    3.30 +	matrix[15] = 1.0f;
    3.31 +
    3.32 +	transpose_matrix(matrix);
    3.33 +}
    3.34 +
    3.35 +void translation_matrix(const float *vec, float *matrix)
    3.36 +{
    3.37 +	memcpy(matrix, idmat, sizeof idmat);
    3.38 +	matrix[12] = vec[0];
    3.39 +	matrix[13] = vec[1];
    3.40 +	matrix[14] = vec[2];
    3.41 +}
    3.42 +
    3.43 +void mult_matrix(float *dest, const float *m1, const float *m2)
    3.44 +{
    3.45 +	int i, j;
    3.46 +	float tmp[16];
    3.47 +
    3.48 +	for(i=0; i<4; i++) {
    3.49 +		for(j=0; j<4; j++) {
    3.50 +			tmp[M(i, j)] = m1[M(i, 0)] * m2[M(0, j)] + m1[M(i, 1)] * m2[M(1, j)] +
    3.51 +				m1[M(i, 2)] * m2[M(2, j)] + m1[M(i, 3)] * m2[M(3, j)];
    3.52 +		}
    3.53 +	}
    3.54 +	memcpy(dest, tmp, sizeof tmp);
    3.55 +}
    3.56 +
    3.57 +void transpose_matrix(float *matrix)
    3.58 +{
    3.59 +	int i, j;
    3.60 +	float tmp[16];
    3.61 +
    3.62 +	for(i=0; i<4; i++) {
    3.63 +		for(j=0; j<4; j++) {
    3.64 +			tmp[M(i, j)] = matrix[M(j, i)];
    3.65 +		}
    3.66 +	}
    3.67 +	memcpy(matrix, tmp, sizeof tmp);
    3.68 +}
    3.69 +
    3.70 +void print_matrix(const float *matrix)
    3.71 +{
    3.72 +	int i, j;
    3.73 +
    3.74 +	for(i=0; i<4; i++) {
    3.75 +		putchar('[');
    3.76 +		for(j=0; j<4; j++) {
    3.77 +			printf("%6.3f ", matrix[M(i, j)]);
    3.78 +		}
    3.79 +		printf("]\n");
    3.80 +	}
    3.81 +}
    3.82 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/vr/mathutil.h	Sat Aug 23 12:03:29 2014 +0300
     4.3 @@ -0,0 +1,13 @@
     4.4 +#ifndef MATHUTIL_H_
     4.5 +#define MATHUTIL_H_
     4.6 +
     4.7 +void rotation_matrix(const float *quat, float *matrix);
     4.8 +void translation_matrix(const float *vec, float *matrix);
     4.9 +
    4.10 +void mult_matrix(float *dest, const float *m1, const float *m2);
    4.11 +
    4.12 +void transpose_matrix(float *matrix);
    4.13 +
    4.14 +void print_matrix(const float *matrix);
    4.15 +
    4.16 +#endif	/* MATHUTIL_H_ */
    4.17 \ No newline at end of file
     5.1 --- a/vrchess.vcxproj	Sat Aug 23 00:24:20 2014 +0300
     5.2 +++ b/vrchess.vcxproj	Sat Aug 23 12:03:29 2014 +0300
     5.3 @@ -58,7 +58,7 @@
     5.4      <Link>
     5.5        <SubSystem>Console</SubSystem>
     5.6        <GenerateDebugInformation>true</GenerateDebugInformation>
     5.7 -      <AdditionalDependencies>opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovrd.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     5.8 +      <AdditionalDependencies>opengl32.lib;freeglutd.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovrd.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     5.9      </Link>
    5.10    </ItemDefinitionGroup>
    5.11    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    5.12 @@ -78,7 +78,7 @@
    5.13        <GenerateDebugInformation>true</GenerateDebugInformation>
    5.14        <EnableCOMDATFolding>true</EnableCOMDATFolding>
    5.15        <OptimizeReferences>true</OptimizeReferences>
    5.16 -      <AdditionalDependencies>opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovr.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.17 +      <AdditionalDependencies>opengl32.lib;freeglut.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;libovr.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    5.18      </Link>
    5.19    </ItemDefinitionGroup>
    5.20    <ItemGroup>