src/WallCell.cpp

Go to the documentation of this file.
00001 
00008 /*
00009 This file is part of Teapot Colony Wars.
00010 
00011 Teapot Colony Wars is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU General Public License as published by
00013 the Free Software Foundation, either version 2 of the License, or
00014 (at your option) any later version.
00015 
00016 Teapot Colony Wars is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with Teapot Colony Wars.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 #include "WallCell.h"
00026 
00027 #include <GL/glut.h>
00028 
00029 #include "Constants.h"
00030 #include "Image.h"
00031 
00032 GLuint WallCell::_tex_name = 0;
00033 
00034 GLuint WallCell::getTexName() {
00035   if(_tex_name == 0) {
00036     Image texture("./textures/WallCell.bmp");
00037     _tex_name = texture.genTexture2D();
00038   }
00039 
00040   return _tex_name;
00041 }
00042 
00043 WallCell::WallCell() {
00044 
00045 }
00046 
00047 WallCell::~WallCell() {
00048 
00049 }
00050 
00051 void WallCell::draw() {
00052   glMatrixMode(GL_MODELVIEW);
00053   glColor3ub((GLubyte) COLOR_MAX,
00054              (GLubyte) COLOR_MAX,
00055              (GLubyte) COLOR_MAX);
00056 
00057   // extinction des lumière pour la face supérieure
00058   glDisable(GL_LIGHTING);
00059   // activation des textures 2D
00060   glEnable(GL_TEXTURE_2D);
00061 
00062   // changement de texture courante
00063   glBindTexture(GL_TEXTURE_2D, getTexName());
00064 
00065   // affichage de la face supérieure
00066   glBegin(GL_TRIANGLE_STRIP);
00067     glNormal3f(0.0, 1.0, 0.0);
00068     glTexCoord2f(0.0, 1.0);
00069     glVertex3f(-0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT, -0.5 * CELL_SIZE);
00070     glTexCoord2f(0.0, 0.0);
00071     glVertex3f(-0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT,  0.5 * CELL_SIZE);
00072     glTexCoord2f(1.0, 1.0);
00073     glVertex3f( 0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT, -0.5 * CELL_SIZE);
00074     glTexCoord2f(1.0, 0.0);
00075     glVertex3f( 0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT,  0.5 * CELL_SIZE);
00076   glEnd();
00077 
00078   // réactivation des lumières
00079   glEnable(GL_LIGHTING);
00080 
00081   // affichage des cotés du mur
00082   glBegin(GL_TRIANGLE_STRIP);
00083     glNormal3f(1.0, 0.0, 0.0);
00084     glTexCoord2f(0.0, 1.0);
00085     glVertex3f( 0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT, -0.5 * CELL_SIZE);
00086     glTexCoord2f(1.0, 1.0);
00087     glVertex3f( 0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT,  0.5 * CELL_SIZE);
00088     glTexCoord2f(0.0, 0.0);
00089     glVertex3f( 0.5 * CELL_SIZE, 0.0, -0.5 * CELL_SIZE);
00090     glTexCoord2f(1.0, 0.0);
00091     glVertex3f( 0.5 * CELL_SIZE, 0.0,  0.5 * CELL_SIZE);
00092   glEnd();
00093   glBegin(GL_TRIANGLE_STRIP);
00094     glNormal3f(-1.0, 0.0, 0.0);
00095     glTexCoord2f(0.0, 1.0);
00096     glVertex3f(-0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT, -0.5 * CELL_SIZE);
00097     glTexCoord2f(1.0, 1.0);
00098     glVertex3f(-0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT,  0.5 * CELL_SIZE);
00099     glTexCoord2f(0.0, 0.0);
00100     glVertex3f(-0.5 * CELL_SIZE, 0.0, -0.5 * CELL_SIZE);
00101     glTexCoord2f(1.0, 0.0);
00102     glVertex3f(-0.5 * CELL_SIZE, 0.0,  0.5 * CELL_SIZE);
00103   glEnd();
00104   glBegin(GL_TRIANGLE_STRIP);
00105     glNormal3f(0.0, 0.0, 1.0);
00106     glTexCoord2f(0.0, 1.0);
00107     glVertex3f(-0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT,  0.5 * CELL_SIZE);
00108     glTexCoord2f(1.0, 1.0);
00109     glVertex3f( 0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT,  0.5 * CELL_SIZE);
00110     glTexCoord2f(0.0, 0.0);
00111     glVertex3f(-0.5 * CELL_SIZE, 0.0,  0.5 * CELL_SIZE);
00112     glTexCoord2f(1.0, 0.0);
00113     glVertex3f( 0.5 * CELL_SIZE, 0.0,  0.5 * CELL_SIZE);
00114   glEnd();
00115   glBegin(GL_TRIANGLE_STRIP);
00116     glNormal3f(0.0, 0.0, -1.0);
00117     glTexCoord2f(0.0, 1.0);
00118     glVertex3f(-0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT, -0.5 * CELL_SIZE);
00119     glTexCoord2f(1.0, 1.0);
00120     glVertex3f( 0.5 * CELL_SIZE, (GLfloat) WALL_HEIGHT, -0.5 * CELL_SIZE);
00121     glTexCoord2f(0.0, 0.0);
00122     glVertex3f(-0.5 * CELL_SIZE, 0.0, -0.5 * CELL_SIZE);
00123     glTexCoord2f(1.0, 0.0);
00124     glVertex3f( 0.5 * CELL_SIZE, 0.0, -0.5 * CELL_SIZE);
00125   glEnd();
00126 
00127   // désactivation des textures
00128   glDisable(GL_TEXTURE_2D);
00129 }

Generated on Sat Feb 2 22:22:54 2008 for Teapot Colony Wars by  doxygen 1.5.4