diff --git a/GL/lighting.c b/GL/lighting.c index 53cd500..3a9aa9a 100644 --- a/GL/lighting.c +++ b/GL/lighting.c @@ -105,8 +105,17 @@ void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params) { case GL_SPECULAR: memcpy(LIGHTS[idx].specular, params, sizeof(GLfloat) * 4); break; - case GL_POSITION: + case GL_POSITION: { + _matrixLoadModelView(); memcpy(LIGHTS[idx].position, params, sizeof(GLfloat) * 4); + + mat_trans_single4( + LIGHTS[idx].position[0], + LIGHTS[idx].position[1], + LIGHTS[idx].position[2], + LIGHTS[idx].position[3] + ); + } break; case GL_CONSTANT_ATTENUATION: case GL_LINEAR_ATTENUATION: @@ -252,7 +261,12 @@ void calculateLightingContribution(const GLint light, const GLfloat* pos, const GLfloat d; vec3f_length(L.x, L.y, L.z, d); - vec3f_normalize(L.x, L.y, L.z); + GLfloat oneOverL = 1.0f / d; + + L.x *= oneOverL; + L.y *= oneOverL; + L.z *= oneOverL; + vec3f_normalize(V.x, V.y, V.z); GLfloat NdotL; diff --git a/samples/lerabot01/main.c b/samples/lerabot01/main.c index 263a11c..07333a1 100644 --- a/samples/lerabot01/main.c +++ b/samples/lerabot01/main.c @@ -245,7 +245,6 @@ void DrawTexturedQuad(int tex, float x, float y, float z) glVertexPointer(3, GL_FLOAT, 0, vertex_data); glDrawArrays(GL_QUADS, 0, 4); - glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); @@ -259,11 +258,11 @@ void DrawGLScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View - //glTranslatef(-5.0f, -5.0f, -10.0f); - glTranslatef(-50.0f, 0.0f, -200.0f); - GLfloat l1_pos[] = {50 + sin(delta) * 100.0f, 25.0, 1.0, 1.0}; - delta+= 0.03; + glTranslatef(-50.0f, 0.0f, -100.0f); + + GLfloat l1_pos[] = {50 + sin(delta) * 100.0f, 6.0, 5.0, 1.0}; + delta += 0.03; glLightfv(GL_LIGHT1, GL_POSITION, l1_pos); //glLightfv(GL_LIGHT1, GL_SPOT_EXPONENT, 3);