Accueil > > > REFLECTION D'OBJ (OPENGL)
REFLECTION D'OBJ (OPENGL)
Information sur la source
Description
Voila ceci est un effet de relfection d'objet sur une surface. j'avait chercher sur le net des cours et des sources sur comment realiser cette effet et j'ai trouver que tous les sources presente utilise le meme principe qui est un peut trop long et moin satisfesant. Alors j'ai pensé de creé mon propre algo sans utiliser le stencil buffer ni le glcolormask et d'esseyer de reduire le code. ben j'ai constater que mon algo personel est plus rapide et c plus JOLI. Le zip conteint deux exe Reflecton General.exe : utilise le stencil buffer et glcolormask ansi que le blending (la methode que tous le monde utilise) Reflect.exe = utilise que le blending (c celui que j'ai realiser et qui est livré avec ces sources ) je pense que mon algo et mieux que l'algo courant , si je me trompe sur ce point veuillez vous me le dire en m'expliquant pourquoi Merci d'avance j'espere que j'ai pas commi bcp de fote ;D ---------------------- Merci a platon179 -----------------------
Source
- 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;
Fichier Zip
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko [FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|