More glext-e fun. Do you love it? DO YA!!
[crack-attack.git] / src / obj_name.cxx
blob684bf8be4c1be7c96122a6a2c66b9d408b6b6ce8
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 using namespace std;
34 #include "Game.h"
35 #include "Displayer.h"
36 #include "String.h"
37 #include "MetaState.h"
38 #include "Communicator.h"
40 GLuint Displayer::name_texture;
42 void Displayer::generateNameTexture ( )
44 glGenTextures(1, &name_texture);
46 glBindTexture(GL_TEXTURE_2D, name_texture);
48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
53 GLubyte texture[DC_NAME_TEX_LENGTH_T][DC_NAME_TEX_LENGTH_S][3];
54 for (int t = DC_NAME_TEX_LENGTH_T; t--; )
55 for (int s = DC_NAME_TEX_LENGTH_S; s--; )
56 texture[t][s][0] = texture[t][s][1] = texture[t][s][2] = 0;
58 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, DC_NAME_TEX_LENGTH_S,
59 DC_NAME_TEX_LENGTH_T, GL_FALSE, GL_RGB, GL_UNSIGNED_BYTE, texture);
61 if (MetaState::mode & CM_SOLO) {
63 int width = String::stringWidth(MetaState::player_name,
64 DC_NAME_TEX_LENGTH_S);
66 GLubyte *name_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
67 String::fillStringTexture(MetaState::player_name, name_subtexture, width);
69 glTexSubImage2D(GL_TEXTURE_2D, 0, (DC_NAME_TEX_LENGTH_S - width) / 2,
70 (DC_NAME_TEX_LENGTH_T - DC_LETTER_TEX_LENGTH) / 2, width,
71 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, name_subtexture);
73 if (name_subtexture != null) {
74 delete [] name_subtexture;
75 name_subtexture = null;
78 } else {
79 int x;
80 int width;
81 GLubyte *string_subtexture;
83 width = String::stringWidth(DC_VS_STRING, DC_NAME_TEX_LENGTH_S);
85 string_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
86 String::fillStringTexture(DC_VS_STRING, string_subtexture, width);
88 glTexSubImage2D(GL_TEXTURE_2D, 0, (DC_NAME_TEX_LENGTH_S - width) / 2,
89 (DC_NAME_TEX_LENGTH_T - DC_LETTER_TEX_LENGTH) / 2, width,
90 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, string_subtexture);
92 if (string_subtexture != null) {
93 delete [] string_subtexture;
94 string_subtexture = null;
97 width = String::stringWidth(MetaState::player_name, DC_NAME_TEX_LENGTH_S);
99 string_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
100 String::fillStringTexture(MetaState::player_name, string_subtexture, width);
102 if (width >= 2 * DC_NAME_TEX_LENGTH_S / 3)
103 x = 0;
104 else
105 x = ((2 * DC_NAME_TEX_LENGTH_S / 3) - width) / 2;
106 glTexSubImage2D(GL_TEXTURE_2D, 0, x, 0, width,
107 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, string_subtexture);
109 if (string_subtexture != null) {
110 delete [] string_subtexture;
111 string_subtexture = null;
114 width = String::stringWidth(Communicator::opponent_name,
115 DC_NAME_TEX_LENGTH_S);
117 string_subtexture = new GLubyte[DC_LETTER_TEX_LENGTH * width * 4];
118 String::fillStringTexture(Communicator::opponent_name, string_subtexture,
119 width);
121 if (width >= 2 * DC_NAME_TEX_LENGTH_S / 3)
122 x = DC_NAME_TEX_LENGTH_S - width;
123 else
124 x = DC_NAME_TEX_LENGTH_S - width
125 - ((2 * DC_NAME_TEX_LENGTH_S / 3) - width) / 2;
126 glTexSubImage2D(GL_TEXTURE_2D, 0, x,
127 DC_NAME_TEX_LENGTH_T - DC_LETTER_TEX_LENGTH, width,
128 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE, string_subtexture);
130 if (string_subtexture != null) {
131 delete [] string_subtexture;
132 string_subtexture = null;