- Finalement voila deux sources des deux effets :
- constater vous meme :D
-
- Reflection : Methode Courant
- ---------------------------------------
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);// Clears the screen.
- glLoadIdentity(); //Reset modelview matrix for new frame.
-
-
- // Here we just set the camera's position.
- gluLookAt(0.0f, 1.5f, 2.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
-
- // Since our reflections uses the stencil buffer we must enable it. Just like if we
- // are enabling depth testing.
- glEnable(GL_STENCIL_TEST);
-
- // Next we must disable depth testing and turn off color modifications on all colors.
- glDisable(GL_DEPTH_TEST);
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-
- // Next two functions will set up the stencil buffer and stencil test.
- glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
- glStencilFunc(GL_ALWAYS, 1, 1); // Test all.
-
- // Now we will draw everything that can reflect the surroundings. This will not
- // actually draw the ground just the "area" that makes up it.
- DrawGround();
-
- // Now we enable depth testing back and enable the color mask.
- glEnable(GL_DEPTH_TEST);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
- // Next we will set the stencil test to pixels equal to 1. What this means is that
- // every pixel on the object that reflects if it has a 1 set to it then we draw on it.
- // Above we set the stencil test to always 1 so when we rendered the ground every pixel
- // of the ground was given the ability to be drawn on. Now we draw everything that we
- // want reflection onto the "ground stencil area".
- glStencilFunc(GL_EQUAL, 1, 1);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-
- // Draw the reflection.
- glPushMatrix();
-
- // We scale to invert the object onto the ground.
- glScalef(1.0, -1.0, 1.0);
-
- // Draw the reflected cube.
- DrawCube();
-
- glPopMatrix();
-
- // Now we are done. We can disable the stencil buffer so what we draw from here on out
- // is not drawn on the ground "area".
- glDisable(GL_STENCIL_TEST);
-
- // Now we can draw the ground. We will blend the ground with the stencil "area"and give
- // it alpha so we can see the reflection.
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- // Set the alpha to 50%.
- glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
-
- // Draw the ground.
- DrawGround();
-
- // Stop the blending.
- glDisable(GL_BLEND);
-
- // Well we are done. Now we draw the cube normally.
- DrawCube();
-
-
- // Increase the objects rotation.
- Rotation += 0.5;
-
- // Reset it if the rotation goes over 360.
- if(Rotation > 360.0f)
- Rotation = 0.0f;
-
-
- glFlush();
- -------------------------------------------------------
-
- Reflection propre algo
- ---------
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
-
- //Place la camera
-
- gluLookAt(0.0f, 2.8f, -4.0f, 0.0f, 0.8f, 0.0f, 0.0f, 1.0f, 0.0f);
-
-
- glPushMatrix();
-
- // Inversé l'obj sur le sol
- glScalef(1.0, -1.0, 1.0);
-
- // Dessine le cube reflecté
- DrawCube();
-
- glPopMatrix();
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glColor4f(1.0f, 1.0f, 1.0f, 0.7f);
-
- // Dessine le sol
- DrawGround();
-
- glDisable(GL_BLEND);
- //Le Cube Normal
-
- DrawCube();
-
- // Rotation
- rot += 0.5;
-
- if(rot > 360.0f)
- rot = 0.0f;
-
- glFlush();
- return TRUE;
Finalement voila deux sources des deux effets :
constater vous meme :D
Reflection : Methode Courant
---------------------------------------
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);// Clears the screen.
glLoadIdentity(); //Reset modelview matrix for new frame.
// Here we just set the camera's position.
gluLookAt(0.0f, 1.5f, 2.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
// Since our reflections uses the stencil buffer we must enable it. Just like if we
// are enabling depth testing.
glEnable(GL_STENCIL_TEST);
// Next we must disable depth testing and turn off color modifications on all colors.
glDisable(GL_DEPTH_TEST);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
// Next two functions will set up the stencil buffer and stencil test.
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 1); // Test all.
// Now we will draw everything that can reflect the surroundings. This will not
// actually draw the ground just the "area" that makes up it.
DrawGround();
// Now we enable depth testing back and enable the color mask.
glEnable(GL_DEPTH_TEST);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
// Next we will set the stencil test to pixels equal to 1. What this means is that
// every pixel on the object that reflects if it has a 1 set to it then we draw on it.
// Above we set the stencil test to always 1 so when we rendered the ground every pixel
// of the ground was given the ability to be drawn on. Now we draw everything that we
// want reflection onto the "ground stencil area".
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Draw the reflection.
glPushMatrix();
// We scale to invert the object onto the ground.
glScalef(1.0, -1.0, 1.0);
// Draw the reflected cube.
DrawCube();
glPopMatrix();
// Now we are done. We can disable the stencil buffer so what we draw from here on out
// is not drawn on the ground "area".
glDisable(GL_STENCIL_TEST);
// Now we can draw the ground. We will blend the ground with the stencil "area"and give
// it alpha so we can see the reflection.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Set the alpha to 50%.
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
// Draw the ground.
DrawGround();
// Stop the blending.
glDisable(GL_BLEND);
// Well we are done. Now we draw the cube normally.
DrawCube();
// Increase the objects rotation.
Rotation += 0.5;
// Reset it if the rotation goes over 360.
if(Rotation > 360.0f)
Rotation = 0.0f;
glFlush();
-------------------------------------------------------
Reflection propre algo
---------
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//Place la camera
gluLookAt(0.0f, 2.8f, -4.0f, 0.0f, 0.8f, 0.0f, 0.0f, 1.0f, 0.0f);
glPushMatrix();
// Inversé l'obj sur le sol
glScalef(1.0, -1.0, 1.0);
// Dessine le cube reflecté
DrawCube();
glPopMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f, 1.0f, 1.0f, 0.7f);
// Dessine le sol
DrawGround();
glDisable(GL_BLEND);
//Le Cube Normal
DrawCube();
// Rotation
rot += 0.5;
if(rot > 360.0f)
rot = 0.0f;
glFlush();
return TRUE;