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.
38 #include "TextureLoader.h"
40 #include "Displayer.h"
42 GLuint
Displayer::sign_small_list
;
43 GLuint
Displayer::sign_large_list
;
44 GLuint
Displayer::sign_small_texture
;
45 GLuint
Displayer::sign_large_texture
;
47 const char *sign_small_subtexture_files
[DC_NUMBER_SMALL_SIGN_SUBTEXTURES
]
48 = { GC_DATA_DIRECTORY("sign_4.tga"),
49 GC_DATA_DIRECTORY("sign_5.tga"),
50 GC_DATA_DIRECTORY("sign_6.tga"),
51 GC_DATA_DIRECTORY("sign_7.tga"),
52 GC_DATA_DIRECTORY("sign_8.tga"),
53 GC_DATA_DIRECTORY("sign_9.tga") };
55 const char *sign_large_subtexture_files
[DC_NUMBER_LARGE_SIGN_SUBTEXTURES
]
56 = { GC_DATA_DIRECTORY("sign_10.tga"),
57 GC_DATA_DIRECTORY("sign_11.tga"),
58 GC_DATA_DIRECTORY("sign_12.tga"),
59 GC_DATA_DIRECTORY("sign_x2.tga"),
60 GC_DATA_DIRECTORY("sign_x3.tga"),
61 GC_DATA_DIRECTORY("sign_x4.tga"),
62 GC_DATA_DIRECTORY("sign_x5.tga"),
63 GC_DATA_DIRECTORY("sign_x6.tga"),
64 GC_DATA_DIRECTORY("sign_x7.tga"),
65 GC_DATA_DIRECTORY("sign_x8.tga"),
66 GC_DATA_DIRECTORY("sign_x9.tga"),
67 GC_DATA_DIRECTORY("sign_x10.tga"),
68 GC_DATA_DIRECTORY("sign_x11.tga"),
69 GC_DATA_DIRECTORY("sign_x12.tga"),
70 GC_DATA_DIRECTORY("sign_bonus.tga") };
72 void Displayer::generateSignList ( )
75 [max(DC_NUMBER_SMALL_SIGN_SUBTEXTURES
, DC_NUMBER_LARGE_SIGN_SUBTEXTURES
)];
77 // load and pack the small sign textures
79 glGenTextures(1, &sign_small_texture
);
81 glBindTexture(GL_TEXTURE_2D
, sign_small_texture
);
83 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
84 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
85 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
86 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
88 for (int n
= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
; n
--; )
89 subtextures
[n
] = TextureLoader::loadAlphaTGA(sign_small_subtexture_files
[n
],
90 DC_SIGN_SMALL_SUBTEX_LENGTH_S
, DC_SIGN_SMALL_SUBTEX_LENGTH_T
);
92 GLubyte small_texture
[DC_SIGN_SMALL_TEX_LENGTH_S
][DC_SIGN_SMALL_TEX_LENGTH_T
];
94 for (int s
= 0; s
< DC_SIGN_SMALL_TEX_LENGTH_S
; s
++)
95 for (int t
= 0; t
< DC_SIGN_SMALL_TEX_LENGTH_T
; t
++) {
96 unsigned n
= (s
/ DC_SIGN_SMALL_SUBTEX_LENGTH_S
)
97 * DC_SIGN_SMALL_TEX_GRID_LENGTH_T
+ t
/ DC_SIGN_SMALL_SUBTEX_LENGTH_T
;
99 if (n
>= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
)
100 small_texture
[s
][t
] = 0;
102 small_texture
[s
][t
] = subtextures
[n
][s
% DC_SIGN_SMALL_SUBTEX_LENGTH_S
103 * DC_SIGN_SMALL_SUBTEX_LENGTH_T
+ t
% DC_SIGN_SMALL_SUBTEX_LENGTH_T
];
106 glTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, DC_SIGN_SMALL_TEX_LENGTH_T
,
107 DC_SIGN_SMALL_TEX_LENGTH_S
, GL_FALSE
, GL_ALPHA
, GL_UNSIGNED_BYTE
,
110 for (int n
= DC_NUMBER_SMALL_SIGN_SUBTEXTURES
; n
--; )
111 if (subtextures
[n
] != null
) {
112 delete [] subtextures
[n
];
113 subtextures
[n
] = null
;
116 // load and pack the large sign textures
118 glGenTextures(1, &sign_large_texture
);
120 glBindTexture(GL_TEXTURE_2D
, sign_large_texture
);
122 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
123 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
124 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
125 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
127 for (int n
= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
; n
--; )
128 subtextures
[n
] = TextureLoader::loadAlphaTGA(sign_large_subtexture_files
[n
],
129 DC_SIGN_LARGE_SUBTEX_LENGTH_S
, DC_SIGN_LARGE_SUBTEX_LENGTH_T
);
131 GLubyte large_texture
[DC_SIGN_LARGE_TEX_LENGTH_S
][DC_SIGN_LARGE_TEX_LENGTH_T
];
133 for (int s
= 0; s
< DC_SIGN_LARGE_TEX_LENGTH_S
; s
++)
134 for (int t
= 0; t
< DC_SIGN_LARGE_TEX_LENGTH_T
; t
++) {
135 unsigned n
= (s
/ DC_SIGN_LARGE_SUBTEX_LENGTH_S
)
136 * DC_SIGN_LARGE_TEX_GRID_LENGTH_T
+ t
/ DC_SIGN_LARGE_SUBTEX_LENGTH_T
;
138 if (n
>= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
)
139 large_texture
[s
][t
] = 0;
141 large_texture
[s
][t
] = subtextures
[n
][s
% DC_SIGN_LARGE_SUBTEX_LENGTH_S
142 * DC_SIGN_LARGE_SUBTEX_LENGTH_T
+ t
% DC_SIGN_LARGE_SUBTEX_LENGTH_T
];
145 glTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, DC_SIGN_LARGE_TEX_LENGTH_T
,
146 DC_SIGN_LARGE_TEX_LENGTH_S
, GL_FALSE
, GL_ALPHA
, GL_UNSIGNED_BYTE
,
149 for (int n
= DC_NUMBER_LARGE_SIGN_SUBTEXTURES
; n
--; )
150 if (subtextures
[n
] != null
) {
151 delete [] subtextures
[n
];
152 subtextures
[n
] = null
;
155 // build the sign display lists
157 sign_small_list
= glGenLists(1);
159 glNewList(sign_small_list
, GL_COMPILE
);
160 glBegin(GL_TRIANGLE_STRIP
);
162 glTexCoord2f(0.0f
, DC_SIGN_SMALL_SUBTEX_COORD_S
);
163 glVertex3f(-DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
164 glTexCoord2f(DC_SIGN_SMALL_SUBTEX_COORD_T
, DC_SIGN_SMALL_SUBTEX_COORD_S
);
165 glVertex3f(DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
166 glTexCoord2f(0.0f
, 0.0f
);
167 glVertex3f(-DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
168 glTexCoord2f(DC_SIGN_SMALL_SUBTEX_COORD_T
, 0.0f
);
169 glVertex3f(DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
174 sign_large_list
= glGenLists(1);
176 glNewList(sign_large_list
, GL_COMPILE
);
177 glBegin(GL_TRIANGLE_STRIP
);
179 glTexCoord2f(0.0f
, DC_SIGN_LARGE_SUBTEX_COORD_S
);
180 glVertex3f(-2.0f
* DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
181 glTexCoord2f(DC_SIGN_LARGE_SUBTEX_COORD_T
, DC_SIGN_LARGE_SUBTEX_COORD_S
);
182 glVertex3f(2.0f
* DC_SIGN_LENGTH
, -DC_SIGN_LENGTH
, 0.0f
);
183 glTexCoord2f(0.0f
, 0.0f
);
184 glVertex3f(-2.0f
* DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);
185 glTexCoord2f(DC_SIGN_LARGE_SUBTEX_COORD_T
, 0.0f
);
186 glVertex3f(2.0f
* DC_SIGN_LENGTH
, DC_SIGN_LENGTH
, 0.0f
);