From fd3e7cde6c870da795438a2b79c0efca90dd56a7 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Thu, 14 Nov 2019 21:12:27 +0000 Subject: [PATCH] Improve the light sample + tweaks --- GL/lighting.c | 2 +- samples/lights/main.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/GL/lighting.c b/GL/lighting.c index 6283350..d75ad65 100644 --- a/GL/lighting.c +++ b/GL/lighting.c @@ -395,7 +395,7 @@ void _glCalculateLighting(EyeSpaceData* ES, Vertex* vertex) { const GLfloat k0 = light->constant_attenuation; const GLfloat k1 = light->linear_attenuation; const GLfloat k2 = light->quadratic_attenuation; - const GLfloat att = (light->position[3] == 0) ? 1.0f : 1.0f / k0 + (k1 * VPpliL) + (k2 * VPpliL * VPpliL); + const GLfloat att = (light->position[3] == 0.0f) ? 1.0f : 1.0f / (k0 + (k1 * VPpliL) + (k2 * VPpliL * VPpliL)); const GLfloat spot = 1.0f; // FIXME: Spotlights const GLfloat fi = (ndotVPpli == 0) ? 0 : 1; diff --git a/samples/lights/main.c b/samples/lights/main.c index e02d85a..a0e94fc 100644 --- a/samples/lights/main.c +++ b/samples/lights/main.c @@ -171,6 +171,16 @@ void InitGL(int Width, int Height) glLightfv(GL_LIGHT0, GL_POSITION, position); glDisable(GL_TEXTURE_2D); + + diffuseLight[1] = 1.0f; + + glEnable(GL_LIGHT1); + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight); + glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight); + + glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.0); + glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 4.5 / 100); + glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 75.0f / (100 * 100)); } @@ -189,6 +199,14 @@ void ReSizeGLScene(int Width, int Height) } void DrawCube(float x, float z) { + static float pos = 0.0f; + const static float radius = 30.0f; + + pos += 0.001f; + + GLfloat position[] = { cos(pos) * radius, 15.0f, sin(pos) * radius, 1.0f }; + glLightfv(GL_LIGHT1, GL_POSITION, position); + glPushMatrix(); glTranslatef(x, 0, z); glColor4f(1, 1, 1, 1);