vrheights
diff src/game.cc @ 3:316ec8250af2
added the teapot code for testing
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 25 Sep 2014 17:13:23 +0300 |
parents | b49461618f61 |
children | 690ef7fa791f |
line diff
1.1 --- a/src/game.cc Thu Sep 25 11:44:45 2014 +0300 1.2 +++ b/src/game.cc Thu Sep 25 17:13:23 2014 +0300 1.3 @@ -4,6 +4,7 @@ 1.4 #include "opengl.h" 1.5 #include "game.h" 1.6 #include "goatvr.h" 1.7 +#include "teapot.h" 1.8 1.9 static void draw_scene(); 1.10 static void toggle_hmd_fullscr(); 1.11 @@ -26,6 +27,7 @@ 1.12 1.13 glEnable(GL_DEPTH_TEST); 1.14 glEnable(GL_CULL_FACE); 1.15 + glEnable(GL_LIGHTING); 1.16 1.17 return true; 1.18 } 1.19 @@ -119,8 +121,53 @@ 1.20 { 1.21 } 1.22 1.23 +static void material(float r, float g, float b, float roughness) 1.24 +{ 1.25 + float gloss = 1.0 - roughness; 1.26 + float diffuse[] = {r * roughness, g * roughness, b * roughness, 1.0}; 1.27 + float specular[] = {gloss, gloss, gloss, 1.0}; 1.28 + float shin = gloss * 128.0; 1.29 + 1.30 + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diffuse); 1.31 + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); 1.32 + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin); 1.33 +} 1.34 + 1.35 static void draw_scene() 1.36 { 1.37 + float lpos[][4] = { 1.38 + {-0.7, 0.7, 1, 0}, 1.39 + {1, 0, 1, 0} 1.40 + }; 1.41 + float lcol[][4] = { 1.42 + {0.9, 0.7, 0.6, 1}, 1.43 + {0.3, 0.4, 0.75, 1} 1.44 + }; 1.45 + for(int i=0; i<2; i++) { 1.46 + glEnable(GL_LIGHT0 + i); 1.47 + glLightfv(GL_LIGHT0 + i, GL_POSITION, lpos[i]); 1.48 + glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lcol[i]); 1.49 + glLightfv(GL_LIGHT0 + i, GL_SPECULAR, lcol[i]); 1.50 + } 1.51 + 1.52 + glMatrixMode(GL_MODELVIEW); 1.53 + 1.54 + material(1, 1, 1, 1); 1.55 + glBegin(GL_QUADS); 1.56 + glNormal3f(0, 1, 0); 1.57 + glVertex3f(-10, 0, 10); 1.58 + glVertex3f(10, 0, 10); 1.59 + glVertex3f(10, 0, -10); 1.60 + glVertex3f(-10, 0, -10); 1.61 + glEnd(); 1.62 + 1.63 + material(1, 1, 1, 0.4); 1.64 + glPushMatrix(); 1.65 + glTranslatef(0, 1.3, -10); 1.66 + glFrontFace(GL_CW); 1.67 + bezier_teapot(2.0); 1.68 + glFrontFace(GL_CCW); 1.69 + glPopMatrix(); 1.70 } 1.71 1.72 static void toggle_hmd_fullscr()