conworlds

diff src/game.cc @ 13:283cdfa7dda2

added a crapload of code from goat3dgfx
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Aug 2014 09:41:24 +0300
parents 778ed91cb7fd
children 9b0db7dbde6e
line diff
     1.1 --- a/src/game.cc	Sat Aug 23 12:03:29 2014 +0300
     1.2 +++ b/src/game.cc	Sun Aug 24 09:41:24 2014 +0300
     1.3 @@ -1,4 +1,5 @@
     1.4  #include "game.h"
     1.5 +#include "gameopt.h"
     1.6  #include "opengl.h"
     1.7  #include "camera.h"
     1.8  #include "texture.h"
     1.9 @@ -18,11 +19,18 @@
    1.10  static FlyCamera cam;
    1.11  static Texture floor_tex;
    1.12  static bool keystate[256];
    1.13 +static float player_height = 1.68;
    1.14  
    1.15  bool game_init()
    1.16  {
    1.17 -	vr_init();
    1.18 -	//vr_use_module_named("null");
    1.19 +	if(opt.vr) {
    1.20 +		vr_init();
    1.21 +		if(opt.vr_module) {
    1.22 +			vr_use_module_named(opt.vr_module);
    1.23 +		}
    1.24 +
    1.25 +		player_height = vr_get_optf(VR_OPT_EYE_HEIGHT);
    1.26 +	}
    1.27  
    1.28  	glEnable(GL_DEPTH_TEST);
    1.29  	glEnable(GL_CULL_FACE);
    1.30 @@ -37,14 +45,16 @@
    1.31  		return false;
    1.32  	}
    1.33  
    1.34 -	cam.input_move(0, 0, 5);
    1.35 +	cam.input_move(0, player_height, 0);
    1.36  	return true;
    1.37  }
    1.38  
    1.39  void game_cleanup()
    1.40  {
    1.41  	floor_tex.destroy();
    1.42 -	vr_shutdown();
    1.43 +	if(opt.vr) {
    1.44 +		vr_shutdown();
    1.45 +	}
    1.46  
    1.47  	if(fbo) {
    1.48  		glDeleteFramebuffers(1, &fbo);
    1.49 @@ -88,24 +98,30 @@
    1.50  
    1.51  void game_render()
    1.52  {
    1.53 -	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    1.54 -	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.55 +	if(opt.vr) {
    1.56 +		glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    1.57 +		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.58  
    1.59 -	glViewport(0, 0, rtwidth / 2.0, rtheight);
    1.60 -	vr_begin(VR_EYE_LEFT);
    1.61 -	game_render_eye(-1);
    1.62 -	vr_end();
    1.63 +		glViewport(0, 0, rtwidth / 2.0, rtheight);
    1.64 +		vr_begin(VR_EYE_LEFT);
    1.65 +		game_render_eye(-1);
    1.66 +		vr_end();
    1.67  
    1.68 -	glViewport(rtwidth / 2, 0, rtwidth / 2.0, rtheight);
    1.69 -	vr_begin(VR_EYE_RIGHT);
    1.70 -	game_render_eye(1);
    1.71 -	vr_end();
    1.72 +		glViewport(rtwidth / 2, 0, rtwidth / 2.0, rtheight);
    1.73 +		vr_begin(VR_EYE_RIGHT);
    1.74 +		game_render_eye(1);
    1.75 +		vr_end();
    1.76  
    1.77 -	glBindFramebuffer(GL_FRAMEBUFFER, 0);
    1.78 -	glViewport(0, 0, fb_width, fb_height);
    1.79 +		glBindFramebuffer(GL_FRAMEBUFFER, 0);
    1.80 +		glViewport(0, 0, fb_width, fb_height);
    1.81  
    1.82 -	vr_output_texture(rtarg->get_texture_id(), 0, 0, (float)rtwidth / (float)rtarg->get_width(),
    1.83 -		(float)rtheight / (float)rtarg->get_height());
    1.84 +		vr_output_texture(rtarg->get_texture_id(), 0, 0, (float)rtwidth / (float)rtarg->get_width(),
    1.85 +			(float)rtheight / (float)rtarg->get_height());
    1.86 +	} else {
    1.87 +		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.88 +
    1.89 +		game_render_eye(0);
    1.90 +	}
    1.91  
    1.92  	vr_swap_buffers();
    1.93  }
    1.94 @@ -218,14 +234,11 @@
    1.95  
    1.96  static void draw_scene()
    1.97  {
    1.98 -	glMatrixMode(GL_MODELVIEW);
    1.99 -	glTranslatef(0, -1.5, 0);
   1.100 -
   1.101  	float lpos[] = {-20, 30, 10, 1};
   1.102  	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
   1.103  
   1.104  	glEnable(GL_TEXTURE_2D);
   1.105 -	floor_tex.bind();
   1.106 +	bind_texture(&floor_tex);
   1.107  
   1.108  	glMatrixMode(GL_TEXTURE);
   1.109  	glScalef(8, 8, 8);
   1.110 @@ -251,19 +264,19 @@
   1.111  		glNormal3f(0, 1, 1);
   1.112  		glVertex3f(-1, 0, 1);
   1.113  		glVertex3f(1, 0, 1);
   1.114 -		glVertex3f(0, 1.2, 0);
   1.115 +		glVertex3f(0, 1.75, 0);
   1.116  		glNormal3f(1, 1, 0);
   1.117  		glVertex3f(1, 0, 1);
   1.118  		glVertex3f(1, 0, -1);
   1.119 -		glVertex3f(0, 1.2, 0);
   1.120 +		glVertex3f(0, 1.75, 0);
   1.121  		glNormal3f(0, 1, -1);
   1.122  		glVertex3f(1, 0, -1);
   1.123  		glVertex3f(-1, 0, -1);
   1.124 -		glVertex3f(0, 1.2, 0);
   1.125 +		glVertex3f(0, 1.75, 0);
   1.126  		glNormal3f(-1, 1, 0);
   1.127  		glVertex3f(-1, 0, -1);
   1.128  		glVertex3f(-1, 0, 1);
   1.129 -		glVertex3f(0, 1.2, 0);
   1.130 +		glVertex3f(0, 1.75, 0);
   1.131  		glEnd();
   1.132  
   1.133  		glPopMatrix();