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") };
69 #define MAX(a, b) ((a) > (b) ? (a) : (b))
72 void Displayer::generateSignList ( )
74 GLubyte
*subtextures
[MAX(
75 DC_NUMBER_SMALL_SIGN_SUBTEXTURES
,
76 DC_NUMBER_LARGE_SIGN_SUBTEXTURES
)];
78 // load and pack the small sign textures
80 glGenTextures(1, &sign_small_texture
);
82 glBindTexture(GL_TEXTURE_2D
, sign_small_texture
);
84 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
85 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
86 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
87 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
89 for (int n
= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
; n
--; )
90 subtextures
[n
] = TextureLoader::loadImageAlpha(sign_small_subtexture_files
[n
],
91 DC_SIGN_SMALL_SUBTEX_LENGTH_S
, DC_SIGN_SMALL_SUBTEX_LENGTH_T
);
93 GLubyte small_texture
[DC_SIGN_SMALL_TEX_LENGTH_S
][DC_SIGN_SMALL_TEX_LENGTH_T
];
95 for (int s
= 0; s
< DC_SIGN_SMALL_TEX_LENGTH_S
; s
++)
96 for (int t
= 0; t
< DC_SIGN_SMALL_TEX_LENGTH_T
; t
++) {
97 unsigned n
= (s
/ DC_SIGN_SMALL_SUBTEX_LENGTH_S
)
98 * DC_SIGN_SMALL_TEX_GRID_LENGTH_T
+ t
/ DC_SIGN_SMALL_SUBTEX_LENGTH_T
;
100 if (n
>= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
)
101 small_texture
[s
][t
] = 0;
103 small_texture
[s
][t
] = subtextures
[n
][s
% DC_SIGN_SMALL_SUBTEX_LENGTH_S
104 * DC_SIGN_SMALL_SUBTEX_LENGTH_T
+ t
% DC_SIGN_SMALL_SUBTEX_LENGTH_T
];
107 glTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, DC_SIGN_SMALL_TEX_LENGTH_T
,
108 DC_SIGN_SMALL_TEX_LENGTH_S
, GL_FALSE
, GL_ALPHA
, GL_UNSIGNED_BYTE
,
111 for (int n
= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
; n
--; )
112 if (subtextures
[n
] != null
) {
113 delete [] subtextures
[n
];
114 subtextures
[n
] = null
;
117 // load and pack the large sign textures
119 glGenTextures(1, &sign_large_texture
);
121 glBindTexture(GL_TEXTURE_2D
, sign_large_texture
);
123 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
124 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
125 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
126 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
128 for (int n
= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
; n
--; )
129 subtextures
[n
] = TextureLoader::loadImageAlpha(sign_large_subtexture_files
[n
],
130 DC_SIGN_LARGE_SUBTEX_LENGTH_S
, DC_SIGN_LARGE_SUBTEX_LENGTH_T
);
132 GLubyte large_texture
[DC_SIGN_LARGE_TEX_LENGTH_S
][DC_SIGN_LARGE_TEX_LENGTH_T
];
134 for (int s
= 0; s
< DC_SIGN_LARGE_TEX_LENGTH_S
; s
++)
135 for (int t
= 0; t
< DC_SIGN_LARGE_TEX_LENGTH_T
; t
++) {
136 unsigned n
= (s
/ DC_SIGN_LARGE_SUBTEX_LENGTH_S
)
137 * DC_SIGN_LARGE_TEX_GRID_LENGTH_T
+ t
/ DC_SIGN_LARGE_SUBTEX_LENGTH_T
;
139 if (n
>= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
)
140 large_texture
[s
][t
] = 0;
142 large_texture
[s
][t
] = subtextures
[n
][s
% DC_SIGN_LARGE_SUBTEX_LENGTH_S
143 * DC_SIGN_LARGE_SUBTEX_LENGTH_T
+ t
% DC_SIGN_LARGE_SUBTEX_LENGTH_T
];
146 glTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, DC_SIGN_LARGE_TEX_LENGTH_T
,
147 DC_SIGN_LARGE_TEX_LENGTH_S
, GL_FALSE
, GL_ALPHA
, GL_UNSIGNED_BYTE
,
150 for (int n
= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
; n
--; )
151 if (subtextures
[n
] != null
) {
152 delete [] subtextures
[n
];
153 subtextures
[n
] = null
;
156 // build the sign display lists
158 sign_small_list
= glGenLists(1);
160 glNewList(sign_small_list
, GL_COMPILE
);
161 glBegin(GL_TRIANGLE_STRIP
);
163 glTexCoord2f(0.0f
, DC_SIGN_SMALL_SUBTEX_COORD_S
);
164 glVertex3f(-DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
165 glTexCoord2f(DC_SIGN_SMALL_SUBTEX_COORD_T
, DC_SIGN_SMALL_SUBTEX_COORD_S
);
166 glVertex3f(DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
167 glTexCoord2f(0.0f
, 0.0f
);
168 glVertex3f(-DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
169 glTexCoord2f(DC_SIGN_SMALL_SUBTEX_COORD_T
, 0.0f
);
170 glVertex3f(DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
175 sign_large_list
= glGenLists(1);
177 glNewList(sign_large_list
, GL_COMPILE
);
178 glBegin(GL_TRIANGLE_STRIP
);
180 glTexCoord2f(0.0f
, DC_SIGN_LARGE_SUBTEX_COORD_S
);
181 glVertex3f(-2.0f
* DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
182 glTexCoord2f(DC_SIGN_LARGE_SUBTEX_COORD_T
, DC_SIGN_LARGE_SUBTEX_COORD_S
);
183 glVertex3f(2.0f
* DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
184 glTexCoord2f(0.0f
, 0.0f
);
185 glVertex3f(-2.0f
* DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
186 glTexCoord2f(DC_SIGN_LARGE_SUBTEX_COORD_T
, 0.0f
);
187 glVertex3f(2.0f
* DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);