glClear(GL_DEPTH_BUFFER_BIT);
// Set up the transforms for the background. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustumf(-0.5, 0.5, -0.5, 0.5, NearPlane, FarPlane); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -NearPlane * 2);
// Render the dark background with alpha = 0. glDisable(GL_DEPTH_TEST); glColor4f(0.5, 0.5, 0.5, 0); glBindTexture(GL_TEXTURE_2D, m_textures.Tiger); RenderDrawable(m_drawables.Quad);
// Set up the transforms for the 3D scene. glMatrixMode(GL_PROJECTION); glLoadMatrixf(m_projection.Pointer()); glMatrixMode(GL_MODELVIEW); glRotatef(20, 1, 0, 0); glBindTexture(GL_TEXTURE_2D, m_textures.Marble);
// Render the disk normally. glColor4f(1, 1, 1, 1); glTranslatef(0, DiskY, 0); RenderDrawable(m_drawables.Disk); glTranslatef(0, -DiskY, 0); glEnable(GL_DEPTH_TEST);
// Render the reflection. glPushMatrix(); glRotatef(theta, 0, 1, 0); glTranslatef(0, KnotY, 0); glEnable(GL_LIGHTING); glBindTexture(GL_TEXTURE_2D, m_textures.Grille); glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); glEnable(GL_BLEND); glMatrixMode(GL_PROJECTION); glLoadMatrixf(m_mirror.Pointer()); RenderDrawable(m_drawables.Knot); glLoadMatrixf(m_projection.Pointer()); glMatrixMode(GL_MODELVIEW); glDisable(GL_LIGHTING); glPopMatrix();
// Render the disk again to make the reflection fade out. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, m_textures.Marble); glColor4f(1, 1, 1, 0.5); glDisable(GL_DEPTH_TEST); glTranslatef(0, DiskY, 0); RenderDrawable(m_drawables.Disk); glTranslatef(0, -DiskY, 0); glEnable(GL_DEPTH_TEST); glColor4f(1, 1, 1, 1); glDisable(GL_BLEND);
// Clear the depth buffer. glClear(GL_DEPTH_BUFFER_BIT);
// Render the floating object. glEnable(GL_LIGHTING); glBindTexture(GL_TEXTURE_2D, m_textures.Grille); glPushMatrix(); glTranslatef(0, KnotY, 0); glRotatef(theta, 0, 1, 0); RenderDrawable(m_drawables.Knot); glPopMatrix(); glDisable(GL_LIGHTING);
|