diff --git a/lighting/SConstruct b/lighting/SConstruct index 6a5771b..90eefbe 100644 --- a/lighting/SConstruct +++ b/lighting/SConstruct @@ -3,6 +3,6 @@ env = Environment(LIBS = ['GL']) env.ParseConfig('sdl-config --cflags --libs') -sources = Glob('*.cc') +sources = [Glob('*.cc'), Glob('../glslUtil/*.c')] env.Program('test', sources) diff --git a/lighting/test.cc b/lighting/test.cc index d27f293..48b1de2 100644 --- a/lighting/test.cc +++ b/lighting/test.cc @@ -6,6 +6,7 @@ #include #include #include +#include "../glslUtil/glslUtil.h" using namespace std; @@ -27,11 +28,12 @@ const GLushort indices[] = { 0, 1, 2, 3, 4, 5 }; GLuint program, vs, fs, data_vbo, index_vbo; -GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc; +GLint ambient_loc, diffuse_loc, specular_loc, shininess_loc, transform_loc; enum Locations { LOC_POSITION, LOC_NORMAL }; +static guMatrix4x4 transform; char * loadFile(const char *fname) { @@ -131,15 +133,14 @@ bool init(int width, int height) glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glViewport(0, 0, WIDTH, HEIGHT); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + guMatrixLoadIdentity(&transform); float near = 0.1; float scale = near * 0.577 * 2; float aspect = (float)width / (float)height; - glFrustum(-aspect * scale, aspect * scale, -scale, scale, near, 1000.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0, 0, -1); + guMatrixFrustum(&transform, -aspect * scale, aspect * scale, -scale, scale, near, 1000.0); +// guPerspective(&transform, 60, (float)width / (float)height, 0.1, 1000.0); + guMatrixTranslate(&transform, 0, 0, -1); +// guMatrixTranslate(&transform, 1, 0.3, 0); vs = makeShader(GL_VERTEX_SHADER, "v_shader.glsl"); fs = makeShader(GL_FRAGMENT_SHADER, "f_shader.glsl"); @@ -174,12 +175,14 @@ bool init(int width, int height) diffuse_loc = glGetUniformLocation(program, "diffuse"); specular_loc = glGetUniformLocation(program, "specular"); shininess_loc = glGetUniformLocation(program, "shininess"); + transform_loc = glGetUniformLocation(program, "transform"); glUseProgram(program); glUniform4f(ambient_loc, 0.2, 0.2, 0.2, 1.0); glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0); glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0); glUniform1f(shininess_loc, 85.0); + glUniformMatrix4fv(transform_loc, 1, GL_TRUE, &transform[0][0]); data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data)); index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices)); diff --git a/lighting/v_shader.glsl b/lighting/v_shader.glsl index 6fde1ce..014d5e1 100644 --- a/lighting/v_shader.glsl +++ b/lighting/v_shader.glsl @@ -1,4 +1,6 @@ +uniform mat4 transform; + attribute vec3 pos; attribute vec3 normal; @@ -7,7 +9,7 @@ varying vec3 normal_i; void main(void) { - gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1); + gl_Position = transform * vec4(pos, 1); pos_i = vec3(gl_Position.x, gl_Position.y, gl_Position.z); - normal_i = gl_NormalMatrix * normal; + normal_i = vec3(transform * vec4(normal, 0.0)); }