fixed lighting

This commit is contained in:
gmueller 2011-01-10 21:44:38 +01:00
parent 6fc4e795d2
commit eb987e1fa2
2 changed files with 15 additions and 14 deletions

View File

@ -4,8 +4,6 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include "MersenneTwister.h"
double rand2() { double rand2() {
float u = (float) rand() / (float) RAND_MAX; float u = (float) rand() / (float) RAND_MAX;
return 2.0 * (u - 0.5); return 2.0 * (u - 0.5);

View File

@ -23,6 +23,20 @@ void key_callback(int key, int state) {
} }
void setup_light() {
GLfloat LightAmbient[] = { 0.1f, 0.1f, 0.1f, 1.0f };
GLfloat LightDiffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
GLfloat LightPosition[] = { 1.0f, 1.0f, 1.0f, 0.0f };
// setup directional light
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
glEnable( GL_LIGHT0);
glEnable( GL_LIGHTING);
}
void setup_opengl() { void setup_opengl() {
// Initialise GLFW // Initialise GLFW
if (!glfwInit()) { if (!glfwInit()) {
@ -52,17 +66,6 @@ void setup_opengl() {
glEnable( GL_DEPTH_TEST); glEnable( GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL); glDepthFunc( GL_LEQUAL);
GLfloat LightAmbient[] = { 0.1f, 0.1f, 0.1f, 1.0f };
GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[] = { 0.0f, 0.0f, 2.0f, 1.0f };
// setup directional light
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
glEnable( GL_LIGHT1);
glEnable( GL_LIGHTING);
// Enable vertical sync (on cards that support it) // Enable vertical sync (on cards that support it)
glfwSwapInterval(1); glfwSwapInterval(1);
} }
@ -672,7 +675,7 @@ void Application::update() {
} }
prepareFrame(rx, ry, rz); prepareFrame(rx, ry, rz);
setup_light();
glEnable( GL_LIGHT0); glEnable( GL_LIGHT0);
glEnable( GL_LIGHTING); glEnable( GL_LIGHTING);
glEnable( GL_CULL_FACE); glEnable( GL_CULL_FACE);