Created
April 20, 2023 22:31
-
-
Save dirocco/21120de48dafed376754879278f53f31 to your computer and use it in GitHub Desktop.
An example of how to draw reflection in OpenGL from 16 years ago
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Viewer::do_reflections() | |
{ | |
if (Settings::reflections) | |
{ | |
Settings::cel_reflection = true; | |
glColorMask(0, 0, 0, 0); | |
glEnable(GL_STENCIL_TEST); | |
glStencilFunc(GL_ALWAYS, 1, 1); | |
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); | |
glDisable(GL_DEPTH_TEST); | |
level->draw_reflective_surfaces(); | |
glEnable(GL_DEPTH_TEST); | |
color_mask(); | |
glStencilFunc(GL_EQUAL, 1, 1); | |
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); | |
double eqr[] = {0.0, -1.0, 0.0, -1.0 }; | |
glEnable(GL_CLIP_PLANE0); | |
glClipPlane(GL_CLIP_PLANE0, eqr); | |
glPushMatrix(); | |
glTranslatef(0.0, -2.0f, 0.0f); | |
glScalef(1.0f, -1.0f, 1.0f); | |
//glTranslatef(0.0, -1.0f, 0.0f); | |
game->draw(); | |
p_engine.draw(); | |
glPopMatrix(); | |
glDisable(GL_CLIP_PLANE0); | |
glDisable(GL_STENCIL_TEST); | |
glEnable(GL_BLEND); | |
glColor4f(1.0f, 1.0f, 1.0f, 0.5f); | |
//glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
level->draw_reflective_surfaces(); | |
glDisable(GL_BLEND); | |
} | |
else | |
level->draw_reflective_surfaces(); | |
Settings::cel_reflection = false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment