summaryrefslogtreecommitdiffstats
path: root/Game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Game.cpp')
-rw-r--r--Game.cpp54
1 files changed, 42 insertions, 12 deletions
diff --git a/Game.cpp b/Game.cpp
index 46f942f..d948b2f 100644
--- a/Game.cpp
+++ b/Game.cpp
@@ -20,12 +20,13 @@
#include "Game.h"
#include "BSPTree.h"
#include "Level.h"
+#include "Shader.h"
#include "Triangle.h"
#include "gl.h"
namespace Zoom {
-Game::Game(bool multisample) : angle(0) {
+Game::Game(bool multisample) : angle(0), lightPos(0) {
glClearColor(0.0, 0.0, 0.0, 1.0);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
@@ -42,19 +43,23 @@ Game::Game(bool multisample) : angle(0) {
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
- static const float light[] = {0, 0, 0, 1};
- static const float lightColor[] = {1, 1, 1, 1};
- glLightfv(GL_LIGHT0, GL_POSITION, light);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
+ glLightfv(GL_LIGHT0, GL_AMBIENT, vmml::vec4f::ZERO.array);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, vmml::vec4f::ONE.array);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, vmml::vec4f::ONE.array);
+ glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0);
+ glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.3);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vmml::vec4f::ONE.array);
+ glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 128);
+
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
- glLoadIdentity();
+ Shader::loadProgram("default.vert", "default.frag");
loadLevel("level.xml");
}
@@ -70,21 +75,46 @@ void Game::run(int delta) {
if(angle >= 360)
angle -= 360;
+
+ lightPos += delta;
+ lightPos %= 24000;
}
void Game::render() {
- std::list<BSPTree::TriangleRecord> triangles;
+ int i;
+ float light[] = {0, 0, 0, 1};
+
+ if(lightPos < 12000) i = lightPos;
+ else i = 24000 - lightPos;
+
+ if(i < 4000) {
+ light[0] = 0.0;
+ light[2] = -i * 0.001;
+ }
+ else if(i < 8000) {
+ light[0] = (i-4000) * 0.001;
+ light[2] = -4.0;
+ }
+ else if(i < 12000) {
+ light[0] = 4.0;
+ light[2] = -4.0 - (i-8000) * 0.001;
+ }
+ else {
+ light[0] = 4.0;
+ light[2] = -8.0;
+ }
- triangles.insert(triangles.end(), level->getRooms().front().walls.begin(), level->getRooms().front().walls.end());
+ glLightfv(GL_LIGHT0, GL_POSITION, light);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
- glRotatef(angle, 1, 2, 1);
- //glRotatef(3*angle, 0, -1, 2);
- //glRotatef(5*angle, 2, -1, 0);
+ //glRotatef(10, 1, 2, 1);
+ /*glRotatef(5*angle, 0, -1, 2);
+ glRotatef(7*angle, 2, -1, 0);
+ glRotatef(11*angle, 2, -1, 2);*/
- renderer.render(triangles);
+ renderer.render(level->getRooms().front().walls);
glPopMatrix();
}