00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00058 glDisable(GL_LIGHTING);
00059
00060 glEnable(GL_TEXTURE_2D);
00061
00062
00063 glBindTexture(GL_TEXTURE_2D, getTexName());
00064
00065
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
00079 glEnable(GL_LIGHTING);
00080
00081
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
00128 glDisable(GL_TEXTURE_2D);
00129 }