Each module now includes its own header first. Removed sstream.h and the definition...
[crack-attack.git] / src / obj_name.cxx
blobb46c9dfa31389ce5fe81c4725e8957ab6a9d08b1
1 /*
2 * names.cxx
3 * Daniel Nelson - 11/9/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
25 * Build the name texture.
28 #include <GL/glut.h>
30 #include "glext.h"
32 #include "Game.h"
33 #include "Displayer.h"
34 #include "String.h"
35 #include "MetaState.h"
36 #include "Communicator.h"
38 GLuint Displayer::name_texture;
40 void Displayer::generateNameTexture ( )
42 glGenTextures(1, &name_texture);
44 glBindTexture(GL_TEXTURE_2D, name_texture);
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
51 GLubyte texture[DC_NAME_TEX_LENGTH_T][DC_NAME_TEX_LENGTH_S][3];
52 for (int t = DC_NAME_TEX_LENGTH_T; t--; )
53 for (int s = DC_NAME_TEX_LENGTH_S; s--; )
54 texture[t][s][0] = texture[t][s][1] = texture[t][s][2] = 0;
56 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, DC_NAME_TEX_LENGTH_S,
57 DC_NAME_TEX_LENGTH_T, GL_FALSE, GL_RGB, GL_UNSIGNED_BYTE, texture);
59 if (MetaState::mode & CM_SOLO) {
61 int width = String::stringWidth(MetaState::player_name,
62 DC_NAME_TEX_LENGTH_S);
64 GLubyte *name_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
65 String::fillStringTexture(MetaState::player_name, name_subtexture, width);
67 glTexSubImage2D(GL_TEXTURE_2D, 0, (DC_NAME_TEX_LENGTH_S - width) / 2,
68 (DC_NAME_TEX_LENGTH_T - DC_LETTER_TEX_LENGTH) / 2, width,
69 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, name_subtexture);
71 if (name_subtexture != null) {
72 delete [] name_subtexture;
73 name_subtexture = null;
76 } else {
77 int x;
78 int width;
79 GLubyte *string_subtexture;
81 width = String::stringWidth(DC_VS_STRING, DC_NAME_TEX_LENGTH_S);
83 string_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
84 String::fillStringTexture(DC_VS_STRING, string_subtexture, width);
86 glTexSubImage2D(GL_TEXTURE_2D, 0, (DC_NAME_TEX_LENGTH_S - width) / 2,
87 (DC_NAME_TEX_LENGTH_T - DC_LETTER_TEX_LENGTH) / 2, width,
88 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, string_subtexture);
90 if (string_subtexture != null) {
91 delete [] string_subtexture;
92 string_subtexture = null;
95 width = String::stringWidth(MetaState::player_name, DC_NAME_TEX_LENGTH_S);
97 string_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
98 String::fillStringTexture(MetaState::player_name, string_subtexture, width);
100 if (width >= 2 * DC_NAME_TEX_LENGTH_S / 3)
101 x = 0;
102 else
103 x = ((2 * DC_NAME_TEX_LENGTH_S / 3) - width) / 2;
104 glTexSubImage2D(GL_TEXTURE_2D, 0, x, 0, width,
105 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, string_subtexture);
107 if (string_subtexture != null) {
108 delete [] string_subtexture;
109 string_subtexture = null;
112 width = String::stringWidth(Communicator::opponent_name,
113 DC_NAME_TEX_LENGTH_S);
115 string_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
116 String::fillStringTexture(Communicator::opponent_name, string_subtexture,
117 width);
119 if (width >= 2 * DC_NAME_TEX_LENGTH_S / 3)
120 x = DC_NAME_TEX_LENGTH_S - width;
121 else
122 x = DC_NAME_TEX_LENGTH_S - width
123 - ((2 * DC_NAME_TEX_LENGTH_S / 3) - width) / 2;
124 glTexSubImage2D(GL_TEXTURE_2D, 0, x,
125 DC_NAME_TEX_LENGTH_T - DC_LETTER_TEX_LENGTH, width,
126 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, string_subtexture);
128 if (string_subtexture != null) {
129 delete [] string_subtexture;
130 string_subtexture = null;