3 * Daniel Nelson - 11/9/0
5 * Copyright (C) 2000 Daniel Nelson
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
25 * Build the name texture.
38 #include "Displayer.h"
40 #include "MetaState.h"
41 #include "Communicator.h"
43 GLuint
Displayer::name_texture
;
45 void Displayer::generateNameTexture ( )
47 glGenTextures(1, &name_texture
);
49 glBindTexture(GL_TEXTURE_2D
, name_texture
);
51 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
52 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
53 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
54 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
56 GLubyte texture
[DC_NAME_TEX_LENGTH_T
][DC_NAME_TEX_LENGTH_S
][3];
57 for (int t
= DC_NAME_TEX_LENGTH_T
; t
--; )
58 for (int s
= DC_NAME_TEX_LENGTH_S
; s
--; )
59 texture
[t
][s
][0] = texture
[t
][s
][1] = texture
[t
][s
][2] = 0;
61 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, DC_NAME_TEX_LENGTH_S
,
62 DC_NAME_TEX_LENGTH_T
, GL_FALSE
, GL_RGB
, GL_UNSIGNED_BYTE
, texture
);
64 if (MetaState::mode
& CM_SOLO
) {
66 int width
= String::stringWidth(MetaState::player_name
,
67 DC_NAME_TEX_LENGTH_S
);
69 GLubyte
*name_subtexture
= new GLubyte
[DC_LETTER_TEX_LENGTH
* width
* 4];
70 String::fillStringTexture(MetaState::player_name
, name_subtexture
, width
);
72 glTexSubImage2D(GL_TEXTURE_2D
, 0, (DC_NAME_TEX_LENGTH_S
- width
) / 2,
73 (DC_NAME_TEX_LENGTH_T
- DC_LETTER_TEX_LENGTH
) / 2, width
,
74 DC_LETTER_TEX_LENGTH
, GL_RGBA
, GL_UNSIGNED_BYTE
, name_subtexture
);
76 if (name_subtexture
!= null
) {
77 delete [] name_subtexture
;
78 name_subtexture
= null
;
84 GLubyte
*string_subtexture
;
86 width
= String::stringWidth(DC_VS_STRING
, DC_NAME_TEX_LENGTH_S
);
88 string_subtexture
= new GLubyte
[DC_LETTER_TEX_LENGTH
* width
* 4];
89 String::fillStringTexture(DC_VS_STRING
, string_subtexture
, width
);
91 glTexSubImage2D(GL_TEXTURE_2D
, 0, (DC_NAME_TEX_LENGTH_S
- width
) / 2,
92 (DC_NAME_TEX_LENGTH_T
- DC_LETTER_TEX_LENGTH
) / 2, width
,
93 DC_LETTER_TEX_LENGTH
, GL_RGBA
, GL_UNSIGNED_BYTE
, string_subtexture
);
95 if (string_subtexture
!= null
) {
96 delete [] string_subtexture
;
97 string_subtexture
= null
;
100 width
= String::stringWidth(MetaState::player_name
, DC_NAME_TEX_LENGTH_S
);
102 string_subtexture
= new GLubyte
[DC_LETTER_TEX_LENGTH
* width
* 4];
103 String::fillStringTexture(MetaState::player_name
, string_subtexture
, width
);
105 if (width
>= 2 * DC_NAME_TEX_LENGTH_S
/ 3)
108 x
= ((2 * DC_NAME_TEX_LENGTH_S
/ 3) - width
) / 2;
109 glTexSubImage2D(GL_TEXTURE_2D
, 0, x
, 0, width
,
110 DC_LETTER_TEX_LENGTH
, GL_RGBA
, GL_UNSIGNED_BYTE
, string_subtexture
);
112 if (string_subtexture
!= null
) {
113 delete [] string_subtexture
;
114 string_subtexture
= null
;
117 width
= String::stringWidth(Communicator::opponent_name
,
118 DC_NAME_TEX_LENGTH_S
);
120 string_subtexture
= new GLubyte
[DC_LETTER_TEX_LENGTH
* width
* 4];
121 String::fillStringTexture(Communicator::opponent_name
, string_subtexture
,
124 if (width
>= 2 * DC_NAME_TEX_LENGTH_S
/ 3)
125 x
= DC_NAME_TEX_LENGTH_S
- width
;
127 x
= DC_NAME_TEX_LENGTH_S
- width
128 - ((2 * DC_NAME_TEX_LENGTH_S
/ 3) - width
) / 2;
129 glTexSubImage2D(GL_TEXTURE_2D
, 0, x
,
130 DC_NAME_TEX_LENGTH_T
- DC_LETTER_TEX_LENGTH
, width
,
131 DC_LETTER_TEX_LENGTH
, GL_RGBA
, GL_UNSIGNED_BYTE
, string_subtexture
);
133 if (string_subtexture
!= null
) {
134 delete [] string_subtexture
;
135 string_subtexture
= null
;