diff options
-rw-r--r-- | src/render.c | 81 |
1 files changed, 27 insertions, 54 deletions
diff --git a/src/render.c b/src/render.c index 1ef1880..a8a9ced 100644 --- a/src/render.c +++ b/src/render.c @@ -510,89 +510,61 @@ static void render_setup_lighting(Game *game) { GLfloat pos[4]; GLfloat dir[3]; - GLfloat ambient[4]; + GLfloat ambient[4] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat diffuse[4]; GLfloat specular[4]; glEnable(GL_LIGHTING); + /* Set a very dull background */ ambient[0] = 0.01; ambient[1] = 0.01; ambient[2] = 0.01; ambient[3] = 1.0; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); + /* All lights have zero ambient (shader will ignore them) */ + ambient[0] = 0.0; ambient[1] = 0.0; ambient[2] = 0.0; + + /* Lander craft's headlight */ pos[0] = game->lander->x; pos[1] = game->lander->y; pos[2] = game->lander->z+0.3; pos[3] = 1.0; + glLightfv(GL_LIGHT0, GL_POSITION, pos); dir[0] = sinf(game->lander->yaw); dir[1] = cosf(game->lander->yaw); dir[2] = 0.0; dir[3] = 1.0; - diffuse[0] = 1.0; - diffuse[1] = 1.0; - diffuse[2] = 1.0; - diffuse[3] = 1.0; - specular[0] = 1.0; - specular[1] = 1.0; - specular[2] = 1.0; - specular[3] = 1.0; - ambient[0] = 0.0; - ambient[1] = 0.0; - ambient[2] = 0.0; - ambient[3] = 1.0; - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular); - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir); glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 20.0); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.02); + /* Headlight colours */ + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); /* Initialised to zero above */ + diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0; diffuse[3] = 1.0; + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + specular[0] = 1.0; specular[1] = 1.0; specular[2] = 1.0; specular[3] = 1.0; + glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); - pos[0] = -1.0; - pos[1] = 0.8; - pos[2] = 4.0; - pos[3] = 0.0; - diffuse[0] = 0.2; - diffuse[1] = 0.2; - diffuse[2] = 0.2; - diffuse[3] = 1.0; - specular[0] = 0.8; - specular[1] = 0.8; - specular[2] = 0.8; - specular[3] = 1.0; - ambient[0] = 0.0; - ambient[1] = 0.0; - ambient[2] = 0.0; - ambient[3] = 1.0; + /* A very dim fill-in light. Adds a tiny amount of shape to things, and lifts the floor a little */ + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); /* Initialised to zero above */ + pos[0] = -1.0; pos[1] = 0.8; pos[2] = 4.0; pos[3] = 0.0; glLightfv(GL_LIGHT1, GL_POSITION, pos); + diffuse[0] = 0.02; diffuse[1] = 0.02; diffuse[2] = 0.02; diffuse[3] = 1.0; glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); + specular[0] = 0.0; specular[1] = 0.0; specular[2] = 0.0; specular[3] = 1.0; glLightfv(GL_LIGHT1, GL_SPECULAR, specular); - glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glEnable(GL_LIGHT1); - pos[0] = -1.0; - pos[1] = 0.8; - pos[2] = 4.0; - pos[3] = 0.0; - diffuse[0] = 0.3; - diffuse[1] = 0.3; - diffuse[2] = 0.3; - diffuse[3] = 1.0; - specular[0] = 1.0; - specular[1] = 1.0; - specular[2] = 1.0; - specular[3] = 1.0; - ambient[0] = 0.0; - ambient[1] = 0.0; - ambient[2] = 0.0; - ambient[3] = 1.0; + /* A fill-in light, only used on its own, to light the lander craft itself */ + glLightfv(GL_LIGHT2, GL_AMBIENT, ambient); /* Initialised to zero above */ + pos[0] = -1.0; pos[1] = 0.8; pos[2] = 4.0; pos[3] = 0.0; glLightfv(GL_LIGHT2, GL_POSITION, pos); + diffuse[0] = 0.3; diffuse[1] = 0.3; diffuse[2] = 0.3; diffuse[3] = 1.0; glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse); + specular[0] = 1.0; specular[1] = 1.0; specular[2] = 1.0; specular[3] = 1.0; glLightfv(GL_LIGHT2, GL_SPECULAR, specular); - glLightfv(GL_LIGHT2, GL_AMBIENT, ambient); } @@ -691,6 +663,7 @@ static void render_draw_2d(RenderContext *r, Game *game) { void render_draw(Game *game, Uint32 t) { RenderContext *r; + GLfloat amb[] = { 0.0, 0.0, 0.0, 1.0 }; r = game->render; @@ -709,7 +682,7 @@ void render_draw(Game *game, Uint32 t) { game->lander->x, game->lander->y, game->lander->z+10.0, sqrtf(2.0)*sinf(game->lander->yaw), sqrtf(2.0)*cosf(game->lander->yaw), 0.0); render_setup_lighting(game); - GLfloat amb[] = { 0.1, 0.1, 0.1, 1.0 }; + amb[0] = 0.1; amb[1] = 0.1; amb[2] = 0.1; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); render_draw_stuff(game, t); @@ -754,14 +727,14 @@ void render_draw(Game *game, Uint32 t) { if ( r->shaders ) glUniform1i(glGetUniformLocation(game->render->lighting_program, "texture_enabled"), 1); if ( r->shaders ) glUniform1i(glGetUniformLocation(game->render->lighting_program, "fill_light_enabled"), 0); render_setup_lighting(game); + amb[0] = 0.02; amb[1] = 0.02; amb[2] = 0.02; + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); render_draw_stuff(game, t); /* Finally, draw the lander */ glEnable(GL_LIGHT2); glDisable(GL_LIGHT0); glDisable(GL_LIGHT1); - GLfloat amb[] = { 0.3, 0.3, 0.3, 1.0 }; - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); |