3 * Daniel Nelson - 9/14/0
5 * Copyright (C) 2000 Daniel Nelson
6 * Copyright (C) 2004 Andrew Sayman
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Daniel Nelson - aluminumangel.org
26 * Generates the display list and textures for the reward signs.
33 #include "TextureLoader.h"
35 #include "Displayer.h"
37 GLuint
Displayer::sign_small_list
;
38 GLuint
Displayer::sign_large_list
;
39 GLuint
Displayer::sign_small_texture
;
40 GLuint
Displayer::sign_large_texture
;
42 const char *sign_small_subtexture_files
[DC_NUMBER_SMALL_SIGN_SUBTEXTURES
]
43 = { GC_DATA_DIRECTORY("sign_4.tga"),
44 GC_DATA_DIRECTORY("sign_5.tga"),
45 GC_DATA_DIRECTORY("sign_6.tga"),
46 GC_DATA_DIRECTORY("sign_7.tga"),
47 GC_DATA_DIRECTORY("sign_8.tga"),
48 GC_DATA_DIRECTORY("sign_9.tga") };
50 const char *sign_large_subtexture_files
[DC_NUMBER_LARGE_SIGN_SUBTEXTURES
]
51 = { GC_DATA_DIRECTORY("sign_10.tga"),
52 GC_DATA_DIRECTORY("sign_11.tga"),
53 GC_DATA_DIRECTORY("sign_12.tga"),
54 GC_DATA_DIRECTORY("sign_x2.tga"),
55 GC_DATA_DIRECTORY("sign_x3.tga"),
56 GC_DATA_DIRECTORY("sign_x4.tga"),
57 GC_DATA_DIRECTORY("sign_x5.tga"),
58 GC_DATA_DIRECTORY("sign_x6.tga"),
59 GC_DATA_DIRECTORY("sign_x7.tga"),
60 GC_DATA_DIRECTORY("sign_x8.tga"),
61 GC_DATA_DIRECTORY("sign_x9.tga"),
62 GC_DATA_DIRECTORY("sign_x10.tga"),
63 GC_DATA_DIRECTORY("sign_x11.tga"),
64 GC_DATA_DIRECTORY("sign_x12.tga"),
65 GC_DATA_DIRECTORY("sign_bonus.tga") };
67 void Displayer::generateSignList ( )
69 GLubyte
*subtextures
[std::max(
70 DC_NUMBER_SMALL_SIGN_SUBTEXTURES
,
71 DC_NUMBER_LARGE_SIGN_SUBTEXTURES
)];
73 // load and pack the small sign textures
75 glGenTextures(1, &sign_small_texture
);
77 glBindTexture(GL_TEXTURE_2D
, sign_small_texture
);
79 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
80 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
81 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
82 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
84 for (int n
= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
; n
--; )
85 subtextures
[n
] = TextureLoader::loadAlphaTGA(sign_small_subtexture_files
[n
],
86 DC_SIGN_SMALL_SUBTEX_LENGTH_S
, DC_SIGN_SMALL_SUBTEX_LENGTH_T
);
88 GLubyte small_texture
[DC_SIGN_SMALL_TEX_LENGTH_S
][DC_SIGN_SMALL_TEX_LENGTH_T
];
90 for (int s
= 0; s
< DC_SIGN_SMALL_TEX_LENGTH_S
; s
++)
91 for (int t
= 0; t
< DC_SIGN_SMALL_TEX_LENGTH_T
; t
++) {
92 unsigned n
= (s
/ DC_SIGN_SMALL_SUBTEX_LENGTH_S
)
93 * DC_SIGN_SMALL_TEX_GRID_LENGTH_T
+ t
/ DC_SIGN_SMALL_SUBTEX_LENGTH_T
;
95 if (n
>= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
)
96 small_texture
[s
][t
] = 0;
98 small_texture
[s
][t
] = subtextures
[n
][s
% DC_SIGN_SMALL_SUBTEX_LENGTH_S
99 * DC_SIGN_SMALL_SUBTEX_LENGTH_T
+ t
% DC_SIGN_SMALL_SUBTEX_LENGTH_T
];
102 glTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, DC_SIGN_SMALL_TEX_LENGTH_T
,
103 DC_SIGN_SMALL_TEX_LENGTH_S
, GL_FALSE
, GL_ALPHA
, GL_UNSIGNED_BYTE
,
106 for (int n
= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
; n
--; )
107 if (subtextures
[n
] != null
) {
108 delete [] subtextures
[n
];
109 subtextures
[n
] = null
;
112 // load and pack the large sign textures
114 glGenTextures(1, &sign_large_texture
);
116 glBindTexture(GL_TEXTURE_2D
, sign_large_texture
);
118 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
119 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
120 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
121 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
123 for (int n
= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
; n
--; )
124 subtextures
[n
] = TextureLoader::loadAlphaTGA(sign_large_subtexture_files
[n
],
125 DC_SIGN_LARGE_SUBTEX_LENGTH_S
, DC_SIGN_LARGE_SUBTEX_LENGTH_T
);
127 GLubyte large_texture
[DC_SIGN_LARGE_TEX_LENGTH_S
][DC_SIGN_LARGE_TEX_LENGTH_T
];
129 for (int s
= 0; s
< DC_SIGN_LARGE_TEX_LENGTH_S
; s
++)
130 for (int t
= 0; t
< DC_SIGN_LARGE_TEX_LENGTH_T
; t
++) {
131 unsigned n
= (s
/ DC_SIGN_LARGE_SUBTEX_LENGTH_S
)
132 * DC_SIGN_LARGE_TEX_GRID_LENGTH_T
+ t
/ DC_SIGN_LARGE_SUBTEX_LENGTH_T
;
134 if (n
>= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
)
135 large_texture
[s
][t
] = 0;
137 large_texture
[s
][t
] = subtextures
[n
][s
% DC_SIGN_LARGE_SUBTEX_LENGTH_S
138 * DC_SIGN_LARGE_SUBTEX_LENGTH_T
+ t
% DC_SIGN_LARGE_SUBTEX_LENGTH_T
];
141 glTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, DC_SIGN_LARGE_TEX_LENGTH_T
,
142 DC_SIGN_LARGE_TEX_LENGTH_S
, GL_FALSE
, GL_ALPHA
, GL_UNSIGNED_BYTE
,
145 for (int n
= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
; n
--; )
146 if (subtextures
[n
] != null
) {
147 delete [] subtextures
[n
];
148 subtextures
[n
] = null
;
151 // build the sign display lists
153 sign_small_list
= glGenLists(1);
155 glNewList(sign_small_list
, GL_COMPILE
);
156 glBegin(GL_TRIANGLE_STRIP
);
158 glTexCoord2f(0.0f
, DC_SIGN_SMALL_SUBTEX_COORD_S
);
159 glVertex3f(-DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
160 glTexCoord2f(DC_SIGN_SMALL_SUBTEX_COORD_T
, DC_SIGN_SMALL_SUBTEX_COORD_S
);
161 glVertex3f(DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
162 glTexCoord2f(0.0f
, 0.0f
);
163 glVertex3f(-DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
164 glTexCoord2f(DC_SIGN_SMALL_SUBTEX_COORD_T
, 0.0f
);
165 glVertex3f(DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
170 sign_large_list
= glGenLists(1);
172 glNewList(sign_large_list
, GL_COMPILE
);
173 glBegin(GL_TRIANGLE_STRIP
);
175 glTexCoord2f(0.0f
, DC_SIGN_LARGE_SUBTEX_COORD_S
);
176 glVertex3f(-2.0f
* DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
177 glTexCoord2f(DC_SIGN_LARGE_SUBTEX_COORD_T
, DC_SIGN_LARGE_SUBTEX_COORD_S
);
178 glVertex3f(2.0f
* DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
179 glTexCoord2f(0.0f
, 0.0f
);
180 glVertex3f(-2.0f
* DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
181 glTexCoord2f(DC_SIGN_LARGE_SUBTEX_COORD_T
, 0.0f
);
182 glVertex3f(2.0f
* DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);