twn_fog.c: fog added!

This commit is contained in:
2024-10-01 16:10:36 +03:00
parent edc6fb1e5c
commit ad0438849e
7 changed files with 76 additions and 0 deletions

View File

@ -666,3 +666,30 @@ void finally_render_skybox(char *paths) {
glCallList(list);
}
void finally_apply_fog(float start, float end, float density, Color color) {
if (density < 0.0f || density > 1.0f)
log_warn("Invalid fog density given, should be in range [0..1]");
/* TODO: cache it for constant parameters, which is a common case */
glEnable(GL_FOG);
glFogf(GL_FOG_DENSITY, density);
glFogf(GL_FOG_START, start);
glFogf(GL_FOG_END, end);
float color_conv[4];
color_conv[0] = (float)color.r / UINT8_MAX;
color_conv[1] = (float)color.g / UINT8_MAX;
color_conv[2] = (float)color.b / UINT8_MAX;
color_conv[3] = (float)color.a / UINT8_MAX;
glFogfv(GL_FOG_COLOR, color_conv);
}
void finally_pop_fog(void) {
glDisable(GL_FOG);
}