1
// rendertext.cpp: based on Don's gl_text.cpp
6
short char_coords[94][3] =
67
{ 388, 284, 21 }, //"\"
71
{ 203, 213, 18 }, //` //TODO
100
{ 389, 426, 23 }, //} // coords
101
{ 419, 426, 34 }, //~ // coords
104
void gettextres(int &w, int &h)
106
if(w < MINRESW || h < MINRESH)
108
if(MINRESW > w*MINRESH/h)
121
#define PIXELTAB (FONTH*4)
123
int char_width(int c, int x)
125
if(c=='\t') x = (x+PIXELTAB)/PIXELTAB*PIXELTAB;
126
else if(c==' ') x += FONTH/2;
127
else if(c>=33 && c<=126)
130
int in_width = char_coords[c][2];
136
int text_width(const char *str, int limit)
139
for(int i = 0; str[i] && (limit<0 ||i<limit); i++)
146
x = char_width(str[i], x);
151
int text_visible(const char *str, int max)
161
x = char_width(str[i], x);
162
if(x > max) return i;
168
void draw_textf(const char *fstr, int left, int top, ...)
170
s_sprintfdlv(str, top, fstr);
171
draw_text(str, left, top);
174
void draw_text(const char *str, int left, int top, int r, int g, int b, int a)
176
static Texture *charstex = NULL;
177
if(!charstex) charstex = textureload("data/newerchars.png");
179
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
180
glBindTexture(GL_TEXTURE_2D, charstex->gl);
181
glColor4ub(r, g, b, a);
182
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
188
float in_left, in_top, in_right, in_bottom;
189
int in_width, in_height;
192
for (i = 0; str[i] != 0; i++)
195
if(c=='\t') { x = (x-left+PIXELTAB)/PIXELTAB*PIXELTAB+left; continue; };
196
if(c=='\f') switch(str[i+1])
198
case '0': glColor3ub(64,255,128); i++; continue; // green: player talk
199
case '1': glColor3ub(96,160,255); i++; continue; // blue: "echo" command
200
case '2': glColor3ub(255,192,64); i++; continue; // yellow: gameplay messages
201
case '3': glColor3ub(255,64,64); i++; continue; // red: important errors
202
default: continue; // white: everything else
204
if(c==' ') { x += FONTH/2; continue; };
206
if(c<0 || c>=95) continue;
208
in_width = char_coords[c][2];
210
in_left = ((float) char_coords[c][0]+2-2) / 512.0f;
211
in_top = ((float) char_coords[c][1]+2-3) / 512.0f;
212
in_right = ((float) char_coords[c][0]+2+3+in_width) / 512.0f;
213
in_bottom = ((float) char_coords[c][1]+2+4+in_height) / 512.0f;
216
glTexCoord2f(in_left, in_top ); glVertex2i(x, y);
217
glTexCoord2f(in_right, in_top ); glVertex2i(x + in_width, y);
218
glTexCoord2f(in_right, in_bottom); glVertex2i(x + in_width, y + in_height);
219
glTexCoord2f(in_left, in_bottom); glVertex2i(x, y + in_height);
227
Texture *sky[6] = { 0, 0, 0, 0, 0, 0 };
229
void loadsky(char *basename)
231
static string lastsky = "";
232
if(strcmp(lastsky, basename)==0) return;
233
static char *side[] = { "ft", "bk", "lf", "rt", "dn", "up" };
236
s_sprintfd(name)("packages/%s_%s.jpg", basename, side[i]);
237
if((sky[i] = textureload(name, true))==crosshair) conoutf("could not load sky textures");
238
// FIXME? now doesn't overwrite old sky any more which uses more memory, but gives faster loadtimes...
240
s_strcpy(lastsky, basename);
243
COMMAND(loadsky, "s");
245
void draw_envbox_face(float s0, float t0, int x0, int y0, int z0,
246
float s1, float t1, int x1, int y1, int z1,
247
float s2, float t2, int x2, int y2, int z2,
248
float s3, float t3, int x3, int y3, int z3,
251
glBindTexture(GL_TEXTURE_2D, texture);
253
glTexCoord2f(s3, t3); glVertex3i(x3, y3, z3);
254
glTexCoord2f(s2, t2); glVertex3i(x2, y2, z2);
255
glTexCoord2f(s1, t1); glVertex3i(x1, y1, z1);
256
glTexCoord2f(s0, t0); glVertex3i(x0, y0, z0);
261
void draw_envbox(int w, float zclip)
263
if(!sky[0]) fatal("no skybox");
265
float vclip = 1-zclip;
266
int z = int(ceil(2*w*(vclip-0.5f)));
268
glDepthMask(GL_FALSE);
270
draw_envbox_face(1.0f, vclip, -w, -w, z,
271
0.0f, vclip, w, -w, z,
272
0.0f, 0.0f, w, -w, -w,
273
1.0f, 0.0f, -w, -w, -w, sky[0]->gl);
275
draw_envbox_face(1.0f, vclip, +w, w, z,
276
0.0f, vclip, -w, w, z,
277
0.0f, 0.0f, -w, w, -w,
278
1.0f, 0.0f, +w, w, -w, sky[1]->gl);
280
draw_envbox_face(0.0f, 0.0f, -w, -w, -w,
281
1.0f, 0.0f, -w, w, -w,
282
1.0f, vclip, -w, w, z,
283
0.0f, vclip, -w, -w, z, sky[2]->gl);
285
draw_envbox_face(1.0f, vclip, +w, -w, z,
286
0.0f, vclip, +w, w, z,
287
0.0f, 0.0f, +w, w, -w,
288
1.0f, 0.0f, +w, -w, -w, sky[3]->gl);
291
draw_envbox_face(0.0f, 1.0f, -w, w, w,
292
0.0f, 0.0f, +w, w, w,
293
1.0f, 0.0f, +w, -w, w,
294
1.0f, 1.0f, -w, -w, w, sky[4]->gl);
296
draw_envbox_face(0.0f, 1.0f, +w, w, -w,
297
0.0f, 0.0f, -w, w, -w,
298
1.0f, 0.0f, -w, -w, -w,
299
1.0f, 1.0f, +w, -w, -w, sky[5]->gl);
301
glDepthMask(GL_TRUE);