vrheights
diff src/game.cc @ 5:053a52f0cb64
console
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 26 Sep 2014 18:40:15 +0300 |
parents | 690ef7fa791f |
children | 608e03b688f8 |
line diff
1.1 --- a/src/game.cc Fri Sep 26 13:19:22 2014 +0300 1.2 +++ b/src/game.cc Fri Sep 26 18:40:15 2014 +0300 1.3 @@ -6,6 +6,8 @@ 1.4 #include "game.h" 1.5 #include "goatvr.h" 1.6 #include "teapot.h" 1.7 +#include "console.h" 1.8 +#include "drawtext.h" 1.9 1.10 static void draw_scene(); 1.11 static void material(float r, float g, float b, float roughness); 1.12 @@ -13,16 +15,23 @@ 1.13 static void create_rtarg(int x, int y); 1.14 static int next_pow2(int x); 1.15 1.16 +bool opt_separate_walk_look; 1.17 + 1.18 static int win_width, win_height; 1.19 static unsigned int fb_tex; 1.20 static unsigned int fbo, fb_depth; 1.21 static int fb_xsz, fb_ysz; 1.22 static int fb_tex_xsz, fb_tex_ysz; 1.23 1.24 +static unsigned int chess_tex; 1.25 + 1.26 static float cam_theta, cam_phi; 1.27 static Vector3 cam_pos; 1.28 static bool keystate[256]; 1.29 1.30 +static Console con; 1.31 +static dtx_font *con_font; 1.32 + 1.33 bool game_init() 1.34 { 1.35 init_opengl(); 1.36 @@ -35,6 +44,24 @@ 1.37 glEnable(GL_CULL_FACE); 1.38 glEnable(GL_LIGHTING); 1.39 1.40 + unsigned char chess_pixels[] = { 1.41 + 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 1.42 + 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0xff 1.43 + }; 1.44 + glGenTextures(1, &chess_tex); 1.45 + glBindTexture(GL_TEXTURE_2D, chess_tex); 1.46 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1.47 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1.48 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, chess_pixels); 1.49 + 1.50 + if(!(con_font = dtx_open_font_glyphmap("data/mono14.glyphmap"))) { 1.51 + fprintf(stderr, "failed to open console font\n"); 1.52 + return false; 1.53 + } 1.54 + con.set_size(6, 40); 1.55 + con.set_font(con_font, 14); 1.56 + con.set_position(0, 0, Console::CENTER); 1.57 + 1.58 return true; 1.59 } 1.60 1.61 @@ -49,7 +76,12 @@ 1.62 float dt = (tm - prev_upd) / 1000.0; 1.63 prev_upd = tm; 1.64 1.65 - float offs = dt * 1.0; 1.66 + if(con.is_visible()) { 1.67 + con.update(); 1.68 + return; 1.69 + } 1.70 + 1.71 + float offs = dt * 5.0; 1.72 Vector3 dir; 1.73 1.74 if(keystate['d'] || keystate['D']) { 1.75 @@ -65,8 +97,13 @@ 1.76 dir += Vector3(0, 0, offs); 1.77 } 1.78 1.79 - cam_pos.x += dir.x * cos(cam_theta) - dir.y * sin(cam_theta); 1.80 - cam_pos.z += dir.x * sin(cam_theta) + dir.y * cos(cam_theta); 1.81 + float cos_theta = cos(DEG_TO_RAD(cam_theta)); 1.82 + float sin_theta = sin(DEG_TO_RAD(cam_theta)); 1.83 + cam_pos.x += dir.x * cos_theta - dir.z * sin_theta; 1.84 + cam_pos.z += dir.x * sin_theta + dir.z * cos_theta; 1.85 + 1.86 + if(!opt_separate_walk_look) { 1.87 + } 1.88 } 1.89 1.90 void game_display() 1.91 @@ -96,6 +133,7 @@ 1.92 glTranslatef(-cam_pos.x, -cam_pos.y, -cam_pos.z); 1.93 1.94 draw_scene(); 1.95 + con.draw(); 1.96 1.97 vr_end(); 1.98 } 1.99 @@ -112,7 +150,7 @@ 1.100 win_width = x; 1.101 win_height = y; 1.102 1.103 - create_rtarg(vr_geti_def(VR_RENDER_XRES, x), vr_geti_def(VR_RENDER_YRES, y)); 1.104 + create_rtarg(vr_geti_def(VR_RENDER_XRES, x * 2), vr_geti_def(VR_RENDER_YRES, y)); 1.105 vr_output_texture(fb_tex, 0, 0, (float)fb_xsz / (float)fb_tex_xsz, (float)fb_ysz / (float)fb_tex_ysz); 1.106 1.107 /* these might be overriden in VR mode (see game_display) */ 1.108 @@ -125,21 +163,33 @@ 1.109 void game_keyboard(int key, bool pressed) 1.110 { 1.111 if(pressed) { 1.112 - switch(key) { 1.113 - case 27: 1.114 - exit_game(); 1.115 - break; 1.116 + if(con.is_visible()) { 1.117 + if(key == 27 || key == '`') { 1.118 + con.hide(); 1.119 + } else { 1.120 + con.input_key(key); 1.121 + } 1.122 + } else { 1.123 + switch(key) { 1.124 + case 27: 1.125 + exit_game(); 1.126 + break; 1.127 1.128 - case 'f': 1.129 - toggle_hmd_fullscr(); 1.130 - break; 1.131 + case 'f': 1.132 + toggle_hmd_fullscr(); 1.133 + break; 1.134 1.135 - case 'r': 1.136 - vr_recenter(); 1.137 - break; 1.138 + case 'r': 1.139 + vr_recenter(); 1.140 + break; 1.141 1.142 - default: 1.143 - break; 1.144 + case '`': 1.145 + con.show(); 1.146 + break; 1.147 + 1.148 + default: 1.149 + break; 1.150 + } 1.151 } 1.152 } 1.153 1.154 @@ -197,14 +247,17 @@ 1.155 1.156 glMatrixMode(GL_MODELVIEW); 1.157 1.158 + glBindTexture(GL_TEXTURE_2D, chess_tex); 1.159 + glEnable(GL_TEXTURE_2D); 1.160 material(1, 1, 1, 1); 1.161 glBegin(GL_QUADS); 1.162 glNormal3f(0, 1, 0); 1.163 - glVertex3f(-10, 0, 10); 1.164 - glVertex3f(10, 0, 10); 1.165 - glVertex3f(10, 0, -10); 1.166 - glVertex3f(-10, 0, -10); 1.167 + glTexCoord2f(0, 0); glVertex3f(-10, 0, 10); 1.168 + glTexCoord2f(1, 0); glVertex3f(10, 0, 10); 1.169 + glTexCoord2f(1, 1); glVertex3f(10, 0, -10); 1.170 + glTexCoord2f(0, 1); glVertex3f(-10, 0, -10); 1.171 glEnd(); 1.172 + glDisable(GL_TEXTURE_2D); 1.173 1.174 material(1, 1, 1, 0.4); 1.175 glPushMatrix(); 1.176 @@ -272,6 +325,8 @@ 1.177 fb_tex_xsz = next_pow2(fb_xsz); 1.178 fb_tex_ysz = next_pow2(fb_ysz); 1.179 1.180 + printf("creating %dx%d render target (tex size: %dx%d)\n", fb_xsz, fb_ysz, fb_tex_xsz, fb_tex_ysz); 1.181 + 1.182 if(!fbo) { 1.183 glGenFramebuffers(1, &fbo); 1.184