/* * * Stenciltricks, code to perform tricks with OpenGL's stencil buffer easily. * * Copyright (C) 2006-2007 Alejandro Valenzuela Roca, * * http://mexinetica.com/~lanjoe9 * * This file is part of MotorJ, a free framework for videogame creation. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #include "stenciltricks.h" #ifndef NINTENDO_DS // FIXME: Should not be auto-compiled in Nintendo DS (No stencil buffer in Nintendo DS.) #ifndef NINTENDO_WII // FIXME: Stencil stuff is probably supported on the Wii void st_do_trick(stenciltrick * trick, float t_elapsed){ float step = t_elapsed/(float)trick->duracion; if (trick->porciento < 100){ if (trick->porciento+step > 100){ trick->porciento = 100; } else { trick->porciento += step; } if (trick->tipo == ST_CORTINILLA_ABRIR){ glClearStencil(0); glClear( GL_STENCIL_BUFFER_BIT ); glStencilFunc( GL_ALWAYS, 1, 1); glPushMatrix(); glLoadIdentity(); //Deshabilitar algunas cosas glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Buffer de color glEnable( GL_STENCIL_TEST ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); glDisable(GL_DEPTH_TEST); // Buffer de profundidad glDisable(GL_TEXTURE_2D); // Texturizado glDisable( GL_LIGHTING ); // Iluminación glColor3f( 1.0f, 1.0f, 1.0f); //glTranslatef(0.1,0.1,0); glRotatef(1080*(trick->porciento/100), 0, 0, 1); glBegin(GL_POLYGON); glVertex3f(0, 3.0*(trick->porciento/100), -2); glVertex3f(-2.0*(trick->porciento/100), 2.0*(trick->porciento/100), -2); glVertex3f(-3.0*(trick->porciento/100), 0, -2); glVertex3f(-2.0*(trick->porciento/100), -2.0*(trick->porciento/100), -2); glVertex3f(0, -3.0*(trick->porciento/100), -2); glVertex3f(2.0*(trick->porciento/100), -2.0*(trick->porciento/100), -2); glVertex3f(3.0*(trick->porciento/100), 0, -2); glVertex3f(2.0*(trick->porciento/100), 2.0*(trick->porciento/100), -2); glEnd(); glPopMatrix(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); //glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); //glClear( GL_STENCIL_BUFFER_BIT ); glEnable( GL_LIGHTING ); // Set the stencil buffer to only allow writing // to the screen when the value of the // stencil buffer is 1 glStencilFunc( GL_EQUAL, 1, 1 ); glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); if (trick->porciento>99){ glClearStencil(1); glClear( GL_STENCIL_BUFFER_BIT ); } }else if (trick->tipo == ST_CORTINILLA_CERRAR){ float invporciento = (100-trick->porciento); glClearStencil(0); glClear( GL_STENCIL_BUFFER_BIT ); glStencilFunc( GL_ALWAYS, 1, 1); glPushMatrix(); glLoadIdentity(); //Deshabilitar algunas cosas glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Buffer de color glEnable( GL_STENCIL_TEST ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); glDisable(GL_DEPTH_TEST); // Buffer de profundidad glDisable(GL_TEXTURE_2D); // Texturizado glDisable( GL_LIGHTING ); // Iluminación glColor3f( 1.0f, 1.0f, 1.0f); //glTranslatef(0.1,0.1,0); glRotatef(1080*(trick->porciento/100), 0, 0, 1); glBegin(GL_POLYGON); glVertex3f(0, 3.0*(invporciento/100), -2); glVertex3f(-2.0*(invporciento/100), 2.0*(invporciento/100), -2); glVertex3f(-3.0*(invporciento/100), 0, -2); glVertex3f(-2.0*(invporciento/100), -2.0*(invporciento/100), -2); glVertex3f(0, -3.0*(invporciento/100), -2); glVertex3f(2.0*(invporciento/100), -2.0*(invporciento/100), -2); glVertex3f(3.0*(invporciento/100), 0, -2); glVertex3f(2.0*(invporciento/100), 2.0*(invporciento/100), -2); glEnd(); glPopMatrix(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); //glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); //glClear( GL_STENCIL_BUFFER_BIT ); glEnable( GL_LIGHTING ); // Set the stencil buffer to only allow writing // to the screen when the value of the // stencil buffer is 1 glStencilFunc( GL_EQUAL, 1, 1 ); glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); if (trick->porciento>99){ glClearStencil(0); glClear( GL_STENCIL_BUFFER_BIT ); } } } } #endif #endif