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 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
WIN APIWIN API par omarino_007
Cliquez pour lire la suite par omarino_007
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|