From 963eeb54da9f53e2ff20f81296f5392b8ab5f62f Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Tue, 28 Aug 2018 15:55:50 +0100 Subject: [PATCH] Start work on spotlights --- GL/lighting.c | 11 ++++++++++- samples/lerabot01/main.c | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/GL/lighting.c b/GL/lighting.c index b13f2a3..d52d3f1 100644 --- a/GL/lighting.c +++ b/GL/lighting.c @@ -125,13 +125,18 @@ void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params) { } } break; + case GL_SPOT_DIRECTION: { + LIGHTS[idx].spot_direction[0] = params[0]; + LIGHTS[idx].spot_direction[1] = params[1]; + LIGHTS[idx].spot_direction[2] = params[2]; + } break; case GL_CONSTANT_ATTENUATION: case GL_LINEAR_ATTENUATION: case GL_QUADRATIC_ATTENUATION: case GL_SPOT_CUTOFF: - case GL_SPOT_DIRECTION: case GL_SPOT_EXPONENT: glLightf(light, pname, *params); + break; default: _glKosThrowError(GL_INVALID_ENUM, __func__); _glKosPrintError(); @@ -156,7 +161,11 @@ void APIENTRY glLightf(GLenum light, GLenum pname, GLfloat param) { LIGHTS[idx].quadratic_attenuation = param; break; case GL_SPOT_EXPONENT: + LIGHTS[idx].spot_exponent = param; + break; case GL_SPOT_CUTOFF: + LIGHTS[idx].spot_cutoff = param; + break; default: _glKosThrowError(GL_INVALID_ENUM, __func__); _glKosPrintError(); diff --git a/samples/lerabot01/main.c b/samples/lerabot01/main.c index 07333a1..4ce79b6 100644 --- a/samples/lerabot01/main.c +++ b/samples/lerabot01/main.c @@ -162,6 +162,19 @@ void InitGL(int Width, int Height) // We call this right after our OpenG glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.0f); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.0001); glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.00001); + + GLfloat l2_pos[] = {0.0, 15.0, 1.0, 1.0}; + GLfloat l2_dir[] = {0.0, -1.0, 0.0}; + GLfloat l2_diff[] = {0.5, 0.5, 0.0, 1.0}; + GLfloat l2_amb[] = {0.5, 0.5, 0.5, 1.0}; + + glEnable(GL_LIGHT2); + glLightfv(GL_LIGHT2, GL_DIFFUSE, l2_diff); + glLightfv(GL_LIGHT2, GL_POSITION, l2_pos); + glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, l2_dir); + glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 1.0f); + glLightf(GL_LIGHT2, GL_LINEAR_ATTENUATION, 0.0001); + glLightf(GL_LIGHT2, GL_QUADRATIC_ATTENUATION, 0.00001); } /* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */