Start work on spotlights

This commit is contained in:
Luke Benstead 2018-08-28 15:55:50 +01:00
parent c191ced3f9
commit 963eeb54da
2 changed files with 23 additions and 1 deletions

View File

@ -125,13 +125,18 @@ void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params) {
} }
} }
break; 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_CONSTANT_ATTENUATION:
case GL_LINEAR_ATTENUATION: case GL_LINEAR_ATTENUATION:
case GL_QUADRATIC_ATTENUATION: case GL_QUADRATIC_ATTENUATION:
case GL_SPOT_CUTOFF: case GL_SPOT_CUTOFF:
case GL_SPOT_DIRECTION:
case GL_SPOT_EXPONENT: case GL_SPOT_EXPONENT:
glLightf(light, pname, *params); glLightf(light, pname, *params);
break;
default: default:
_glKosThrowError(GL_INVALID_ENUM, __func__); _glKosThrowError(GL_INVALID_ENUM, __func__);
_glKosPrintError(); _glKosPrintError();
@ -156,7 +161,11 @@ void APIENTRY glLightf(GLenum light, GLenum pname, GLfloat param) {
LIGHTS[idx].quadratic_attenuation = param; LIGHTS[idx].quadratic_attenuation = param;
break; break;
case GL_SPOT_EXPONENT: case GL_SPOT_EXPONENT:
LIGHTS[idx].spot_exponent = param;
break;
case GL_SPOT_CUTOFF: case GL_SPOT_CUTOFF:
LIGHTS[idx].spot_cutoff = param;
break;
default: default:
_glKosThrowError(GL_INVALID_ENUM, __func__); _glKosThrowError(GL_INVALID_ENUM, __func__);
_glKosPrintError(); _glKosPrintError();

View File

@ -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_CONSTANT_ATTENUATION, 1.0f);
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.0001); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.0001);
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.00001); 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) */ /* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */