| | 1 | #include "system.h" |
| | 2 | #include "stratdef.h" |
| | 3 | #include "lighting.h" |
| | 4 | #include "bh_types.h" |
| | 5 | #include "hud.h" |
| | 6 | #include "userprofile.h" |
| | 7 | #include "kshape.h" |
| | 8 | #include "menus.h" |
| | 9 | #include <SDL/SDL_opengl.h> |
| | 10 | |
| | 11 | const int VDB_ClipZ = 64; |
| | 12 | extern void HandleRainShaft(MODULE *modulePtr, int bottomY, int topY, int numberOfRaindrops); |
| | 13 | extern int got_any_key(); |
| | 14 | |
| | 15 | extern unsigned char GammaValues[256]; |
| | 16 | extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock; |
| | 17 | extern DISPLAYBLOCK *ActiveBlockList[]; |
| | 18 | extern int HUDScaleFactor; |
| | 19 | extern int CloakingPhase; |
| | 20 | extern int NumActiveBlocks; |
| | 21 | extern int ChromeImageNumber; |
| | 22 | extern int WaterShaftImageNumber; |
| | 23 | |
| | 24 | static int StaticImageNumber; |
| | 25 | int SpecialFXImageNumber; |
| | 26 | int CloudyImageNumber; |
| | 27 | int HUDImageNumber; |
| | 28 | int AlienTongueImageNumber; |
| | 29 | int PredatorNumbersImageNumber; |
| | 30 | int BurningImageNumber; |
| | 31 | int HUDFontsImageNumber; |
| | 32 | |
| | 33 | int WaterFallBase; |
| | 34 | static int MeshXScale; |
| | 35 | static int MeshZScale; |
| | 36 | static int WaterXOrigin; |
| | 37 | static int WaterZOrigin; |
| | 38 | static float WaterUScale; |
| | 39 | static float WaterVScale; |
| | 40 | GLfloat ZNear; |
| | 41 | |
| | 42 | #define MaxImages 200 |
| | 43 | |
| | 44 | enum FILTERING_MODE_ID |
| | 45 | { |
| | 46 | FILTERING_BILINEAR_OFF, |
| | 47 | FILTERING_BILINEAR_ON, |
| | 48 | FILTERING_NOT_SET |
| | 49 | |
| | 50 | } CurrentFilteringMode = FILTERING_BILINEAR_OFF; |
| | 51 | |
| | 52 | struct TEXTURE |
| | 53 | { |
| | 54 | uint8_t *buf; |
| | 55 | GLuint id; |
| | 56 | uint32_t w; |
| | 57 | uint32_t h; |
| | 58 | enum FILTERING_MODE_ID filter; |
| | 59 | |
| | 60 | } *CurrTextureHandle, *CurrentlyBoundTexture; |
| | 61 | |
| | 62 | struct |
| | 63 | { |
| | 64 | struct TEXTURE *Texture; |
| | 65 | char * ImageName; |
| | 66 | |
| | 67 | } ImageHeaderArray[MaxImages]; |
| | 68 | |
| | 69 | static int AAFontImageNumber; |
| | 70 | char AAFontWidths[256]; |
| | 71 | |
| | 72 | int NumImages = -1; |
| | 73 | |
| | 74 | enum TRANSLUCENCY_TYPE CurrentTranslucencyMode = TRANSLUCENCY_OFF; |
| | 75 | |
| | 76 | #define TA_MAXVERTICES 2048 |
| | 77 | #define TA_MAXTRIANGLES 2048 |
| | 78 | |
| | 79 | struct VertexArray |
| | 80 | { |
| | 81 | GLfloat v[4]; |
| | 82 | GLfloat t[3]; /* 3rd float is padding */ |
| | 83 | GLubyte c[4]; |
| | 84 | |
| | 85 | } *varrp, *svarrp; |
| | 86 | |
| | 87 | struct TriangleArray |
| | 88 | { |
| | 89 | int a; |
| | 90 | int b; |
| | 91 | int c; |
| | 92 | |
| | 93 | } *tarrp, *starrp; |
| | 94 | |
| | 95 | struct VertexArray varr[TA_MAXVERTICES * 2]; |
| | 96 | |
| | 97 | struct TriangleArray tarr[TA_MAXTRIANGLES * 2]; |
| | 98 | |
| | 99 | int varrc, tarrc, svarrc, starrc; |
| | 100 | |
| | 101 | VECTORCH MeshVertex[256]; |
| | 102 | VECTORCH MeshWorldVertex[256]; |
| | 103 | unsigned int MeshVertexColour[256]; |
| | 104 | unsigned int MeshVertexSpecular[256]; |
| | 105 | char MeshVertexOutcode[256]; |
| | 106 | |
| | 107 | /* Do not call this directly! */ |
| | 108 | static void SetTranslucencyMode(enum TRANSLUCENCY_TYPE mode) |
| | 109 | { |
| | 110 | switch(mode) |
| | 111 | { |
| | 112 | case TRANSLUCENCY_OFF: |
| | 113 | switch(UserProfile.active_bonus) |
| | 114 | { |
| | 115 | case CHEATMODE_NONACTIVE: |
| | 116 | default: |
| | 117 | glBlendFunc(GL_ONE, GL_ZERO); |
| | 118 | break; |
| | 119 | case CHEATMODE_TRIPTASTIC: |
| | 120 | case CHEATMODE_MOTIONBLUR: |
| | 121 | glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); |
| | 122 | } |
| | 123 | break; |
| | 124 | case TRANSLUCENCY_NORMAL: |
| | 125 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| | 126 | break; |
| | 127 | case TRANSLUCENCY_COLOUR: |
| | 128 | glBlendFunc(GL_ZERO, GL_SRC_COLOR); |
| | 129 | break; |
| | 130 | case TRANSLUCENCY_INVCOLOUR: |
| | 131 | glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); |
| | 132 | break; |
| | 133 | case TRANSLUCENCY_GLOWING: |
| | 134 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
| | 135 | break; |
| | 136 | case TRANSLUCENCY_DARKENINGCOLOUR: |
| | 137 | glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); |
| | 138 | break; |
| | 139 | case TRANSLUCENCY_JUSTSETZ: |
| | 140 | glBlendFunc(GL_ZERO, GL_ONE); |
| | 141 | break; |
| | 142 | default: |
| | 143 | fprintf(stderr, "TranslucencyMode: invalid %d\n", mode); |
| | 144 | } |
| | 145 | } |
| | 146 | |
| | 147 | void ResetOpeGL() |
| | 148 | { |
| | 149 | glEnable(GL_DEPTH_TEST); |
| | 150 | glEnable(GL_TEXTURE_2D); |
| | 151 | glEnable(GL_BLEND); |
| | 152 | glDepthFunc(GL_LEQUAL); |
| | 153 | glBlendFunc(GL_ONE, GL_ZERO); |
| | 154 | |
| | 155 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| | 156 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| | 157 | CurrentTranslucencyMode = TRANSLUCENCY_OFF; |
| | 158 | CurrentFilteringMode = FILTERING_BILINEAR_OFF; |
| | 159 | CurrentlyBoundTexture = CurrTextureHandle = NULL; |
| | 160 | ZNear = (GLfloat) (VDB_ClipZ * GlobalScale) * 2.0f; |
| | 161 | |
| | 162 | tarrc = varrc = starrc = svarrc = 0; |
| | 163 | tarrp = tarr; |
| | 164 | varrp = varr; |
| | 165 | starrp = &tarr[TA_MAXTRIANGLES]; |
| | 166 | svarrp = &varr[TA_MAXVERTICES]; |
| | 167 | } |
| | 168 | |
| | 169 | /* |
| | 170 | A few things: |
| | 171 | - Vertices with a specular color are done twice. |
| | 172 | Might want to try spitting apart the three arrays and using the same vertex |
| | 173 | array for both passes. |
| | 174 | - Fix code for separate color support. |
| | 175 | */ |
| | 176 | |
| | 177 | void InitOpenGL() |
| | 178 | { |
| | 179 | glEnableClientState(GL_VERTEX_ARRAY); |
| | 180 | glVertexPointer(4, GL_FLOAT, sizeof(varr[0]), varr[0].v); |
| | 181 | |
| | 182 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| | 183 | glTexCoordPointer(2, GL_FLOAT, sizeof(varr[0]), varr[0].t); |
| | 184 | |
| | 185 | glEnableClientState(GL_COLOR_ARRAY); |
| | 186 | glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(varr[0]), varr[0].c); |
| | 187 | |
| | 188 | ResetOpeGL(); |
| | 189 | } |
| | 190 | |
| | 191 | static void FlushTriangleBuffers(int backup) |
| | 192 | { |
| | 193 | if (tarrc) |
| | 194 | { |
| | 195 | glDrawElements(GL_TRIANGLES, tarrc*3, GL_UNSIGNED_INT, tarr); |
| | 196 | tarrc = varrc = 0; |
| | 197 | tarrp = tarr; |
| | 198 | varrp = varr; |
| | 199 | //printf("FLUSHING BUFFER %d\n", tarrc); |
| | 200 | } |
| | 201 | |
| | 202 | if (starrc) |
| | 203 | { |
| | 204 | |
| | 205 | //printf("FLUSHING BUFFER %d\n", starrc); |
| | 206 | if (CurrentlyBoundTexture != NULL) |
| | 207 | { |
| | 208 | if (!backup) |
| | 209 | CurrentlyBoundTexture = NULL; |
| | 210 | |
| | 211 | glBindTexture(GL_TEXTURE_2D, 0); |
| | 212 | } |
| | 213 | |
| | 214 | if (CurrentTranslucencyMode != TRANSLUCENCY_GLOWING) |
| | 215 | { |
| | 216 | if (!backup) |
| | 217 | CurrentTranslucencyMode = TRANSLUCENCY_GLOWING; |
| | 218 | |
| | 219 | SetTranslucencyMode(TRANSLUCENCY_GLOWING); |
| | 220 | |
| | 221 | if (CurrentTranslucencyMode == TRANSLUCENCY_OFF) |
| | 222 | { |
| | 223 | glEnable(GL_BLEND); |
| | 224 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
| | 225 | } |
| | 226 | } |
| | 227 | |
| | 228 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| | 229 | glDrawElements(GL_TRIANGLES, starrc*3, GL_UNSIGNED_INT, &tarr[TA_MAXTRIANGLES]); |
| | 230 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| | 231 | |
| | 232 | if (backup) |
| | 233 | { |
| | 234 | if (CurrentlyBoundTexture) |
| | 235 | glBindTexture(GL_TEXTURE_2D, CurrentlyBoundTexture->id); |
| | 236 | |
| | 237 | if (CurrentTranslucencyMode != TRANSLUCENCY_GLOWING) |
| | 238 | SetTranslucencyMode(CurrentTranslucencyMode); |
| | 239 | } |
| | 240 | else |
| | 241 | { |
| | 242 | CurrentlyBoundTexture = NULL; |
| | 243 | CurrentTranslucencyMode = TRANSLUCENCY_GLOWING; |
| | 244 | } |
| | 245 | |
| | 246 | starrc = 0; |
| | 247 | starrp = &tarr[TA_MAXTRIANGLES]; |
| | 248 | |
| | 249 | svarrc = 0; |
| | 250 | svarrp = &varr[TA_MAXVERTICES]; |
| | 251 | } |
| | 252 | } |
| | 253 | |
| | 254 | static void CheckBoundTextureIsCorrect(struct TEXTURE *tex) |
| | 255 | { |
| | 256 | if (NULL == tex) |
| | 257 | { |
| | 258 | glDisable(GL_TEXTURE_2D); |
| | 259 | } |
| | 260 | else if (tex != CurrentlyBoundTexture) |
| | 261 | { |
| | 262 | FlushTriangleBuffers(1); |
| | 263 | |
| | 264 | glEnable(GL_TEXTURE_2D); |
| | 265 | glBindTexture(GL_TEXTURE_2D, tex->id); |
| | 266 | |
| | 267 | if (tex->filter != CurrentFilteringMode) |
| | 268 | { |
| | 269 | switch(CurrentFilteringMode) |
| | 270 | { |
| | 271 | case FILTERING_BILINEAR_OFF: |
| | 272 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| | 273 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| | 274 | break; |
| | 275 | case FILTERING_BILINEAR_ON: |
| | 276 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| | 277 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| | 278 | default: |
| | 279 | break; |
| | 280 | } |
| | 281 | |
| | 282 | tex->filter = CurrentFilteringMode; |
| | 283 | } |
| | 284 | } |
| | 285 | |
| | 286 | CurrentlyBoundTexture = tex; |
| | 287 | } |
| | 288 | |
| | 289 | static void CheckFilteringModeIsCorrect(enum FILTERING_MODE_ID filter) |
| | 290 | { |
| | 291 | CurrentFilteringMode = filter; |
| | 292 | |
| | 293 | if (CurrentlyBoundTexture && CurrentlyBoundTexture->filter != CurrentFilteringMode) |
| | 294 | { |
| | 295 | FlushTriangleBuffers(1); |
| | 296 | |
| | 297 | switch(CurrentFilteringMode) |
| | 298 | { |
| | 299 | case FILTERING_BILINEAR_OFF: |
| | 300 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| | 301 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| | 302 | break; |
| | 303 | case FILTERING_BILINEAR_ON: |
| | 304 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| | 305 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| | 306 | default: |
| | 307 | break; |
| | 308 | } |
| | 309 | |
| | 310 | CurrentlyBoundTexture->filter = CurrentFilteringMode; |
| | 311 | } |
| | 312 | } |
| | 313 | |
| | 314 | static void CheckTranslucencyModeIsCorrect(enum TRANSLUCENCY_TYPE mode) |
| | 315 | { |
| | 316 | if (CurrentTranslucencyMode != mode) |
| | 317 | { |
| | 318 | FlushTriangleBuffers(1); |
| | 319 | SetTranslucencyMode(mode); |
| | 320 | CurrentTranslucencyMode = mode; |
| | 321 | } |
| | 322 | } |
| | 323 | |
| | 324 | static void CheckTriangleBuffer(int rver, int sver, int rtri, struct TEXTURE *tex, enum TRANSLUCENCY_TYPE mode) |
| | 325 | { |
| | 326 | if ( |
| | 327 | ((rver + varrc) >= TA_MAXVERTICES) |
| | 328 | || |
| | 329 | ((sver + svarrc) >= TA_MAXVERTICES) |
| | 330 | || |
| | 331 | (!rtri && ((rver - 2 + tarrc) >= TA_MAXTRIANGLES)) |
| | 332 | || |
| | 333 | (rtri && ((rtri + tarrc) >= TA_MAXTRIANGLES)) |
| | 334 | || |
| | 335 | ((sver - 2 + starrc) >= TA_MAXTRIANGLES)) |
| | 336 | { |
| | 337 | FlushTriangleBuffers(0); |
| | 338 | } |
| | 339 | |
| | 340 | if (-1 != (intptr_t)tex) |
| | 341 | CheckBoundTextureIsCorrect(tex); |
| | 342 | |
| | 343 | if (TRANSLUCENCY_NOT_SET != mode) |
| | 344 | CheckTranslucencyModeIsCorrect(mode); |
| | 345 | |
| | 346 | #define OUTPUT_TRIANGLE(x, y, z) \ |
| | 347 | { \ |
| | 348 | tarrp->a = varrc + (x); \ |
| | 349 | tarrp->b = varrc + (y); \ |
| | 350 | tarrp->c = varrc + (z); \ |
| | 351 | \ |
| | 352 | tarrp++; \ |
| | 353 | tarrc++; \ |
| | 354 | } |
| | 355 | if (!rtri) |
| | 356 | { |
| | 357 | switch(rver) |
| | 358 | { |
| | 359 | case 0: |
| | 360 | break; |
| | 361 | case 3: |
| | 362 | OUTPUT_TRIANGLE(0, 2, 1); |
| | 363 | break; |
| | 364 | case 5: |
| | 365 | OUTPUT_TRIANGLE(0, 1, 4); |
| | 366 | OUTPUT_TRIANGLE(1, 3, 4); |
| | 367 | OUTPUT_TRIANGLE(1, 2, 3); |
| | 368 | break; |
| | 369 | case 8: |
| | 370 | OUTPUT_TRIANGLE(0, 6, 7); |
| | 371 | case 7: |
| | 372 | OUTPUT_TRIANGLE(0, 5, 6); |
| | 373 | case 6: |
| | 374 | OUTPUT_TRIANGLE(0, 4, 5); |
| | 375 | OUTPUT_TRIANGLE(0, 3, 4); |
| | 376 | case 4: |
| | 377 | OUTPUT_TRIANGLE(0, 2, 3); |
| | 378 | OUTPUT_TRIANGLE(0, 1, 2); |
| | 379 | break; |
| | 380 | default: |
| | 381 | fprintf(stderr, "DrawTriangles_T2F_C4UB_V4F: vertices = %d\n", rver); |
| | 382 | } |
| | 383 | } |
| | 384 | #undef OUTPUT_TRIANGLE |
| | 385 | |
| | 386 | #define OUTPUT_TRIANGLE(x, y, z) \ |
| | 387 | { \ |
| | 388 | starrp->a = TA_MAXVERTICES + svarrc + (x);\ |
| | 389 | starrp->b = TA_MAXVERTICES + svarrc + (y);\ |
| | 390 | starrp->c = TA_MAXVERTICES + svarrc + (z);\ |
| | 391 | \ |
| | 392 | starrp++; \ |
| | 393 | starrc++; \ |
| | 394 | } |
| | 395 | switch(sver) |
| | 396 | { |
| | 397 | case 0: |
| | 398 | break; |
| | 399 | case 3: |
| | 400 | OUTPUT_TRIANGLE(0, 2, 1); |
| | 401 | break; |
| | 402 | case 5: |
| | 403 | OUTPUT_TRIANGLE(0, 1, 4); |
| | 404 | OUTPUT_TRIANGLE(1, 3, 4); |
| | 405 | OUTPUT_TRIANGLE(1, 2, 3); |
| | 406 | break; |
| | 407 | case 8: |
| | 408 | OUTPUT_TRIANGLE(0, 6, 7); |
| | 409 | case 7: |
| | 410 | OUTPUT_TRIANGLE(0, 5, 6); |
| | 411 | case 6: |
| | 412 | OUTPUT_TRIANGLE(0, 4, 5); |
| | 413 | OUTPUT_TRIANGLE(0, 3, 4); |
| | 414 | case 4: |
| | 415 | OUTPUT_TRIANGLE(0, 2, 3); |
| | 416 | OUTPUT_TRIANGLE(0, 1, 2); |
| | 417 | break; |
| | 418 | default: |
| | 419 | fprintf(stderr, "DrawTriangles_T2F_C4UB_V4F: vertices = %d\n", sver); |
| | 420 | } |
| | 421 | #undef OUTPUT_TRIANGLE |
| | 422 | } |
| | 423 | |
| | 424 | static void CreateOGLTexture(struct TEXTURE *tex) |
| | 425 | { |
| | 426 | glGenTextures(1, &tex->id); |
| | 427 | glBindTexture(GL_TEXTURE_2D, tex->id); |
| | 428 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| | 429 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| | 430 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| | 431 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| | 432 | |
| | 433 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->w, tex->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex->buf); |
| | 434 | |
| | 435 | tex->filter = FILTERING_BILINEAR_ON; |
| | 436 | } |
| | 437 | |
| | 438 | void assign_textures() |
| | 439 | { |
| | 440 | int i = 2; |
| | 441 | |
| | 442 | for (; i <= NumImages; i++) |
| | 443 | { |
| | 444 | struct TEXTURE *tex = ImageHeaderArray[i].Texture; |
| | 445 | |
| | 446 | if (NULL != tex->buf) |
| | 447 | { |
| | 448 | CreateOGLTexture(tex); |
| | 449 | free(tex->buf); |
| | 450 | tex->buf = NULL; |
| | 451 | } |
| | 452 | } |
| | 453 | } |
| | 454 | |
| | 455 | void ThisFramesRenderingHasBegun() |
| | 456 | { |
| | 457 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_ON); |
| | 458 | } |
| | 459 | |
| | 460 | void ThisFramesRenderingHasFinished() |
| | 461 | { |
| | 462 | FlushTriangleBuffers(0); |
| | 463 | } |
| | 464 | |
| | 465 | void DecalSystem_Setup() |
| | 466 | { |
| | 467 | FlushTriangleBuffers(0); |
| | 468 | |
| | 469 | glDepthMask(GL_FALSE); |
| | 470 | |
| | 471 | /* this does stop zfighting with bulletmarks on walls... */ |
| | 472 | glEnable(GL_POLYGON_OFFSET_FILL); |
| | 473 | glPolygonOffset(-8.0, -8.0); |
| | 474 | } |
| | 475 | |
| | 476 | void DecalSystem_End() |
| | 477 | { |
| | 478 | FlushTriangleBuffers(0); |
| | 479 | |
| | 480 | glDepthMask(GL_TRUE); |
| | 481 | |
| | 482 | glDisable(GL_POLYGON_OFFSET_FILL); |
| | 483 | } |
| | 484 | |
| | 485 | void Rectangle(int x0, int y0, int x1, int y1, int r, int g, int b, int a) |
| | 486 | { |
| | 487 | if (y1 > y0) |
| | 488 | { |
| | 489 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_GLOWING); |
| | 490 | CheckBoundTextureIsCorrect(NULL); |
| | 491 | glColor4ub(r, g, b, a); |
| | 492 | |
| | 493 | GLfloat x_0 = (float)(x0 - ScreenDescriptorBlock.SDB_CentreX) / ScreenDescriptorBlock.SDB_CentreX; |
| | 494 | GLfloat x_1 = (float)((x1 - 1) - ScreenDescriptorBlock.SDB_CentreX) / ScreenDescriptorBlock.SDB_CentreX; |
| | 495 | GLfloat y_0 = -(float)(y0 - ScreenDescriptorBlock.SDB_CentreY) / ScreenDescriptorBlock.SDB_CentreY; |
| | 496 | GLfloat y_1 = -(float)((y1 - 1) - ScreenDescriptorBlock.SDB_CentreY) / ScreenDescriptorBlock.SDB_CentreY; |
| | 497 | |
| | 498 | glDisable(GL_DEPTH_TEST); |
| | 499 | glRectf(x_0, y_0, x_1, y_1); |
| | 500 | glEnable(GL_DEPTH_TEST); |
| | 501 | } |
| | 502 | } |
| | 503 | |
| | 504 | void TexturedPolygon(int texture, RENDERVERTEX *vertices, enum TRANSLUCENCY_TYPE TranslucencyMode) |
| | 505 | { |
| | 506 | float RecipW, RecipH; |
| | 507 | CurrTextureHandle = ImageHeaderArray[texture].Texture; |
| | 508 | int nr_vertices = RenderPolygon.NumberOfVertices; |
| | 509 | |
| | 510 | if (CurrTextureHandle->w == 128) |
| | 511 | { |
| | 512 | RecipW = (1.0f / 128.0f) / 65536.0f; |
| | 513 | } |
| | 514 | else |
| | 515 | { |
| | 516 | float width = CurrTextureHandle->w; |
| | 517 | RecipW = (1.0f / width) / 65536.0f; |
| | 518 | } |
| | 519 | |
| | 520 | if (CurrTextureHandle->h == 128) |
| | 521 | { |
| | 522 | RecipH = (1.0f / 128.0f) / 65536.0f; |
| | 523 | } |
| | 524 | else |
| | 525 | { |
| | 526 | float height = CurrTextureHandle->h; |
| | 527 | RecipH = (1.0f / height) / 65536.0f; |
| | 528 | } |
| | 529 | |
| | 530 | CheckTriangleBuffer(nr_vertices, nr_vertices, 0, CurrTextureHandle, TranslucencyMode); |
| | 531 | |
| | 532 | while(nr_vertices--) |
| | 533 | { |
| | 534 | const float zvalue = vertices->Z; |
| | 535 | const float rhw = 1.0f / zvalue; |
| | 536 | const GLfloat z = 1.0f - ZNear / zvalue; |
| | 537 | const GLfloat s = ((float)vertices->U) * RecipW + (1.0f / 256.0f); |
| | 538 | const GLfloat t = ((float)vertices->V) * RecipH + (1.0f / 256.0f); |
| | 539 | |
| | 540 | // if (s < 0.0 || t < 0.0 || s >= 1.0 || t >= 1.0) fprintf(stderr, "HEY! s = %f, t = %f (%d, %d)\n", s, t, vertices->U,
vertices->V); |
| | 541 | |
| | 542 | GLfloat x = ((float)vertices->X * (Global_VDB.VDB_ProjX + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 543 | GLfloat y = -((float)vertices->Y * (Global_VDB.VDB_ProjY + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 544 | |
| | 545 | varrp->v[0] = svarrp->v[0] = x / rhw; |
| | 546 | varrp->v[1] = svarrp->v[1] = y / rhw; |
| | 547 | varrp->v[2] = svarrp->v[2] = z / rhw; |
| | 548 | varrp->v[3] = svarrp->v[3] = 1 / rhw; |
| | 549 | |
| | 550 | varrp->t[0] = svarrp->t[0] = s; |
| | 551 | varrp->t[1] = svarrp->t[1] = t; |
| | 552 | |
| | 553 | varrp->c[0] = GammaValues[vertices->R]; |
| | 554 | varrp->c[1] = GammaValues[vertices->G]; |
| | 555 | varrp->c[2] = GammaValues[vertices->B]; |
| | 556 | varrp->c[3] = vertices->A; |
| | 557 | |
| | 558 | svarrp->c[0] = GammaValues[vertices->SpecularR]; |
| | 559 | svarrp->c[1] = GammaValues[vertices->SpecularG]; |
| | 560 | svarrp->c[2] = GammaValues[vertices->SpecularB]; |
| | 561 | svarrp->c[3] = 255; |
| | 562 | |
| | 563 | varrp++; |
| | 564 | varrc++; |
| | 565 | svarrp++; |
| | 566 | svarrc++; |
| | 567 | vertices++; |
| | 568 | } |
| | 569 | } |
| | 570 | |
| | 571 | void SkyPolygon_Output(RENDERVERTEX *vertices, enum TRANSLUCENCY_TYPE TranslucencyMode) |
| | 572 | { |
| | 573 | float RecipW, RecipH; |
| | 574 | CurrTextureHandle = ImageHeaderArray[CloudyImageNumber].Texture; |
| | 575 | int nr_vertices = RenderPolygon.NumberOfVertices; |
| | 576 | |
| | 577 | if (CurrTextureHandle->w == 128) |
| | 578 | { |
| | 579 | RecipW = (1.0f / 128.0f) / 65536.0f; |
| | 580 | } |
| | 581 | else |
| | 582 | { |
| | 583 | float width = CurrTextureHandle->w; |
| | 584 | RecipW = (1.0f / width) / 65536.0f; |
| | 585 | } |
| | 586 | |
| | 587 | if (CurrTextureHandle->h == 128) |
| | 588 | { |
| | 589 | RecipH = (1.0f / 128.0f) / 65536.0f; |
| | 590 | } |
| | 591 | else |
| | 592 | { |
| | 593 | float height = CurrTextureHandle->h; |
| | 594 | RecipH = (1.0f / height) / 65536.0f; |
| | 595 | } |
| | 596 | |
| | 597 | CheckTriangleBuffer(nr_vertices, 0, 0, CurrTextureHandle, TranslucencyMode); |
| | 598 | |
| | 599 | while(nr_vertices--) |
| | 600 | { |
| | 601 | const float zvalue = vertices->Z; |
| | 602 | GLfloat rhw = 1.0 / zvalue; |
| | 603 | |
| | 604 | GLfloat s = ((float)vertices->U) * RecipW + (1.0f/256.0f); |
| | 605 | GLfloat t = ((float)vertices->V) * RecipH + (1.0f/256.0f); |
| | 606 | |
| | 607 | // if (s < 0.0 || t < 0.0 || s >= 1.0 || t >= 1.0) fprintf(stderr, "HEY! s = %f, t = %f (%d, %d)\n", s, t, vertices->U,
vertices->V); |
| | 608 | |
| | 609 | GLfloat x = ((float)vertices->X * (Global_VDB.VDB_ProjX + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 610 | GLfloat y = -((float)vertices->Y * (Global_VDB.VDB_ProjY + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 611 | |
| | 612 | varrp->v[0] = x / rhw; |
| | 613 | varrp->v[1] = y / rhw; |
| | 614 | varrp->v[2] = 1.0f / rhw; |
| | 615 | varrp->v[3] = 1 / rhw; |
| | 616 | |
| | 617 | varrp->t[0] = s; |
| | 618 | varrp->t[1] = t; |
| | 619 | |
| | 620 | varrp->c[0] = vertices->R; |
| | 621 | varrp->c[1] = vertices->G; |
| | 622 | varrp->c[2] = vertices->B; |
| | 623 | varrp->c[3] = vertices->A; |
| | 624 | |
| | 625 | varrp++; |
| | 626 | varrc++; |
| | 627 | vertices++; |
| | 628 | } |
| | 629 | } |
| | 630 | |
| | 631 | void ZBufferedCloakedPolygon_Output(int texture_number, RENDERVERTEX *vertices) |
| | 632 | { |
| | 633 | float RecipW, RecipH; |
| | 634 | CurrTextureHandle = ImageHeaderArray[texture_number].Texture; |
| | 635 | int nr_vertices = RenderPolygon.NumberOfVertices; |
| | 636 | |
| | 637 | if (CurrTextureHandle->w == 128) |
| | 638 | { |
| | 639 | RecipW = 1.0f / 128.0f; |
| | 640 | } |
| | 641 | else |
| | 642 | { |
| | 643 | float width = (float)CurrTextureHandle->w; |
| | 644 | RecipW = 1.0f / width; |
| | 645 | } |
| | 646 | |
| | 647 | if (CurrTextureHandle->h == 128) |
| | 648 | { |
| | 649 | RecipH = 1.0f / 128.0f; |
| | 650 | } |
| | 651 | else |
| | 652 | { |
| | 653 | float height = (float)CurrTextureHandle->h; |
| | 654 | RecipH = 1.0f / height; |
| | 655 | } |
| | 656 | |
| | 657 | CheckTriangleBuffer(nr_vertices, 0, 0, CurrTextureHandle, TRANSLUCENCY_NORMAL); |
| | 658 | |
| | 659 | while(nr_vertices--) |
| | 660 | { |
| | 661 | float zvalue = vertices->Z; |
| | 662 | float rhw = 1.0f / zvalue; |
| | 663 | GLfloat z = 1.0f - ZNear / zvalue; |
| | 664 | |
| | 665 | GLfloat s = (((float)vertices->U/65536.0f)+0.5) * RecipW; |
| | 666 | GLfloat t = (((float)vertices->V/65536.0f)+0.5) * RecipH; |
| | 667 | |
| | 668 | // if (s < 0.0 || t < 0.0 || s >= 1.0 || t >= 1.0) fprintf(stderr, "HEY! s = %f, t = %f (%d, %d)\n", s, t, vertices->U,
vertices->V); |
| | 669 | |
| | 670 | GLfloat x = ((float)vertices->X * (Global_VDB.VDB_ProjX + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 671 | GLfloat y = -((float)vertices->Y * (Global_VDB.VDB_ProjY + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 672 | |
| | 673 | varrp->v[0] = x / rhw; |
| | 674 | varrp->v[1] = y / rhw; |
| | 675 | varrp->v[2] = z / rhw; |
| | 676 | varrp->v[3] = 1 / rhw; |
| | 677 | |
| | 678 | varrp->t[0] = s; |
| | 679 | varrp->t[1] = t; |
| | 680 | |
| | 681 | varrp->c[0] = vertices->R; |
| | 682 | varrp->c[1] = vertices->G; |
| | 683 | varrp->c[2] = vertices->B; |
| | 684 | varrp->c[3] = vertices->A; |
| | 685 | |
| | 686 | varrp++; |
| | 687 | varrc++; |
| | 688 | vertices++; |
| | 689 | } |
| | 690 | } |
| | 691 | |
| | 692 | int LightIntensityAtPoint(const VECTORCH *pointPtr) |
| | 693 | { |
| | 694 | int intensity = 0; |
| | 695 | int i, j; |
| | 696 | |
| | 697 | for(i=0; i < NumActiveBlocks; i++) |
| | 698 | { |
| | 699 | DISPLAYBLOCK *dispPtr = ActiveBlockList[i]; |
| | 700 | |
| | 701 | if (dispPtr->ObNumLights) |
| | 702 | { |
| | 703 | for(j = 0; j < dispPtr->ObNumLights; j++) |
| | 704 | { |
| | 705 | LIGHTBLOCK *lptr = dispPtr->ObLights[j]; |
| | 706 | VECTORCH disp = lptr->LightWorld; |
| | 707 | |
| | 708 | disp.vx -= pointPtr->vx; |
| | 709 | disp.vy -= pointPtr->vy; |
| | 710 | disp.vz -= pointPtr->vz; |
| | 711 | |
| | 712 | int dist = Approximate3dMagnitude(&disp); |
| | 713 | |
| | 714 | if (dist < lptr->LightRange) |
| | 715 | intensity += WideMulNarrowDiv(lptr->LightBright, lptr->LightRange - dist, lptr->LightRange); |
| | 716 | } |
| | 717 | } |
| | 718 | } |
| | 719 | |
| | 720 | return (intensity > ONE_FIXED) ? ONE_FIXED : intensity; |
| | 721 | } |
| | 722 | |
| | 723 | void Decal_Output(const DECAL *decalPtr, RENDERVERTEX *vertices) |
| | 724 | { |
| | 725 | const DECAL_DESC *decalDescPtr = &DecalDescription[decalPtr->DecalID]; |
| | 726 | struct TEXTURE *TextureHandle; |
| | 727 | static const float RecipW = 1.0f / 256.0f; |
| | 728 | static const float RecipH = 1.0f / 256.0f; |
| | 729 | int r, g, b; |
| | 730 | int nr_vertices = RenderPolygon.NumberOfVertices; |
| | 731 | |
| | 732 | switch(decalPtr->DecalID) |
| | 733 | { |
| | 734 | case DECAL_SHAFTOFLIGHT: |
| | 735 | case DECAL_SHAFTOFLIGHT_OUTER: |
| | 736 | TextureHandle = NULL; |
| | 737 | break; |
| | 738 | default: |
| | 739 | TextureHandle = ImageHeaderArray[SpecialFXImageNumber].Texture; |
| | 740 | } |
| | 741 | |
| | 742 | if (CHEATMODE_RAINBOWBLOOD == UserProfile.active_bonus) |
| | 743 | { |
| | 744 | r = FastRandom() & 255; |
| | 745 | g = FastRandom() & 255; |
| | 746 | b = FastRandom() & 255; |
| | 747 | } |
| | 748 | else if (decalDescPtr->IsLit) |
| | 749 | { |
| | 750 | int intensity = LightIntensityAtPoint(decalPtr->Vertices); |
| | 751 | |
| | 752 | r = MUL_FIXED(intensity, decalDescPtr->RedScale[PlayerStatus.VisionMode]); |
| | 753 | g = MUL_FIXED(intensity, decalDescPtr->GreenScale[PlayerStatus.VisionMode]); |
| | 754 | b = MUL_FIXED(intensity, decalDescPtr->BlueScale[PlayerStatus.VisionMode]); |
| | 755 | } |
| | 756 | else |
| | 757 | { |
| | 758 | r = decalDescPtr->RedScale[PlayerStatus.VisionMode]; |
| | 759 | g = decalDescPtr->GreenScale[PlayerStatus.VisionMode]; |
| | 760 | b = decalDescPtr->BlueScale[PlayerStatus.VisionMode]; |
| | 761 | } |
| | 762 | |
| | 763 | CheckTriangleBuffer(nr_vertices, 0, 0, TextureHandle, decalDescPtr->TranslucencyType); |
| | 764 | |
| | 765 | while(nr_vertices--) |
| | 766 | { |
| | 767 | float zvalue = vertices->Z; |
| | 768 | float rhw = 1.0f / zvalue; |
| | 769 | GLfloat z = 1.0f - ZNear / zvalue; |
| | 770 | |
| | 771 | GLfloat x = ((float)vertices->X * (Global_VDB.VDB_ProjX + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 772 | GLfloat y = -((float)vertices->Y * (Global_VDB.VDB_ProjY + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 773 | |
| | 774 | GLfloat s = ((float)(vertices->U / 65536.0f)+0.5f) * RecipW; |
| | 775 | GLfloat t = ((float)(vertices->V / 65536.0f)+0.5f) * RecipH; |
| | 776 | |
| | 777 | varrp->v[0] = x / rhw; |
| | 778 | varrp->v[1] = y / rhw; |
| | 779 | varrp->v[2] = z / rhw; |
| | 780 | varrp->v[3] = 1 / rhw; |
| | 781 | |
| | 782 | varrp->t[0] = s; |
| | 783 | varrp->t[1] = t; |
| | 784 | |
| | 785 | varrp->c[0] = r; |
| | 786 | varrp->c[1] = g; |
| | 787 | varrp->c[2] = b; |
| | 788 | varrp->c[3] = decalDescPtr->Alpha; |
| | 789 | |
| | 790 | varrp++; |
| | 791 | varrc++; |
| | 792 | vertices++; |
| | 793 | } |
| | 794 | } |
| | 795 | |
| | 796 | void Particle_Output(PARTICLE *particlePtr, RENDERVERTEX *vertices) |
| | 797 | { |
| | 798 | int r, g, b, a; |
| | 799 | const PARTICLE_DESC *particleDescPtr = &ParticleDescription[particlePtr->ParticleID]; |
| | 800 | struct TEXTURE *TextureHandle = ImageHeaderArray[SpecialFXImageNumber].Texture; |
| | 801 | static const float RecipW = 1.0f / 256.0f; |
| | 802 | static const float RecipH = 1.0f / 256.0f; |
| | 803 | int nr_vertices = RenderPolygon.NumberOfVertices; |
| | 804 | |
| | 805 | if (CHEATMODE_RAINBOWBLOOD == UserProfile.active_bonus) |
| | 806 | { |
| | 807 | r = FastRandom() & 255; |
| | 808 | g = FastRandom() & 255; |
| | 809 | b = FastRandom() & 255; |
| | 810 | a = particleDescPtr->Alpha; |
| | 811 | } |
| | 812 | else if (particleDescPtr->IsLit && !((particlePtr->ParticleID == PARTICLE_ALIEN_BLOOD) && (PlayerStatus.VisionMode ==
VISION_MODE_PRED_SEEALIENS))) |
| | 813 | { |
| | 814 | if (particlePtr->ParticleID == PARTICLE_SMOKECLOUD || particlePtr->ParticleID == PARTICLE_ANDROID_BLOOD) |
| | 815 | { |
| | 816 | /* this should be OK. (ColourComponents was RGBA while RGBA_MAKE is BGRA (little endian) */ |
| | 817 | r = (particlePtr->Colour >> 0) & 0xFF; |
| | 818 | g = (particlePtr->Colour >> 8) & 0xFF; |
| | 819 | b = (particlePtr->Colour >> 16) & 0xFF; |
| | 820 | a = (particlePtr->Colour >> 24) & 0xFF; |
| | 821 | } |
| | 822 | else |
| | 823 | { |
| | 824 | int intensity = LightIntensityAtPoint(&particlePtr->Position); |
| | 825 | |
| | 826 | r = MUL_FIXED(intensity, particleDescPtr->RedScale[PlayerStatus.VisionMode]); |
| | 827 | g = MUL_FIXED(intensity, particleDescPtr->GreenScale[PlayerStatus.VisionMode]); |
| | 828 | b = MUL_FIXED(intensity, particleDescPtr->BlueScale[PlayerStatus.VisionMode]); |
| | 829 | a = particleDescPtr->Alpha; |
| | 830 | } |
| | 831 | } |
| | 832 | else |
| | 833 | { |
| | 834 | b = particlePtr->Colour & 0xFF; |
| | 835 | g = (particlePtr->Colour >> 8) & 0xFF; |
| | 836 | r = (particlePtr->Colour >> 16) & 0xFF; |
| | 837 | a = (particlePtr->Colour >> 24) & 0xFF; |
| | 838 | } |
| | 839 | |
| | 840 | CheckTriangleBuffer(nr_vertices, 0, 0, TextureHandle, particleDescPtr->TranslucencyType); |
| | 841 | |
| | 842 | while(nr_vertices--) |
| | 843 | { |
| | 844 | const float zvalue = vertices->Z; |
| | 845 | GLfloat rhw = 1.0f / zvalue; |
| | 846 | GLfloat s = ((GLfloat)(vertices->U>>16)+0.5f) * RecipW; |
| | 847 | GLfloat t = ((GLfloat)(vertices->V>>16)+0.5f) * RecipH; |
| | 848 | |
| | 849 | GLfloat x = ((float)vertices->X * (Global_VDB.VDB_ProjX + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 850 | GLfloat y = -((float)vertices->Y * (Global_VDB.VDB_ProjY +1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 851 | |
| | 852 | GLfloat z = (particleDescPtr->IsDrawnInFront) ? -0.999f : (particleDescPtr->IsDrawnAtBack) ? 0.999f : (1.0f - ZNear / zvalue); |
| | 853 | //z = 1.0f - ZNear / zvalue; /* currently maps [ZNear, inf) to [-1, 1], probably could be more precise with a ZFar */ |
| | 854 | |
| | 855 | varrp->v[0] = x / rhw; |
| | 856 | varrp->v[1] = y / rhw; |
| | 857 | varrp->v[2] = z / rhw; |
| | 858 | varrp->v[3] = 1 / rhw; |
| | 859 | |
| | 860 | varrp->t[0] = s; |
| | 861 | varrp->t[1] = t; |
| | 862 | |
| | 863 | varrp->c[0] = r; |
| | 864 | varrp->c[1] = g; |
| | 865 | varrp->c[2] = b; |
| | 866 | varrp->c[3] = a; |
| | 867 | |
| | 868 | varrp++; |
| | 869 | varrc++; |
| | 870 | vertices++; |
| | 871 | } |
| | 872 | } |
| | 873 | |
| | 874 | void Polygon(RENDERVERTEX *vertices, enum TRANSLUCENCY_TYPE TranslucencyMode) |
| | 875 | { |
| | 876 | int nr_vertices = RenderPolygon.NumberOfVertices; |
| | 877 | CheckTriangleBuffer(nr_vertices, 0, 0, NULL, TranslucencyMode); |
| | 878 | CheckBoundTextureIsCorrect(NULL); |
| | 879 | |
| | 880 | while(nr_vertices--) |
| | 881 | { |
| | 882 | float zvalue = vertices->Z; |
| | 883 | float rhw = 1.0f / zvalue; |
| | 884 | GLfloat z = 1.0f - ZNear / zvalue; |
| | 885 | |
| | 886 | GLfloat x = ((float)vertices->X * (Global_VDB.VDB_ProjX + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 887 | GLfloat y = -((float)vertices->Y * (Global_VDB.VDB_ProjY + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 888 | |
| | 889 | varrp->v[0] = x / rhw; |
| | 890 | varrp->v[1] = y / rhw; |
| | 891 | varrp->v[2] = z / rhw; |
| | 892 | varrp->v[3] = 1 / rhw; |
| | 893 | |
| | 894 | varrp->c[0] = vertices->R; |
| | 895 | varrp->c[1] = vertices->G; |
| | 896 | varrp->c[2] = vertices->B; |
| | 897 | varrp->c[3] = vertices->A; |
| | 898 | |
| | 899 | varrp++; |
| | 900 | varrc++; |
| | 901 | vertices++; |
| | 902 | } |
| | 903 | } |
| | 904 | |
| | 905 | void PlayerOnFireOverlay() |
| | 906 | { |
| | 907 | int FMVParticleColour = (VISION_MODE_IMAGEINTENSIFIER == PlayerStatus.VisionMode) ? RGBA_MAKE(0,255,0,128) : RGBA_MAKE(255,255,255,128); |
| | 908 | |
| | 909 | int colour = (FMVParticleColour & 0xffffff) + (128 << 24); |
| | 910 | GLfloat s[4], t[4]; |
| | 911 | int b = (colour >> 0) & 0xFF; |
| | 912 | int g = (colour >> 8) & 0xFF; |
| | 913 | int r = (colour >> 16) & 0xFF; |
| | 914 | int a = (colour >> 24) & 0xFF; |
| | 915 | float u = (FastRandom() & 255) / 256.0f; |
| | 916 | float v = (FastRandom() & 255) / 256.0f; |
| | 917 | |
| | 918 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_GLOWING); |
| | 919 | CheckBoundTextureIsCorrect(ImageHeaderArray[BurningImageNumber].Texture); |
| | 920 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_ON); |
| | 921 | |
| | 922 | glColor4ub(r, g, b, a); |
| | 923 | |
| | 924 | s[0] = s[3] = u; |
| | 925 | s[1] = s[2] = u + 1.0f; |
| | 926 | |
| | 927 | t[0] = t[1] = v; |
| | 928 | t[2] = t[3] = v + 1.0f; |
| | 929 | |
| | 930 | glBegin(GL_QUADS); |
| | 931 | glTexCoord2f(s[0], t[0]); glVertex3i(-1, -1, -1); |
| | 932 | glTexCoord2f(s[1], t[1]); glVertex3i(1, -1, -1); |
| | 933 | glTexCoord2f(s[2], t[2]); glVertex3i(1, 1, -1); |
| | 934 | glTexCoord2f(s[3], t[3]); glVertex3i(-1, 1, -1); |
| | 935 | glEnd(); |
| | 936 | } |
| | 937 | |
| | 938 | void PlayerDamagedOverlay(int intensity) |
| | 939 | { |
| | 940 | int theta[2]; |
| | 941 | int colour, baseColour; |
| | 942 | int r, g, b, a; |
| | 943 | int i; |
| | 944 | |
| | 945 | theta[0] = (CloakingPhase / 8) & 4095; |
| | 946 | theta[1] = (800 - CloakingPhase / 8) & 4095; |
| | 947 | |
| | 948 | switch(AvP.PlayerType) |
| | 949 | { |
| | 950 | case I_Marine: |
| | 951 | default: |
| | 952 | baseColour = 0xff0000; |
| | 953 | break; |
| | 954 | case I_Alien: |
| | 955 | baseColour = 0xffff00; |
| | 956 | break; |
| | 957 | case I_Predator: |
| | 958 | baseColour = 0x00ff00; |
| | 959 | } |
| | 960 | |
| | 961 | CheckBoundTextureIsCorrect(ImageHeaderArray[SpecialFXImageNumber].Texture); |
| | 962 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_ON); |
| | 963 | |
| | 964 | colour = 0xffffff - baseColour + (intensity << 24); |
| | 965 | |
| | 966 | b = (colour >> 0) & 0xFF; |
| | 967 | g = (colour >> 8) & 0xFF; |
| | 968 | r = (colour >> 16) & 0xFF; |
| | 969 | a = (colour >> 24) & 0xFF; |
| | 970 | |
| | 971 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_INVCOLOUR); |
| | 972 | |
| | 973 | glColor4ub(r, g, b, a); |
| | 974 | |
| | 975 | for (i = 0; i < 2; i++) |
| | 976 | { |
| | 977 | GLfloat s[4], t[4]; |
| | 978 | |
| | 979 | float sin = (GetSin(theta[i])) / 65536.0f / 16.0f; |
| | 980 | float cos = (GetCos(theta[i])) / 65536.0f / 16.0f; |
| | 981 | |
| | 982 | s[0] = 0.875f + (cos*(-1) - sin*(-1)); |
| | 983 | s[1] = 0.875f + (cos*(+1) - sin*(-1)); |
| | 984 | s[2] = 0.875f + (cos*(+1) - sin*(+1)); |
| | 985 | s[3] = 0.875f + (cos*(-1) - sin*(+1)); |
| | 986 | |
| | 987 | t[0] = 0.375f + (sin*(-1) + cos*(-1)); |
| | 988 | t[1] = 0.375f + (sin*(+1) + cos*(-1)); |
| | 989 | t[2] = 0.375f + (sin*(+1) + cos*(+1)); |
| | 990 | t[3] = 0.375f + (sin*(-1) + cos*(+1)); |
| | 991 | |
| | 992 | glBegin(GL_QUADS); |
| | 993 | glTexCoord2f(s[0], t[0]); glVertex3i(-1, -1, -1); |
| | 994 | glTexCoord2f(s[1], t[1]); glVertex3i(1, -1, -1); |
| | 995 | glTexCoord2f(s[2], t[2]); glVertex3i(1, 1, -1); |
| | 996 | glTexCoord2f(s[3], t[3]); glVertex3i(-1, 1, -1); |
| | 997 | glEnd(); |
| | 998 | |
| | 999 | colour = baseColour + (intensity << 24); |
| | 1000 | |
| | 1001 | b = (colour >> 0) & 0xFF; |
| | 1002 | g = (colour >> 8) & 0xFF; |
| | 1003 | r = (colour >> 16) & 0xFF; |
| | 1004 | a = (colour >> 24) & 0xFF; |
| | 1005 | |
| | 1006 | glColor4ub(r, g, b, a); |
| | 1007 | |
| | 1008 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_GLOWING); |
| | 1009 | } |
| | 1010 | } |
| | 1011 | |
| | 1012 | void update_static() |
| | 1013 | { |
| | 1014 | struct TEXTURE *temp = ImageHeaderArray[StaticImageNumber].Texture; |
| | 1015 | unsigned char *ptr = temp->buf; |
| | 1016 | int i; |
| | 1017 | |
| | 1018 | for(i=0; i < 128 * 128; i++, ptr += 3) |
| | 1019 | ptr[0] = ptr[1] = ptr[2] = ((FastRandom() % 2) ? 0 : 255); |
| | 1020 | |
| | 1021 | CheckBoundTextureIsCorrect(ImageHeaderArray[StaticImageNumber].Texture); |
| | 1022 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, temp->w, temp->h, 0, GL_RGB, GL_UNSIGNED_BYTE, temp->buf); |
| | 1023 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_ON); |
| | 1024 | } |
| | 1025 | |
| | 1026 | void DrawNoiseOverlay(int tr) |
| | 1027 | { |
| | 1028 | update_static(); |
| | 1029 | |
| | 1030 | glColor4ub(255, 255, 255, tr); |
| | 1031 | |
| | 1032 | glBegin(GL_QUADS); |
| | 1033 | glTexCoord2i(0, 0); glVertex3i(-1, -1, -1); |
| | 1034 | glTexCoord2i(1, 0); glVertex3i(1, -1, -1); |
| | 1035 | glTexCoord2i(1, 1); glVertex3i(1, 1, -1); |
| | 1036 | glTexCoord2i(0, 1); glVertex3i(-1, 1, -1); |
| | 1037 | glEnd(); |
| | 1038 | } |
| | 1039 | |
| | 1040 | void ScreenInversionOverlay() |
| | 1041 | { |
| | 1042 | int i = 0; |
| | 1043 | int theta[2]; |
| | 1044 | |
| | 1045 | theta[0] = (CloakingPhase / 8) & 4095; |
| | 1046 | theta[1] = (800 - CloakingPhase / 8) & 4095; |
| | 1047 | |
| | 1048 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_DARKENINGCOLOUR); |
| | 1049 | CheckBoundTextureIsCorrect(ImageHeaderArray[SpecialFXImageNumber].Texture); |
| | 1050 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_ON); |
| | 1051 | |
| | 1052 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
| | 1053 | |
| | 1054 | for (; i < 2; i++) |
| | 1055 | { |
| | 1056 | GLfloat s[4], t[4]; |
| | 1057 | |
| | 1058 | float sin = GetSin(theta[i]) / 65536.0f / 16.0f; |
| | 1059 | float cos = GetCos(theta[i]) / 65536.0f / 16.0f; |
| | 1060 | |
| | 1061 | s[0] = 0.375f + (cos*(-1) - sin*(-1)); |
| | 1062 | s[1] = 0.375f + (cos*(+1) - sin*(-1)); |
| | 1063 | s[2] = 0.375f + (cos*(+1) - sin*(+1)); |
| | 1064 | s[3] = 0.375f + (cos*(-1) - sin*(+1)); |
| | 1065 | |
| | 1066 | t[0] = 0.375f + (sin*(-1) + cos*(-1)); |
| | 1067 | t[2] = 0.375f + (sin*(+1) + cos*(+1)); |
| | 1068 | t[1] = 0.375f + (sin*(+1) + cos*(-1)); |
| | 1069 | t[3] = 0.375f + (sin*(-1) + cos*(+1)); |
| | 1070 | |
| | 1071 | glBegin(GL_QUADS); |
| | 1072 | glTexCoord2f(s[0], t[0]); glVertex2i(-1, -1); |
| | 1073 | glTexCoord2f(s[1], t[1]); glVertex2i(1, -1); |
| | 1074 | glTexCoord2f(s[2], t[2]); glVertex2i(1, 1); |
| | 1075 | glTexCoord2f(s[3], t[3]); glVertex2i(-1, 1); |
| | 1076 | glEnd(); |
| | 1077 | |
| | 1078 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_COLOUR); |
| | 1079 | } |
| | 1080 | } |
| | 1081 | |
| | 1082 | void PredatorScreenInversionOverlay() |
| | 1083 | { |
| | 1084 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_DARKENINGCOLOUR); |
| | 1085 | CheckBoundTextureIsCorrect(NULL); |
| | 1086 | |
| | 1087 | glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |
| | 1088 | |
| | 1089 | glBegin(GL_QUADS); |
| | 1090 | glVertex3i(-1, -1, -1); |
| | 1091 | glVertex3i( 1, -1, -1); |
| | 1092 | glVertex3i( 1, 1, -1); |
| | 1093 | glVertex3i(-1, 1, -1); |
| | 1094 | glEnd(); |
| | 1095 | } |
| | 1096 | |
| | 1097 | void DrawScanlinesOverlay(float level) |
| | 1098 | { |
| | 1099 | GLfloat s[4]; |
| | 1100 | int a = 64.0f + level * 64.0f; |
| | 1101 | float size = 128.0f * (1.0f - level * 0.8f); |
| | 1102 | |
| | 1103 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_NORMAL); |
| | 1104 | CheckBoundTextureIsCorrect(ImageHeaderArray[PredatorNumbersImageNumber].Texture); |
| | 1105 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_ON); |
| | 1106 | |
| | 1107 | glColor4ub(255, 255, 255, a); |
| | 1108 | |
| | 1109 | s[0] = s[1] = (128.0f - size) / 256.0f; |
| | 1110 | s[2] = s[3] = (128.0f + size) / 256.0f; |
| | 1111 | |
| | 1112 | glBegin(GL_QUADS); |
| | 1113 | glTexCoord2f(s[0], 1.0f); glVertex3i(-1, -1, -1); |
| | 1114 | glTexCoord2f(s[1], 1.0f); glVertex3i(1, -1, -1); |
| | 1115 | glTexCoord2f(s[2], 1.0f); glVertex3i(1, 1, -1); |
| | 1116 | glTexCoord2f(s[3], 1.0f); glVertex3i(-1, 1, -1); |
| | 1117 | glEnd(); |
| | 1118 | } |
| | 1119 | |
| | 1120 | void FadeDownScreen(int brightness, int colour) |
| | 1121 | { |
| | 1122 | int t = 255 - (brightness >> 8); |
| | 1123 | |
| | 1124 | if (t < 0) |
| | 1125 | t = 0; |
| | 1126 | |
| | 1127 | colour = (t << 24) + colour; |
| | 1128 | |
| | 1129 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_NORMAL); |
| | 1130 | CheckBoundTextureIsCorrect(NULL); |
| | 1131 | |
| | 1132 | int b = (colour >> 0) & 0xFF; |
| | 1133 | int g = (colour >> 8) & 0xFF; |
| | 1134 | int r = (colour >> 16) & 0xFF; |
| | 1135 | int a = (colour >> 24) & 0xFF; |
| | 1136 | |
| | 1137 | glColor4ub(r, g, b, a); |
| | 1138 | |
| | 1139 | glBegin(GL_QUADS); |
| | 1140 | glVertex3i(-1, -1, -1); |
| | 1141 | glVertex3i(1, -1, -1); |
| | 1142 | glVertex3i(1, 1, -1); |
| | 1143 | glVertex3i(-1, 1, -1); |
| | 1144 | glEnd(); |
| | 1145 | } |
| | 1146 | |
| | 1147 | void HUDQuad_Output(int imageNumber, struct VertexTag *quadVerticesPtr, unsigned int colour) |
| | 1148 | { |
| | 1149 | float RecipW, RecipH; |
| | 1150 | int i; |
| | 1151 | GLfloat x[4], y[4], s[4], t[4]; |
| | 1152 | struct TEXTURE *tex = ImageHeaderArray[imageNumber].Texture; |
| | 1153 | |
| | 1154 | /* possibly use polygon offset? (predator hud) */ |
| | 1155 | |
| | 1156 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_GLOWING); |
| | 1157 | CheckBoundTextureIsCorrect(tex); |
| | 1158 | |
| | 1159 | if (tex->w == 128) |
| | 1160 | { |
| | 1161 | RecipW = 1.0f / 128.0f; |
| | 1162 | } |
| | 1163 | else |
| | 1164 | { |
| | 1165 | float width = (float) tex->w; |
| | 1166 | RecipW = 1.0f / width; |
| | 1167 | } |
| | 1168 | |
| | 1169 | if (tex->h == 128) |
| | 1170 | { |
| | 1171 | RecipH = 1.0f / 128.0f; |
| | 1172 | } |
| | 1173 | else |
| | 1174 | { |
| | 1175 | float height = (float) tex->h; |
| | 1176 | RecipH = 1.0f / height; |
| | 1177 | } |
| | 1178 | |
| | 1179 | int b = (colour >> 0) & 0xFF; |
| | 1180 | int g = (colour >> 8) & 0xFF; |
| | 1181 | int r = (colour >> 16) & 0xFF; |
| | 1182 | int a = (colour >> 24) & 0xFF; |
| | 1183 | |
| | 1184 | glColor4ub(r, g, b, a); |
| | 1185 | |
| | 1186 | for (i = 0; i < 4; i++) |
| | 1187 | { |
| | 1188 | x[i] = quadVerticesPtr[i].X; |
| | 1189 | x[i] = (x[i] - ScreenDescriptorBlock.SDB_CentreX) / ScreenDescriptorBlock.SDB_CentreX; |
| | 1190 | y[i] = quadVerticesPtr[i].Y; |
| | 1191 | y[i] = -(y[i] - ScreenDescriptorBlock.SDB_CentreY) / ScreenDescriptorBlock.SDB_CentreY; |
| | 1192 | |
| | 1193 | s[i] = ((float)quadVerticesPtr[i].U) * RecipW; |
| | 1194 | t[i] = ((float)quadVerticesPtr[i].V) * RecipH; |
| | 1195 | } |
| | 1196 | |
| | 1197 | glBegin(GL_QUADS); |
| | 1198 | glTexCoord2f(s[0], t[0]); glVertex3f(x[0], y[0], -1.0f); |
| | 1199 | glTexCoord2f(s[1], t[1]); glVertex3f(x[1], y[1], -1.0f); |
| | 1200 | glTexCoord2f(s[2], t[2]); glVertex3f(x[2], y[2], -1.0f); |
| | 1201 | glTexCoord2f(s[3], t[3]); glVertex3f(x[3], y[3], -1.0f); |
| | 1202 | glEnd(); |
| | 1203 | } |
| | 1204 | |
| | 1205 | void RenderHUDNumber_Centred(unsigned int number,int x,int y,int colour) |
| | 1206 | { |
| | 1207 | struct VertexTag quadVertices[4]; |
| | 1208 | int noOfDigits = 3; |
| | 1209 | int h = MUL_FIXED(HUDScaleFactor, HUD_DIGITAL_NUMBERS_HEIGHT); |
| | 1210 | int w = MUL_FIXED(HUDScaleFactor, HUD_DIGITAL_NUMBERS_WIDTH); |
| | 1211 | |
| | 1212 | quadVertices[0].Y = y; |
| | 1213 | quadVertices[1].Y = y; |
| | 1214 | quadVertices[2].Y = y + h; |
| | 1215 | quadVertices[3].Y = y + h; |
| | 1216 | |
| | 1217 | x += (3 * w) / 2; |
| | 1218 | |
| | 1219 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_OFF); |
| | 1220 | |
| | 1221 | do { |
| | 1222 | int topLeftU, topLeftV; |
| | 1223 | |
| | 1224 | int digit = number % 10; |
| | 1225 | number /= 10; |
| | 1226 | |
| | 1227 | if (digit < 8) |
| | 1228 | { |
| | 1229 | topLeftU = 1 + (digit) * 16; |
| | 1230 | topLeftV = 1; |
| | 1231 | } |
| | 1232 | else |
| | 1233 | { |
| | 1234 | topLeftU = 1 + (digit-8) * 16; |
| | 1235 | topLeftV = 1 + 24; |
| | 1236 | } |
| | 1237 | |
| | 1238 | topLeftV += 80; |
| | 1239 | |
| | 1240 | quadVertices[0].U = topLeftU; |
| | 1241 | quadVertices[0].V = topLeftV; |
| | 1242 | quadVertices[1].U = topLeftU + HUD_DIGITAL_NUMBERS_WIDTH; |
| | 1243 | quadVertices[1].V = topLeftV; |
| | 1244 | quadVertices[2].U = topLeftU + HUD_DIGITAL_NUMBERS_WIDTH; |
| | 1245 | quadVertices[2].V = topLeftV + HUD_DIGITAL_NUMBERS_HEIGHT; |
| | 1246 | quadVertices[3].U = topLeftU; |
| | 1247 | quadVertices[3].V = topLeftV + HUD_DIGITAL_NUMBERS_HEIGHT; |
| | 1248 | |
| | 1249 | x -= 1+w; |
| | 1250 | quadVertices[0].X = x; |
| | 1251 | quadVertices[3].X = x; |
| | 1252 | quadVertices[1].X = x + w; |
| | 1253 | quadVertices[2].X = x + w; |
| | 1254 | |
| | 1255 | HUDQuad_Output(HUDFontsImageNumber, quadVertices, colour); |
| | 1256 | |
| | 1257 | } while (--noOfDigits); |
| | 1258 | } |
| | 1259 | |
| | 1260 | void RenderHUDString(const char *stringPtr, int x,int y,int colour) |
| | 1261 | { |
| | 1262 | struct VertexTag quadVertices[4]; |
| | 1263 | quadVertices[0].Y = y-1; |
| | 1264 | quadVertices[1].Y = y-1; |
| | 1265 | quadVertices[2].Y = y + HUD_FONT_HEIGHT + 1; |
| | 1266 | quadVertices[3].Y = y + HUD_FONT_HEIGHT + 1; |
| | 1267 | |
| | 1268 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_OFF); |
| | 1269 | |
| | 1270 | while(*stringPtr) |
| | 1271 | { |
| | 1272 | char c = *stringPtr++; |
| | 1273 | int topLeftU = 1+((c-32) & 15) * 16; |
| | 1274 | int topLeftV = 1+((c-32) >> 4) * 16; |
| | 1275 | |
| | 1276 | quadVertices[0].U = topLeftU - 1; |
| | 1277 | quadVertices[0].V = topLeftV - 1; |
| | 1278 | quadVertices[1].U = topLeftU + HUD_FONT_WIDTH + 1; |
| | 1279 | quadVertices[1].V = topLeftV - 1; |
| | 1280 | quadVertices[2].U = topLeftU + HUD_FONT_WIDTH + 1; |
| | 1281 | quadVertices[2].V = topLeftV + HUD_FONT_HEIGHT + 1; |
| | 1282 | quadVertices[3].U = topLeftU - 1; |
| | 1283 | quadVertices[3].V = topLeftV + HUD_FONT_HEIGHT + 1; |
| | 1284 | |
| | 1285 | quadVertices[0].X = x - 1; |
| | 1286 | quadVertices[3].X = x - 1; |
| | 1287 | quadVertices[1].X = x + HUD_FONT_WIDTH + 1; |
| | 1288 | quadVertices[2].X = x + HUD_FONT_WIDTH + 1; |
| | 1289 | |
| | 1290 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1291 | |
| | 1292 | x += AAFontWidths[(unsigned char)c]; |
| | 1293 | } |
| | 1294 | } |
| | 1295 | |
| | 1296 | void RenderHUDString_Centred(const char *stringPtr, int centreX, int y, int colour) |
| | 1297 | { |
| | 1298 | int x, length = 0; |
| | 1299 | const char *ptr = stringPtr; |
| | 1300 | struct VertexTag quadVertices[4]; |
| | 1301 | |
| | 1302 | while(*ptr) |
| | 1303 | length += AAFontWidths[(unsigned char)*ptr++]; |
| | 1304 | |
| | 1305 | length = MUL_FIXED(HUDScaleFactor, length); |
| | 1306 | |
| | 1307 | x = centreX-length / 2; |
| | 1308 | |
| | 1309 | quadVertices[0].Y = y - MUL_FIXED(HUDScaleFactor, 1); |
| | 1310 | quadVertices[1].Y = y - MUL_FIXED(HUDScaleFactor, 1); |
| | 1311 | quadVertices[2].Y = y + MUL_FIXED(HUDScaleFactor, HUD_FONT_HEIGHT + 1); |
| | 1312 | quadVertices[3].Y = y + MUL_FIXED(HUDScaleFactor, HUD_FONT_HEIGHT + 1); |
| | 1313 | |
| | 1314 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_OFF); |
| | 1315 | |
| | 1316 | while(*stringPtr) |
| | 1317 | { |
| | 1318 | char c = *stringPtr++; |
| | 1319 | |
| | 1320 | int topLeftU = 1+((c-32)&15)*16; |
| | 1321 | int topLeftV = 1+((c-32)>>4)*16; |
| | 1322 | |
| | 1323 | quadVertices[0].U = topLeftU - 1; |
| | 1324 | quadVertices[0].V = topLeftV - 1; |
| | 1325 | quadVertices[1].U = topLeftU + HUD_FONT_WIDTH + 1; |
| | 1326 | quadVertices[1].V = topLeftV - 1; |
| | 1327 | quadVertices[2].U = topLeftU + HUD_FONT_WIDTH + 1; |
| | 1328 | quadVertices[2].V = topLeftV + HUD_FONT_HEIGHT + 1; |
| | 1329 | quadVertices[3].U = topLeftU - 1; |
| | 1330 | quadVertices[3].V = topLeftV + HUD_FONT_HEIGHT + 1; |
| | 1331 | |
| | 1332 | quadVertices[0].X = x - MUL_FIXED(HUDScaleFactor,1); |
| | 1333 | quadVertices[3].X = x - MUL_FIXED(HUDScaleFactor,1); |
| | 1334 | quadVertices[1].X = x + MUL_FIXED(HUDScaleFactor,HUD_FONT_WIDTH + 1); |
| | 1335 | quadVertices[2].X = x + MUL_FIXED(HUDScaleFactor,HUD_FONT_WIDTH + 1); |
| | 1336 | |
| | 1337 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1338 | |
| | 1339 | x += MUL_FIXED(HUDScaleFactor,AAFontWidths[(unsigned char)c]); |
| | 1340 | } |
| | 1341 | } |
| | 1342 | |
| | 1343 | void RenderStringCentred(const char *stringPtr, int centreX, int y, int colour) |
| | 1344 | { |
| | 1345 | int length = 0; |
| | 1346 | const char *ptr = stringPtr; |
| | 1347 | |
| | 1348 | while(*ptr) |
| | 1349 | length += AAFontWidths[(unsigned char)*ptr++]; |
| | 1350 | |
| | 1351 | RenderHUDString(stringPtr, centreX-length/2, y, colour); |
| | 1352 | } |
| | 1353 | |
| | 1354 | void RenderStringVertically(const char *stringPtr, int centreX, int bottomY, int colour) |
| | 1355 | { |
| | 1356 | struct VertexTag quadVertices[4]; |
| | 1357 | int y = bottomY; |
| | 1358 | |
| | 1359 | quadVertices[0].X = centreX - (HUD_FONT_HEIGHT/2) - 1; |
| | 1360 | quadVertices[1].X = quadVertices[0].X; |
| | 1361 | quadVertices[2].X = quadVertices[0].X+2+HUD_FONT_HEIGHT*1; |
| | 1362 | quadVertices[3].X = quadVertices[2].X; |
| | 1363 | |
| | 1364 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_OFF); |
| | 1365 | |
| | 1366 | while(*stringPtr) |
| | 1367 | { |
| | 1368 | char c = *stringPtr++; |
| | 1369 | |
| | 1370 | int topLeftU = 1+((c-32)&15)*16; |
| | 1371 | int topLeftV = 1+((c-32)>>4)*16; |
| | 1372 | |
| | 1373 | quadVertices[0].U = topLeftU - 1; |
| | 1374 | quadVertices[0].V = topLeftV - 1; |
| | 1375 | quadVertices[1].U = topLeftU + HUD_FONT_WIDTH; |
| | 1376 | quadVertices[1].V = topLeftV - 1; |
| | 1377 | quadVertices[2].U = topLeftU + HUD_FONT_WIDTH; |
| | 1378 | quadVertices[2].V = topLeftV + HUD_FONT_HEIGHT + 1; |
| | 1379 | quadVertices[3].U = topLeftU - 1; |
| | 1380 | quadVertices[3].V = topLeftV + HUD_FONT_HEIGHT + 1; |
| | 1381 | |
| | 1382 | quadVertices[0].Y = y ; |
| | 1383 | quadVertices[1].Y = y - HUD_FONT_WIDTH*1 -1; |
| | 1384 | quadVertices[2].Y = y - HUD_FONT_WIDTH*1 -1; |
| | 1385 | quadVertices[3].Y = y ; |
| | 1386 | |
| | 1387 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1388 | |
| | 1389 | y -= AAFontWidths[(unsigned char)c]; |
| | 1390 | } |
| | 1391 | } |
| | 1392 | |
| | 1393 | int RenderSmallMenuText(const char *textPtr, int x, int y, int alpha, enum MENUFORMAT_ID format) |
| | 1394 | { |
| | 1395 | switch(format) |
| | 1396 | { |
| | 1397 | case MENUFORMAT_LEFTJUSTIFIED: |
| | 1398 | break; // supplied x is correct |
| | 1399 | case MENUFORMAT_RIGHTJUSTIFIED: |
| | 1400 | { |
| | 1401 | int length = 0; |
| | 1402 | const char *ptr = textPtr; |
| | 1403 | |
| | 1404 | while(*ptr) |
| | 1405 | { |
| | 1406 | int index = *ptr++; |
| | 1407 | length += AAFontWidths[index]; |
| | 1408 | } |
| | 1409 | |
| | 1410 | x -= length; |
| | 1411 | } |
| | 1412 | break; |
| | 1413 | case MENUFORMAT_CENTREJUSTIFIED: |
| | 1414 | { |
| | 1415 | int length = 0; |
| | 1416 | const char *ptr = textPtr; |
| | 1417 | |
| | 1418 | while(*ptr) |
| | 1419 | { |
| | 1420 | int index = *ptr++; |
| | 1421 | length+=AAFontWidths[index]; |
| | 1422 | } |
| | 1423 | |
| | 1424 | x -= length/2; |
| | 1425 | } |
| | 1426 | break; |
| | 1427 | default: |
| | 1428 | fprintf(stderr, "RenderSmallMenuText: UNKNOWN TEXT FORMAT\n"); |
| | 1429 | exit(4); |
| | 1430 | } |
| | 1431 | |
| | 1432 | //assert(x > 0); |
| | 1433 | |
| | 1434 | { |
| | 1435 | unsigned int colour = alpha >> 8; |
| | 1436 | |
| | 1437 | if (colour > 255) |
| | 1438 | colour = 255; |
| | 1439 | |
| | 1440 | colour = (colour << 24) + 0xffffff; |
| | 1441 | |
| | 1442 | RenderHUDString(textPtr, x, y, colour); |
| | 1443 | } |
| | 1444 | |
| | 1445 | return x; |
| | 1446 | } |
| | 1447 | |
| | 1448 | int RenderSmallMenuText_Coloured(const char *textPtr, int x, int y, int alpha, enum MENUFORMAT_ID format, int red, int green, int blue) |
| | 1449 | { |
| | 1450 | switch(format) |
| | 1451 | { |
| | 1452 | case MENUFORMAT_LEFTJUSTIFIED: |
| | 1453 | // supplied x is correct |
| | 1454 | break; |
| | 1455 | case MENUFORMAT_RIGHTJUSTIFIED: |
| | 1456 | { |
| | 1457 | int length = 0; |
| | 1458 | const char *ptr = textPtr; |
| | 1459 | |
| | 1460 | while(*ptr) |
| | 1461 | { |
| | 1462 | int index = *ptr++; |
| | 1463 | length+=AAFontWidths[index]; |
| | 1464 | } |
| | 1465 | |
| | 1466 | x -= length; |
| | 1467 | } |
| | 1468 | break; |
| | 1469 | case MENUFORMAT_CENTREJUSTIFIED: |
| | 1470 | { |
| | 1471 | int length = 0; |
| | 1472 | const char *ptr = textPtr; |
| | 1473 | |
| | 1474 | while(*ptr) |
| | 1475 | { |
| | 1476 | int index = *ptr++; |
| | 1477 | length+=AAFontWidths[index]; |
| | 1478 | } |
| | 1479 | |
| | 1480 | x -= length/2; |
| | 1481 | } |
| | 1482 | break; |
| | 1483 | default: |
| | 1484 | fprintf(stderr, "RenderSmallMenuText_Coloured: UNKNOWN TEXT FORMAT\n"); |
| | 1485 | exit(3); |
| | 1486 | } |
| | 1487 | |
| | 1488 | { |
| | 1489 | unsigned int colour = alpha>>8; |
| | 1490 | |
| | 1491 | if (colour>255) |
| | 1492 | colour = 255; |
| | 1493 | |
| | 1494 | colour = (colour<<24); |
| | 1495 | colour += MUL_FIXED(red,255)<<16; |
| | 1496 | colour += MUL_FIXED(green,255)<<8; |
| | 1497 | colour += MUL_FIXED(blue,255); |
| | 1498 | RenderHUDString(textPtr,x,y,colour); |
| | 1499 | } |
| | 1500 | |
| | 1501 | return x; |
| | 1502 | } |
| | 1503 | |
| | 1504 | void DrawRectangle(int x, int y, int w, int h, int alpha) |
| | 1505 | { |
| | 1506 | struct VertexTag quadVertices[4]; |
| | 1507 | unsigned int colour = alpha>>8; |
| | 1508 | |
| | 1509 | if (colour > 255) |
| | 1510 | colour = 255; |
| | 1511 | |
| | 1512 | colour = (colour << 24) + 0xffffff; |
| | 1513 | |
| | 1514 | quadVertices[0].Y = y; |
| | 1515 | quadVertices[1].Y = y; |
| | 1516 | quadVertices[2].Y = y + 6; |
| | 1517 | quadVertices[3].Y = y + 6; |
| | 1518 | |
| | 1519 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_OFF); |
| | 1520 | /* top left corner */ |
| | 1521 | { |
| | 1522 | int topLeftU = 1; |
| | 1523 | int topLeftV = 238; |
| | 1524 | |
| | 1525 | quadVertices[0].U = topLeftU; |
| | 1526 | quadVertices[0].V = topLeftV; |
| | 1527 | quadVertices[1].U = topLeftU + 6; |
| | 1528 | quadVertices[1].V = topLeftV; |
| | 1529 | quadVertices[2].U = topLeftU + 6; |
| | 1530 | quadVertices[2].V = topLeftV + 6; |
| | 1531 | quadVertices[3].U = topLeftU; |
| | 1532 | quadVertices[3].V = topLeftV + 6; |
| | 1533 | |
| | 1534 | quadVertices[0].X = x; |
| | 1535 | quadVertices[3].X = x; |
| | 1536 | quadVertices[1].X = x + 6; |
| | 1537 | quadVertices[2].X = x + 6; |
| | 1538 | |
| | 1539 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1540 | } |
| | 1541 | /* top */ |
| | 1542 | { |
| | 1543 | int topLeftU = 9; |
| | 1544 | int topLeftV = 238; |
| | 1545 | |
| | 1546 | quadVertices[0].U = topLeftU; |
| | 1547 | quadVertices[0].V = topLeftV; |
| | 1548 | quadVertices[1].U = topLeftU; |
| | 1549 | quadVertices[1].V = topLeftV; |
| | 1550 | quadVertices[2].U = topLeftU; |
| | 1551 | quadVertices[2].V = topLeftV + 6; |
| | 1552 | quadVertices[3].U = topLeftU; |
| | 1553 | quadVertices[3].V = topLeftV + 6; |
| | 1554 | |
| | 1555 | quadVertices[0].X = x+6; |
| | 1556 | quadVertices[3].X = x+6; |
| | 1557 | quadVertices[1].X = x+6 + w-12; |
| | 1558 | quadVertices[2].X = x+6 + w-12; |
| | 1559 | |
| | 1560 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1561 | } |
| | 1562 | /* top right corner */ |
| | 1563 | { |
| | 1564 | int topLeftU = 11; |
| | 1565 | int topLeftV = 238; |
| | 1566 | |
| | 1567 | quadVertices[0].U = topLeftU; |
| | 1568 | quadVertices[0].V = topLeftV; |
| | 1569 | quadVertices[1].U = topLeftU + 6; |
| | 1570 | quadVertices[1].V = topLeftV; |
| | 1571 | quadVertices[2].U = topLeftU + 6; |
| | 1572 | quadVertices[2].V = topLeftV + 6; |
| | 1573 | quadVertices[3].U = topLeftU; |
| | 1574 | quadVertices[3].V = topLeftV + 6; |
| | 1575 | |
| | 1576 | quadVertices[0].X = x + w - 6; |
| | 1577 | quadVertices[3].X = x + w - 6; |
| | 1578 | quadVertices[1].X = x + w; |
| | 1579 | quadVertices[2].X = x + w; |
| | 1580 | |
| | 1581 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1582 | } |
| | 1583 | quadVertices[0].Y = y + 6; |
| | 1584 | quadVertices[1].Y = y + 6; |
| | 1585 | quadVertices[2].Y = y + h - 6; |
| | 1586 | quadVertices[3].Y = y + h - 6; |
| | 1587 | /* right */ |
| | 1588 | { |
| | 1589 | int topLeftU = 1; |
| | 1590 | int topLeftV = 246; |
| | 1591 | |
| | 1592 | quadVertices[0].U = topLeftU; |
| | 1593 | quadVertices[0].V = topLeftV; |
| | 1594 | quadVertices[1].U = topLeftU + 6; |
| | 1595 | quadVertices[1].V = topLeftV; |
| | 1596 | quadVertices[2].U = topLeftU + 6; |
| | 1597 | quadVertices[2].V = topLeftV; |
| | 1598 | quadVertices[3].U = topLeftU; |
| | 1599 | quadVertices[3].V = topLeftV; |
| | 1600 | |
| | 1601 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1602 | } |
| | 1603 | /* left */ |
| | 1604 | { |
| | 1605 | int topLeftU = 1; |
| | 1606 | int topLeftV = 246; |
| | 1607 | |
| | 1608 | quadVertices[0].U = topLeftU; |
| | 1609 | quadVertices[0].V = topLeftV; |
| | 1610 | quadVertices[1].U = topLeftU + 6; |
| | 1611 | quadVertices[1].V = topLeftV; |
| | 1612 | quadVertices[2].U = topLeftU + 6; |
| | 1613 | quadVertices[2].V = topLeftV; |
| | 1614 | quadVertices[3].U = topLeftU; |
| | 1615 | quadVertices[3].V = topLeftV; |
| | 1616 | |
| | 1617 | quadVertices[0].X = x; |
| | 1618 | quadVertices[3].X = x; |
| | 1619 | quadVertices[1].X = x + 6; |
| | 1620 | quadVertices[2].X = x + 6; |
| | 1621 | |
| | 1622 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1623 | } |
| | 1624 | quadVertices[0].Y = y + h - 6; |
| | 1625 | quadVertices[1].Y = y + h - 6; |
| | 1626 | quadVertices[2].Y = y + h; |
| | 1627 | quadVertices[3].Y = y + h; |
| | 1628 | /* bottom left corner */ |
| | 1629 | { |
| | 1630 | int topLeftU = 1; |
| | 1631 | int topLeftV = 248; |
| | 1632 | |
| | 1633 | quadVertices[0].U = topLeftU; |
| | 1634 | quadVertices[0].V = topLeftV; |
| | 1635 | quadVertices[1].U = topLeftU + 6; |
| | 1636 | quadVertices[1].V = topLeftV; |
| | 1637 | quadVertices[2].U = topLeftU + 6; |
| | 1638 | quadVertices[2].V = topLeftV + 6; |
| | 1639 | quadVertices[3].U = topLeftU; |
| | 1640 | quadVertices[3].V = topLeftV + 6; |
| | 1641 | |
| | 1642 | quadVertices[0].X = x; |
| | 1643 | quadVertices[3].X = x; |
| | 1644 | quadVertices[1].X = x + 6; |
| | 1645 | quadVertices[2].X = x + 6; |
| | 1646 | |
| | 1647 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1648 | } |
| | 1649 | /* bottom */ |
| | 1650 | { |
| | 1651 | int topLeftU = 9; |
| | 1652 | int topLeftV = 238; |
| | 1653 | |
| | 1654 | quadVertices[0].U = topLeftU; |
| | 1655 | quadVertices[0].V = topLeftV; |
| | 1656 | quadVertices[1].U = topLeftU; |
| | 1657 | quadVertices[1].V = topLeftV; |
| | 1658 | quadVertices[2].U = topLeftU; |
| | 1659 | quadVertices[2].V = topLeftV + 6; |
| | 1660 | quadVertices[3].U = topLeftU; |
| | 1661 | quadVertices[3].V = topLeftV + 6; |
| | 1662 | |
| | 1663 | quadVertices[0].X = x+6; |
| | 1664 | quadVertices[3].X = x+6; |
| | 1665 | quadVertices[1].X = x+6 + w-12; |
| | 1666 | quadVertices[2].X = x+6 + w-12; |
| | 1667 | |
| | 1668 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1669 | } |
| | 1670 | /* bottom right corner */ |
| | 1671 | { |
| | 1672 | int topLeftU = 11; |
| | 1673 | int topLeftV = 248; |
| | 1674 | |
| | 1675 | quadVertices[0].U = topLeftU; |
| | 1676 | quadVertices[0].V = topLeftV; |
| | 1677 | quadVertices[1].U = topLeftU + 6; |
| | 1678 | quadVertices[1].V = topLeftV; |
| | 1679 | quadVertices[2].U = topLeftU + 6; |
| | 1680 | quadVertices[2].V = topLeftV + 6; |
| | 1681 | quadVertices[3].U = topLeftU; |
| | 1682 | quadVertices[3].V = topLeftV + 6; |
| | 1683 | |
| | 1684 | quadVertices[0].X = x + w - 6; |
| | 1685 | quadVertices[3].X = x + w - 6; |
| | 1686 | quadVertices[1].X = x + w; |
| | 1687 | quadVertices[2].X = x + w; |
| | 1688 | |
| | 1689 | HUDQuad_Output(AAFontImageNumber, quadVertices, colour); |
| | 1690 | } |
| | 1691 | } |
| | 1692 | |
| | 1693 | void DrawSliderBar(int x, int y, int alpha) |
| | 1694 | { |
| | 1695 | struct VertexTag quadVertices[4]; |
| | 1696 | int sliderHeight = 11; |
| | 1697 | unsigned int colour = alpha>>8; |
| | 1698 | |
| | 1699 | if (colour > 255) |
| | 1700 | colour = 255; |
| | 1701 | |
| | 1702 | colour = (colour << 24)+0xffffff; |
| | 1703 | |
| | 1704 | quadVertices[0].Y = y; |
| | 1705 | quadVertices[1].Y = y; |
| | 1706 | quadVertices[2].Y = y + sliderHeight; |
| | 1707 | quadVertices[3].Y = y + sliderHeight; |
| | 1708 | |
| | 1709 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_OFF); |
| | 1710 | { |
| | 1711 | int topLeftU = 1; |
| | 1712 | int topLeftV = 68; |
| | 1713 | |
| | 1714 | quadVertices[0].U = topLeftU; |
| | 1715 | quadVertices[0].V = topLeftV; |
| | 1716 | quadVertices[1].U = topLeftU + 2; |
| | 1717 | quadVertices[1].V = topLeftV; |
| | 1718 | quadVertices[2].U = topLeftU + 2; |
| | 1719 | quadVertices[2].V = topLeftV + sliderHeight; |
| | 1720 | quadVertices[3].U = topLeftU; |
| | 1721 | quadVertices[3].V = topLeftV + sliderHeight; |
| | 1722 | |
| | 1723 | quadVertices[0].X = x; |
| | 1724 | quadVertices[3].X = x; |
| | 1725 | quadVertices[1].X = x + 2; |
| | 1726 | quadVertices[2].X = x + 2; |
| | 1727 | |
| | 1728 | HUDQuad_Output(HUDFontsImageNumber, quadVertices, colour ); |
| | 1729 | } |
| | 1730 | { |
| | 1731 | int topLeftU = 7; |
| | 1732 | int topLeftV = 68; |
| | 1733 | |
| | 1734 | quadVertices[0].U = topLeftU; |
| | 1735 | quadVertices[0].V = topLeftV; |
| | 1736 | quadVertices[1].U = topLeftU + 2; |
| | 1737 | quadVertices[1].V = topLeftV; |
| | 1738 | quadVertices[2].U = topLeftU + 2; |
| | 1739 | quadVertices[2].V = topLeftV + sliderHeight; |
| | 1740 | quadVertices[3].U = topLeftU; |
| | 1741 | quadVertices[3].V = topLeftV + sliderHeight; |
| | 1742 | |
| | 1743 | quadVertices[0].X = x+213+2; |
| | 1744 | quadVertices[3].X = x+213+2; |
| | 1745 | quadVertices[1].X = x+2 +213+2; |
| | 1746 | quadVertices[2].X = x+2 +213+2; |
| | 1747 | |
| | 1748 | HUDQuad_Output(HUDFontsImageNumber, quadVertices, colour ); |
| | 1749 | } |
| | 1750 | quadVertices[2].Y = y + 2; |
| | 1751 | quadVertices[3].Y = y + 2; |
| | 1752 | |
| | 1753 | { |
| | 1754 | int topLeftU = 5; |
| | 1755 | int topLeftV = 77; |
| | 1756 | |
| | 1757 | quadVertices[0].U = topLeftU; |
| | 1758 | quadVertices[0].V = topLeftV; |
| | 1759 | quadVertices[1].U = topLeftU; |
| | 1760 | quadVertices[1].V = topLeftV; |
| | 1761 | quadVertices[2].U = topLeftU; |
| | 1762 | quadVertices[2].V = topLeftV + 2; |
| | 1763 | quadVertices[3].U = topLeftU; |
| | 1764 | quadVertices[3].V = topLeftV + 2; |
| | 1765 | |
| | 1766 | quadVertices[0].X = x + 2; |
| | 1767 | quadVertices[3].X = x + 2; |
| | 1768 | quadVertices[1].X = x + 215; |
| | 1769 | quadVertices[2].X = x + 215; |
| | 1770 | |
| | 1771 | HUDQuad_Output(HUDFontsImageNumber, quadVertices, colour ); |
| | 1772 | } |
| | 1773 | quadVertices[0].Y = y + 9; |
| | 1774 | quadVertices[1].Y = y + 9; |
| | 1775 | quadVertices[2].Y = y + 11; |
| | 1776 | quadVertices[3].Y = y + 11; |
| | 1777 | |
| | 1778 | { |
| | 1779 | int topLeftU = 5; |
| | 1780 | int topLeftV = 77; |
| | 1781 | |
| | 1782 | quadVertices[0].U = topLeftU; |
| | 1783 | quadVertices[0].V = topLeftV; |
| | 1784 | quadVertices[1].U = topLeftU; |
| | 1785 | quadVertices[1].V = topLeftV; |
| | 1786 | quadVertices[2].U = topLeftU; |
| | 1787 | quadVertices[2].V = topLeftV + 2; |
| | 1788 | quadVertices[3].U = topLeftU; |
| | 1789 | quadVertices[3].V = topLeftV + 2; |
| | 1790 | |
| | 1791 | quadVertices[0].X = x + 2; |
| | 1792 | quadVertices[3].X = x + 2; |
| | 1793 | quadVertices[1].X = x + 215; |
| | 1794 | quadVertices[2].X = x + 215; |
| | 1795 | |
| | 1796 | HUDQuad_Output(HUDFontsImageNumber, quadVertices, colour ); |
| | 1797 | } |
| | 1798 | } |
| | 1799 | |
| | 1800 | void DrawSlider(int x, int y, int alpha) |
| | 1801 | { |
| | 1802 | struct VertexTag quadVertices[4]; |
| | 1803 | int sliderHeight = 5; |
| | 1804 | unsigned int colour = alpha>>8; |
| | 1805 | |
| | 1806 | if (colour > 255) |
| | 1807 | colour = 255; |
| | 1808 | |
| | 1809 | colour = (colour << 24) + 0xffffff; |
| | 1810 | |
| | 1811 | quadVertices[0].Y = y; |
| | 1812 | quadVertices[1].Y = y; |
| | 1813 | quadVertices[2].Y = y + sliderHeight; |
| | 1814 | quadVertices[3].Y = y + sliderHeight; |
| | 1815 | |
| | 1816 | CheckFilteringModeIsCorrect(FILTERING_BILINEAR_OFF); |
| | 1817 | |
| | 1818 | { |
| | 1819 | int topLeftU = 11; |
| | 1820 | int topLeftV = 74; |
| | 1821 | |
| | 1822 | quadVertices[0].U = topLeftU; |
| | 1823 | quadVertices[0].V = topLeftV; |
| | 1824 | quadVertices[1].U = topLeftU + 9; |
| | 1825 | quadVertices[1].V = topLeftV; |
| | 1826 | quadVertices[2].U = topLeftU + 9; |
| | 1827 | quadVertices[2].V = topLeftV + sliderHeight; |
| | 1828 | quadVertices[3].U = topLeftU; |
| | 1829 | quadVertices[3].V = topLeftV + sliderHeight; |
| | 1830 | |
| | 1831 | quadVertices[0].X = x; |
| | 1832 | quadVertices[3].X = x; |
| | 1833 | quadVertices[1].X = x + 9; |
| | 1834 | quadVertices[2].X = x + 9; |
| | 1835 | |
| | 1836 | HUDQuad_Output(HUDFontsImageNumber, quadVertices, colour ); |
| | 1837 | } |
| | 1838 | } |
| | 1839 | |
| | 1840 | void DrawColourBar(int yTop, int yBottom, int rScale, int gScale, int bScale) |
| | 1841 | { |
| | 1842 | GLfloat x[4], y[4]; |
| | 1843 | int i; |
| | 1844 | |
| | 1845 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_OFF); |
| | 1846 | CheckBoundTextureIsCorrect(NULL); |
| | 1847 | |
| | 1848 | glBegin(GL_QUADS); |
| | 1849 | for (i = 0; i < 255; ) |
| | 1850 | { |
| | 1851 | unsigned int c = GammaValues[i]; |
| | 1852 | |
| | 1853 | glColor4ub(MUL_FIXED(c, rScale), MUL_FIXED(c,gScale), MUL_FIXED(c,bScale), 0); |
| | 1854 | |
| | 1855 | x[0] = (ScreenDescriptorBlock.SDB_Width * i)/255; |
| | 1856 | x[0] = (x[0] - ScreenDescriptorBlock.SDB_CentreX) / ScreenDescriptorBlock.SDB_CentreX; |
| | 1857 | y[0] = yTop; |
| | 1858 | y[0] = -(y[0] - ScreenDescriptorBlock.SDB_CentreY) / ScreenDescriptorBlock.SDB_CentreY; |
| | 1859 | |
| | 1860 | x[1] = (ScreenDescriptorBlock.SDB_Width * i)/255; |
| | 1861 | x[1] = (x[1] - ScreenDescriptorBlock.SDB_CentreX) / ScreenDescriptorBlock.SDB_CentreX; |
| | 1862 | y[1] = yBottom; |
| | 1863 | y[1] = -(y[1] - ScreenDescriptorBlock.SDB_CentreY) / ScreenDescriptorBlock.SDB_CentreY; |
| | 1864 | |
| | 1865 | i++; |
| | 1866 | c = GammaValues[i]; |
| | 1867 | |
| | 1868 | glColor4ub(MUL_FIXED(c,rScale), MUL_FIXED(c,gScale), MUL_FIXED(c,bScale), 0); |
| | 1869 | |
| | 1870 | x[2] = (ScreenDescriptorBlock.SDB_Width * i)/255; |
| | 1871 | x[2] = (x[2] - ScreenDescriptorBlock.SDB_CentreX) / ScreenDescriptorBlock.SDB_CentreX; |
| | 1872 | y[2] = yBottom; |
| | 1873 | y[2] = -(y[2] - ScreenDescriptorBlock.SDB_CentreY) / ScreenDescriptorBlock.SDB_CentreY; |
| | 1874 | |
| | 1875 | x[3] = (ScreenDescriptorBlock.SDB_Width * i)/255; |
| | 1876 | x[3] = (x[3] - ScreenDescriptorBlock.SDB_CentreX) / ScreenDescriptorBlock.SDB_CentreX; |
| | 1877 | y[3] = yTop; |
| | 1878 | y[3] = -(y[3] - ScreenDescriptorBlock.SDB_CentreY) / ScreenDescriptorBlock.SDB_CentreY; |
| | 1879 | |
| | 1880 | glVertex3f(x[0], y[0], -1.0f); |
| | 1881 | glVertex3f(x[1], y[1], -1.0f); |
| | 1882 | glVertex3f(x[2], y[2], -1.0f); |
| | 1883 | glVertex3f(x[3], y[3], -1.0f); |
| | 1884 | } |
| | 1885 | glEnd(); |
| | 1886 | } |
| | 1887 | |
| | 1888 | void DrawParticle_Rain(PARTICLE *particlePtr, VECTORCH *prevPositionPtr) |
| | 1889 | { |
| | 1890 | VECTORCH vertices[3]; |
| | 1891 | |
| | 1892 | vertices[0] = *prevPositionPtr; |
| | 1893 | |
| | 1894 | /* translate second vertex into view space */ |
| | 1895 | TranslatePointIntoViewspace(&vertices[0]); |
| | 1896 | |
| | 1897 | /* is particle within normal view frustrum ? */ |
| | 1898 | if((-vertices[0].vx <= vertices[0].vz) |
| | 1899 | &&(vertices[0].vx <= vertices[0].vz) |
| | 1900 | &&(-vertices[0].vy <= vertices[0].vz) |
| | 1901 | &&(vertices[0].vy <= vertices[0].vz)) |
| | 1902 | { |
| | 1903 | vertices[1] = particlePtr->Position; |
| | 1904 | vertices[2] = particlePtr->Position; |
| | 1905 | vertices[1].vx += particlePtr->Offset.vx; |
| | 1906 | vertices[2].vx -= particlePtr->Offset.vx; |
| | 1907 | vertices[1].vz += particlePtr->Offset.vz; |
| | 1908 | vertices[2].vz -= particlePtr->Offset.vz; |
| | 1909 | |
| | 1910 | /* translate particle into view space */ |
| | 1911 | TranslatePointIntoViewspace(&vertices[1]); |
| | 1912 | TranslatePointIntoViewspace(&vertices[2]); |
| | 1913 | |
| | 1914 | CheckTriangleBuffer(3, 0, 0, NULL, TRANSLUCENCY_NORMAL); |
| | 1915 | |
| | 1916 | int i; |
| | 1917 | for (i = 0; i < 3; i++) |
| | 1918 | { |
| | 1919 | float zvalue = vertices[i].vz; |
| | 1920 | float rhw = 1.0f / zvalue; |
| | 1921 | float zf = 1.0f - ZNear / zvalue; |
| | 1922 | |
| | 1923 | GLfloat xf = ((float)vertices[i].vx * (Global_VDB.VDB_ProjX + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 1924 | GLfloat yf = -((float)vertices[i].vy * (Global_VDB.VDB_ProjY + 1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 1925 | |
| | 1926 | |
| | 1927 | varrp->v[0] = xf / rhw; |
| | 1928 | varrp->v[1] = yf / rhw; |
| | 1929 | varrp->v[2] = zf / rhw; |
| | 1930 | varrp->v[3] = 1.0f / rhw; |
| | 1931 | |
| | 1932 | varrp->c[0] = i ? 255 : 0; |
| | 1933 | varrp->c[1] = 255; |
| | 1934 | varrp->c[2] = 255; |
| | 1935 | varrp->c[3] = 32; |
| | 1936 | |
| | 1937 | varrp++; |
| | 1938 | varrc++; |
| | 1939 | } |
| | 1940 | } |
| | 1941 | } |
| | 1942 | |
| | 1943 | void DrawWaterFall(int xOrigin, int yOrigin, int zOrigin) |
| | 1944 | { |
| | 1945 | int i; |
| | 1946 | |
| | 1947 | int noRequired = MUL_FIXED(250, NormalFrameTime); |
| | 1948 | |
| | 1949 | for (i=0; i < noRequired; i++) |
| | 1950 | { |
| | 1951 | VECTORCH velocity; |
| | 1952 | VECTORCH position; |
| | 1953 | position.vx = xOrigin; |
| | 1954 | position.vy = yOrigin-(FastRandom()&511);//+45*MeshXScale; |
| | 1955 | position.vz = zOrigin+(FastRandom()%(15*MeshZScale)); |
| | 1956 | |
| | 1957 | velocity.vy = (FastRandom()&511)+512;//-((FastRandom()&1023)+2048)*8; |
| | 1958 | velocity.vx = ((FastRandom()&511)+256)*2; |
| | 1959 | velocity.vz = 0;//-((FastRandom()&511))*8; |
| | 1960 | MakeParticle(&position, &velocity, PARTICLE_WATERFALLSPRAY); |
| | 1961 | } |
| | 1962 | } |
| | 1963 | |
| | 1964 | static void DrawMoltenMetalMesh_Unclipped() |
| | 1965 | { |
| | 1966 | VECTORCH *point = MeshVertex; |
| | 1967 | VECTORCH *pointWS = MeshWorldVertex; |
| | 1968 | |
| | 1969 | int i, x, y; |
| | 1970 | int start; |
| | 1971 | |
| | 1972 | CheckTriangleBuffer(256, 0, 450, (struct TEXTURE *)-1, TRANSLUCENCY_NOT_SET); |
| | 1973 | |
| | 1974 | start = varrc; |
| | 1975 | |
| | 1976 | for (i=0; i < 256; i++) |
| | 1977 | { |
| | 1978 | GLfloat xf, yf, zf; |
| | 1979 | GLfloat sf, tf, rhw; |
| | 1980 | int r, g, b, a; |
| | 1981 | float zvalue; |
| | 1982 | |
| | 1983 | if (point->vz < 1) |
| | 1984 | point->vz = 1; |
| | 1985 | |
| | 1986 | zvalue = point->vz; |
| | 1987 | |
| | 1988 | xf = ((float)point->vx * (Global_VDB.VDB_ProjX +1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreX); |
| | 1989 | yf = -((float)point->vy * (Global_VDB.VDB_ProjY +1)) / (zvalue * ScreenDescriptorBlock.SDB_CentreY); |
| | 1990 | |
| | 1991 | rhw = 1.0f / zvalue; |
| | 1992 | zf = 1.0f - ZNear / zvalue; |
| | 1993 | |
| | 1994 | sf = pointWS->vx*WaterUScale+(1.0f/256.0f); |
| | 1995 | tf = pointWS->vy*WaterVScale+(1.0f/256.0f); |
| | 1996 | |
| | 1997 | b = (MeshVertexColour[i] >> 0) & 0xFF; |
| | 1998 | g = (MeshVertexColour[i] >> 8) & 0xFF; |
| | 1999 | r = (MeshVertexColour[i] >> 16) & 0xFF; |
| | 2000 | a = (MeshVertexColour[i] >> 24) & 0xFF; |
| | 2001 | |
| | 2002 | varrp->v[0] = xf/rhw; |
| | 2003 | varrp->v[1] = yf/rhw; |
| | 2004 | varrp->v[2] = zf/rhw; |
| | 2005 | varrp->v[3] = 1.0f/rhw; |
| | 2006 | |
| | 2007 | varrp->t[0] = sf; |
| | 2008 | varrp->t[1] = tf; |
| | 2009 | |
| | 2010 | varrp->c[0] = r; |
| | 2011 | varrp->c[1] = g; |
| | 2012 | varrp->c[2] = b; |
| | 2013 | varrp->c[3] = a; |
| | 2014 | |
| | 2015 | varrp++; |
| | 2016 | varrc++; |
| | 2017 | |
| | 2018 | point++; |
| | 2019 | pointWS++; |
| | 2020 | } |
| | 2021 | |
| | 2022 | /* CONSTRUCT POLYS */ |
| | 2023 | |
| | 2024 | for (x = 0; x < 15; x++) |
| | 2025 | { |
| | 2026 | for(y = 0; y < 15; y++) |
| | 2027 | { |
| | 2028 | tarrp[0].a = start+0+x+(16*y); |
| | 2029 | tarrp[0].b = start+1+x+(16*y); |
| | 2030 | tarrp[0].c = start+16+x+(16*y); |
| | 2031 | |
| | 2032 | tarrp[1].a = start+1+x+(16*y); |
| | 2033 | tarrp[1].b = start+17+x+(16*y); |
| | 2034 | tarrp[1].c = start+16+x+(16*y); |
| | 2035 | |
| | 2036 | tarrp += 2; |
| | 2037 | tarrc += 2; |
| | 2038 | } |
| | 2039 | } |
| | 2040 | } |
| | 2041 | |
| | 2042 | static void DrawWaterPatch(int xOrigin, int yOrigin, int zOrigin) |
| | 2043 | { |
| | 2044 | int i=0; |
| | 2045 | int x; |
| | 2046 | int offset; |
| | 2047 | |
| | 2048 | for (x=0; x < 16; x++) |
| | 2049 | { |
| | 2050 | int z; |
| | 2051 | for(z=0; z < 16; z++) |
| | 2052 | { |
| | 2053 | VECTORCH *point = &MeshVertex[i]; |
| | 2054 | |
| | 2055 | point->vx = xOrigin+(x*MeshXScale)/15; |
| | 2056 | point->vz = zOrigin+(z*MeshZScale)/15; |
| | 2057 | |
| | 2058 | offset = 0; |
| | 2059 | #if 1 |
| | 2060 | /* basic noise ripples */ |
| | 2061 | // offset = MUL_FIXED(32,GetSin( (point->vx+point->vz+CloakingPhase)&4095 ) ); |
| | 2062 | // offset += MUL_FIXED(16,GetSin( (point->vx-point->vz*2+CloakingPhase/2)&4095 ) ); |
| | 2063 | { |
| | 2064 | offset += EffectOfRipples(point); |
| | 2065 | } |
| | 2066 | #endif |
| | 2067 | // if (offset > 450) offset = 450; |
| | 2068 | // if (offset < -450) offset = -450; |
| | 2069 | point->vy = yOrigin+offset; |
| | 2070 | |
| | 2071 | { |
| | 2072 | int alpha = 128-offset/4; |
| | 2073 | // if (alpha > 255) alpha = 255; |
| | 2074 | // if (alpha < 128) alpha = 128; |
| | 2075 | |
| | 2076 | switch (PlayerStatus.VisionMode) |
| | 2077 | { |
| | 2078 | default: |
| | 2079 | case VISION_MODE_NORMAL: |
| | 2080 | { |
| | 2081 | // MeshVertexColour[i] = RGBA_MAKE(10,51,28,alpha); |
| | 2082 | MeshVertexColour[i] = RGBA_MAKE(255,255,255,alpha); |
| | 2083 | #if 0 |
| | 2084 | #if 1 |
| | 2085 | VECTORCH pos = {24087,yOrigin,39165}; |
| | 2086 | int c = (8191-VectorDistance(&pos,point)); |
| | 2087 | if (c < 0) c=0; |
| | 2088 | else |
| | 2089 | { |
| | 2090 | int s = GetSin((CloakingPhase/2)&4095); |
| | 2091 | s = MUL_FIXED(s,s)/64; |
| | 2092 | c = MUL_FIXED(s,c); |
| | 2093 | } |
| | 2094 | MeshVertexSpecular[i] = (c<<16)+(((c/4)<<8)&0xff00) + (c/4); |
| | 2095 | #else |
| | 2096 | if (!(FastRandom()&1023)) |
| | 2097 | MeshVertexSpecular[i] = 0xc04040; |
| | 2098 | else |
| | 2099 | MeshVertexSpecular[i] = 0; |
| | 2100 | #endif |
| | 2101 | #endif |
| | 2102 | break; |
| | 2103 | } |
| | 2104 | case VISION_MODE_IMAGEINTENSIFIER: |
| | 2105 | { |
| | 2106 | MeshVertexColour[i] = RGBA_MAKE(0,51,0,alpha); |
| | 2107 | break; |
| | 2108 | } |
| | 2109 | case VISION_MODE_PRED_THERMAL: |
| | 2110 | case VISION_MODE_PRED_SEEALIENS: |
| | 2111 | case VISION_MODE_PRED_SEEPREDTECH: |
| | 2112 | { |
| | 2113 | MeshVertexColour[i] = RGBA_MAKE(0,0,28,alpha); |
| | 2114 | break; |
| | 2115 | } |
| | 2116 | } |
| | 2117 | } |
| | 2118 | |
| | 2119 | #if 1 |
| | 2120 | MeshWorldVertex[i].vx = ((point->vx-WaterXOrigin)/4+MUL_FIXED(GetSin((point->vy*16)&4095),128)); |
| | 2121 | MeshWorldVertex[i].vy = ((point->vz-WaterZOrigin)/4+MUL_FIXED(GetSin((point->vy*16+200)&4095),128)); |
| | 2122 | #endif |
| | 2123 | |
| | 2124 | #if 1 |
| | 2125 | TranslatePointIntoViewspace(point); |
| | 2126 | #else |
| | 2127 | point->vx -= Global_VDB.VDB_World.vx; |
| | 2128 | point->vy -= Global_VDB.VDB_World.vy; |
| | 2129 | point->vz -= Global_VDB.VDB_World.vz; |
| | 2130 | RotateVector(point,&(Global_VDB.VDB_Mat)); |
| | 2131 | point->vy = MUL_FIXED(point->vy,87381); |
| | 2132 | |
| | 2133 | #endif |
| | 2134 | /* is particle within normal view frustrum ? */ |
| | 2135 | if(AvP.PlayerType == I_Alien) /* wide frustrum */ |
| | 2136 | { |
| | 2137 | if(( (-point->vx <= point->vz*2) |
| | 2138 | &&(point->vx <= point->vz*2) |
| | 2139 | &&(-point->vy <= point->vz*2) |
| | 2140 | &&(point->vy <= point->vz*2) )) |
| | 2141 | { |
| | 2142 | MeshVertexOutcode[i] = 1; |
| | 2143 | } |
| | 2144 | else |
| | 2145 | { |
| | 2146 | MeshVertexOutcode[i] = 0; |
| | 2147 | } |
| | 2148 | } |
| | 2149 | else |
| | 2150 | { |
| | 2151 | if(( (-point->vx <= point->vz) |
| | 2152 | &&(point->vx <= point->vz) |
| | 2153 | &&(-point->vy <= point->vz) |
| | 2154 | &&(point->vy <= point->vz) )) |
| | 2155 | { |
| | 2156 | MeshVertexOutcode[i] = 1; |
| | 2157 | } |
| | 2158 | else |
| | 2159 | { |
| | 2160 | MeshVertexOutcode[i] = 0; |
| | 2161 | } |
| | 2162 | } |
| | 2163 | |
| | 2164 | i++; |
| | 2165 | } |
| | 2166 | } |
| | 2167 | |
| | 2168 | DrawMoltenMetalMesh_Unclipped(); |
| | 2169 | } |
| | 2170 | |
| | 2171 | extern struct KObject VisibleModules[MAX_NUMBER_OF_VISIBLE_MODULES]; |
| | 2172 | extern int numVisMods; |
| | 2173 | |
| | 2174 | void PostLandscapeRendering() |
| | 2175 | { |
| | 2176 | int numOfModules = numVisMods; |
| | 2177 | |
| | 2178 | if(!strcmp(AvP.LevelName, "fall") || !strcmp(AvP.LevelName, "fall_m")) |
| | 2179 | { |
| | 2180 | char drawWaterFall = 0; |
| | 2181 | char drawStream = 0; |
| | 2182 | char drawStream2 = 0; |
| | 2183 | |
| | 2184 | while(numOfModules--) |
| | 2185 | { |
| | 2186 | DISPLAYBLOCK *objectPtr = VisibleModules[numOfModules].DispPtr; |
| | 2187 | MODULE *modulePtr = objectPtr->Module; |
| | 2188 | |
| | 2189 | if (modulePtr->name) |
| | 2190 | { |
| | 2191 | if( !strcmp(modulePtr->name,"fall01") |
| | 2192 | || !strcmp(modulePtr->name,"well01") |
| | 2193 | || !strcmp(modulePtr->name,"well02") |
| | 2194 | || !strcmp(modulePtr->name,"well03") |
| | 2195 | || !strcmp(modulePtr->name,"well04") |
| | 2196 | || !strcmp(modulePtr->name,"well05") |
| | 2197 | || !strcmp(modulePtr->name,"well06") |
| | 2198 | || !strcmp(modulePtr->name,"well07") |
| | 2199 | || !strcmp(modulePtr->name,"well08") |
| | 2200 | || !strcmp(modulePtr->name,"well")) |
| | 2201 | { |
| | 2202 | drawWaterFall = 1; |
| | 2203 | } |
| | 2204 | else if( !strcmp(modulePtr->name,"stream02") |
| | 2205 | || !strcmp(modulePtr->name,"stream03") |
| | 2206 | || !strcmp(modulePtr->name,"watergate")) |
| | 2207 | { |
| | 2208 | drawStream = 1; |
| | 2209 | } |
| | 2210 | else if( !strcmp(modulePtr->name,"openwat03") |
| | 2211 | || !strcmp(modulePtr->name,"openwat04") |
| | 2212 | || !strcmp(modulePtr->name,"openwat04A") |
| | 2213 | || !strcmp(modulePtr->name,"openwat02")) |
| | 2214 | { |
| | 2215 | drawStream2 = 1; |
| | 2216 | } |
| | 2217 | } |
| | 2218 | } |
| | 2219 | |
| | 2220 | if (drawWaterFall) |
| | 2221 | { |
| | 2222 | // CurrTextureHandle = NULL; |
| | 2223 | // CheckBoundTextureIsCorrect(NULL); |
| | 2224 | // CheckTranslucencyModeIsCorrect(TRANSLUCENCY_NORMAL); |
| | 2225 | |
| | 2226 | FlushTriangleBuffers(1); |
| | 2227 | glDepthMask(GL_FALSE); |
| | 2228 | |
| | 2229 | WaterFallBase = 109952; |
| | 2230 | |
| | 2231 | MeshZScale = (66572-51026)/15; |
| | 2232 | MeshXScale = (109952+3039)/45; |
| | 2233 | |
| | 2234 | DrawWaterFall(175545,-3039,51026); |
| | 2235 | // MeshZScale = -(538490-392169); |
| | 2236 | // MeshXScale = 55000; |
| | 2237 | // DrawWaterPatch(-100000, WaterFallBase, 538490); |
| | 2238 | |
| | 2239 | FlushTriangleBuffers(1); |
| | 2240 | glDepthMask(GL_TRUE); |
| | 2241 | } |
| | 2242 | |
| | 2243 | if (drawStream) |
| | 2244 | { |
| | 2245 | int x = 68581; |
| | 2246 | int y = 12925; // probably should lower this a little.. |
| | 2247 | int z = 93696; |
| | 2248 | MeshXScale = (87869-68581); |
| | 2249 | MeshZScale = (105385-93696); |
| | 2250 | CheckForObjectsInWater(x, x+MeshXScale, z, z+MeshZScale, y); |
| | 2251 | |
| | 2252 | WaterXOrigin=x; |
| | 2253 | WaterZOrigin=z; |
| | 2254 | WaterUScale = 4.0f/(float)MeshXScale; |
| | 2255 | WaterVScale = 4.0f/(float)MeshZScale; |
| | 2256 | MeshXScale/=4; |
| | 2257 | MeshZScale/=2; |
| | 2258 | |
| | 2259 | CurrTextureHandle = ImageHeaderArray[ChromeImageNumber].Texture; |
| | 2260 | CheckTriangleBuffer(0, 0, 0, CurrTextureHandle, TRANSLUCENCY_NORMAL); |
| | 2261 | |
| | 2262 | DrawWaterPatch(x, y, z); |
| | 2263 | DrawWaterPatch(x+MeshXScale, y, z); |
| | 2264 | DrawWaterPatch(x+MeshXScale*2, y, z); |
| | 2265 | DrawWaterPatch(x+MeshXScale*3, y, z); |
| | 2266 | DrawWaterPatch(x, y, z+MeshZScale); |
| | 2267 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale); |
| | 2268 | DrawWaterPatch(x+MeshXScale*2, y, z+MeshZScale); |
| | 2269 | DrawWaterPatch(x+MeshXScale*3, y, z+MeshZScale); |
| | 2270 | } |
| | 2271 | |
| | 2272 | #if 0 // added, but then disabled (too squishy) |
| | 2273 | if (drawStream2) |
| | 2274 | { |
| | 2275 | int x = 217400; |
| | 2276 | int y = 20750; |
| | 2277 | int z = 54000; |
| | 2278 | MeshXScale = (87869-68581); |
| | 2279 | MeshZScale = (105385-93696); |
| | 2280 | |
| | 2281 | CheckForObjectsInWater(x, x+MeshXScale, z, z+MeshZScale, y); |
| | 2282 | |
| | 2283 | WaterXOrigin=x; |
| | 2284 | WaterZOrigin=z; |
| | 2285 | WaterUScale = 4.0f/(float)MeshXScale; |
| | 2286 | WaterVScale = 4.0f/(float)MeshZScale; |
| | 2287 | MeshXScale/=4; |
| | 2288 | MeshZScale/=2; |
| | 2289 | |
| | 2290 | CurrTextureHandle = ImageHeaderArray[ChromeImageNumber].Texture; |
| | 2291 | CheckTriangleBuffer(0, 0, 0, CurrTextureHandle, TRANSLUCENCY_NORMAL); |
| | 2292 | |
| | 2293 | DrawWaterPatch(x, y, z); |
| | 2294 | DrawWaterPatch(x+MeshXScale, y, z); |
| | 2295 | DrawWaterPatch(x+MeshXScale*2, y, z); |
| | 2296 | DrawWaterPatch(x+MeshXScale*3, y, z); |
| | 2297 | DrawWaterPatch(x, y, z+MeshZScale); |
| | 2298 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale); |
| | 2299 | DrawWaterPatch(x+MeshXScale*2, y, z+MeshZScale); |
| | 2300 | DrawWaterPatch(x+MeshXScale*3, y, z+MeshZScale); |
| | 2301 | } |
| | 2302 | #endif |
| | 2303 | } |
| | 2304 | else if(!strcmp(AvP.LevelName, "invasion_a")) // || !strcmp(AvP.LevelName, "invasion") || !strcmp(AvP.LevelName,
"invasion_p")) |
| | 2305 | { |
| | 2306 | char drawWater = 0; |
| | 2307 | char drawEndWater = 0; |
| | 2308 | |
| | 2309 | while(numOfModules--) |
| | 2310 | { |
| | 2311 | DISPLAYBLOCK *objectPtr = VisibleModules[numOfModules].DispPtr; |
| | 2312 | MODULE *modulePtr = objectPtr->Module; |
| | 2313 | |
| | 2314 | // if it's a module, which isn't inside another module |
| | 2315 | if (modulePtr->name) |
| | 2316 | { |
| | 2317 | if( !strcmp(modulePtr->name,"hivepool") || !strcmp(modulePtr->name,"hivepool04")) |
| | 2318 | { |
| | 2319 | drawWater = 1; |
| | 2320 | break; |
| | 2321 | } |
| | 2322 | else |
| | 2323 | { |
| | 2324 | if(!strcmp(modulePtr->name,"shaftbot")) |
| | 2325 | { |
| | 2326 | drawEndWater = 1; |
| | 2327 | } |
| | 2328 | if( !strcasecmp(modulePtr->name,"shaft01") |
| | 2329 | || !strcasecmp(modulePtr->name,"shaft02") |
| | 2330 | || !strcasecmp(modulePtr->name,"shaft03") |
| | 2331 | || !strcasecmp(modulePtr->name,"shaft04") |
| | 2332 | || !strcasecmp(modulePtr->name,"shaft05") |
| | 2333 | || !strcasecmp(modulePtr->name,"shaft06")) |
| | 2334 | { |
| | 2335 | HandleRainShaft(modulePtr, -11726,-107080,10); |
| | 2336 | drawEndWater = 1; |
| | 2337 | break; |
| | 2338 | } |
| | 2339 | } |
| | 2340 | } |
| | 2341 | } |
| | 2342 | |
| | 2343 | if (drawWater) |
| | 2344 | { |
| | 2345 | int x = 20767; |
| | 2346 | int y = -36000+200; |
| | 2347 | int z = 30238; |
| | 2348 | MeshXScale = (36353-20767); |
| | 2349 | MeshZScale = (41927-30238); |
| | 2350 | |
| | 2351 | CheckForObjectsInWater(x, x+MeshXScale, z, z+MeshZScale, y); |
| | 2352 | |
| | 2353 | WaterXOrigin=x; |
| | 2354 | WaterZOrigin=z; |
| | 2355 | WaterUScale = 4.0f/(float)MeshXScale; |
| | 2356 | WaterVScale = 4.0f/(float)MeshZScale; |
| | 2357 | MeshXScale/=4; |
| | 2358 | MeshZScale/=2; |
| | 2359 | |
| | 2360 | CurrTextureHandle = ImageHeaderArray[ChromeImageNumber].Texture; |
| | 2361 | CheckTriangleBuffer(0, 0, 0, CurrTextureHandle, TRANSLUCENCY_NORMAL); |
| | 2362 | DrawWaterPatch(x, y, z); |
| | 2363 | DrawWaterPatch(x+MeshXScale, y, z); |
| | 2364 | DrawWaterPatch(x+MeshXScale*2, y, z); |
| | 2365 | DrawWaterPatch(x+MeshXScale*3, y, z); |
| | 2366 | DrawWaterPatch(x, y, z+MeshZScale); |
| | 2367 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale); |
| | 2368 | DrawWaterPatch(x+MeshXScale*2, y, z+MeshZScale); |
| | 2369 | DrawWaterPatch(x+MeshXScale*3, y, z+MeshZScale); |
| | 2370 | } |
| | 2371 | else if (drawEndWater) |
| | 2372 | { |
| | 2373 | int x = -15471; |
| | 2374 | int y = -11720-500; |
| | 2375 | int z = -55875; |
| | 2376 | MeshXScale = (15471-1800); |
| | 2377 | MeshZScale = (55875-36392); |
| | 2378 | |
| | 2379 | CheckForObjectsInWater(x, x+MeshXScale, z, z+MeshZScale, y); |
| | 2380 | |
| | 2381 | WaterXOrigin=x; |
| | 2382 | WaterZOrigin=z; |
| | 2383 | WaterUScale = 4.0f/(float)(MeshXScale+1800-3782); |
| | 2384 | WaterVScale = 4.0f/(float)MeshZScale; |
| | 2385 | MeshXScale/=4; |
| | 2386 | MeshZScale/=2; |
| | 2387 | |
| | 2388 | CurrTextureHandle = ImageHeaderArray[WaterShaftImageNumber].Texture; |
| | 2389 | CheckTriangleBuffer(0, 0, 0, CurrTextureHandle, TRANSLUCENCY_NORMAL); |
| | 2390 | DrawWaterPatch(x, y, z); |
| | 2391 | DrawWaterPatch(x+MeshXScale, y, z); |
| | 2392 | DrawWaterPatch(x+MeshXScale*2, y, z); |
| | 2393 | DrawWaterPatch(x+MeshXScale*3, y, z); |
| | 2394 | DrawWaterPatch(x, y, z+MeshZScale); |
| | 2395 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale); |
| | 2396 | DrawWaterPatch(x+MeshXScale*2, y, z+MeshZScale); |
| | 2397 | DrawWaterPatch(x+MeshXScale*3, y, z+MeshZScale); |
| | 2398 | } |
| | 2399 | } |
| | 2400 | else if(!strcmp(AvP.LevelName, "derelict_a") || !strcmp(AvP.LevelName, "derelict")) |
| | 2401 | { |
| | 2402 | MirroringActive = 0; |
| | 2403 | |
| | 2404 | while(numOfModules--) |
| | 2405 | { |
| | 2406 | DISPLAYBLOCK *objectPtr = VisibleModules[numOfModules].DispPtr; |
| | 2407 | MODULE *modulePtr = objectPtr->Module; |
| | 2408 | |
| | 2409 | if (modulePtr->name) |
| | 2410 | { |
| | 2411 | if(!strcasecmp(modulePtr->name,"start-en01") || !strcasecmp(modulePtr->name,"start")) |
| | 2412 | { |
| | 2413 | extern void RenderMirrorSurface(); |
| | 2414 | extern void RenderMirrorSurface2(); |
| | 2415 | extern void RenderParticlesInMirror(); |
| | 2416 | MirroringActive = 1; |
| | 2417 | MirroringAxis = -5700*2; |
| | 2418 | RenderParticlesInMirror(); |
| | 2419 | RenderMirrorSurface(); |
| | 2420 | RenderMirrorSurface2(); |
| | 2421 | break; |
| | 2422 | } |
| | 2423 | else if (!strcasecmp(modulePtr->name,"water-01")) |
| | 2424 | { |
| | 2425 | const int x = -102799; |
| | 2426 | const int y = 32000; |
| | 2427 | const int z = -200964; |
| | 2428 | HandleRainShaft(modulePtr, y, 0, 16); |
| | 2429 | MeshXScale = (102799-87216); |
| | 2430 | MeshZScale = (200964-180986); |
| | 2431 | |
| | 2432 | CheckForObjectsInWater(x, x+MeshXScale, z, z+MeshZScale, y); |
| | 2433 | |
| | 2434 | WaterXOrigin = x; |
| | 2435 | WaterZOrigin = z; |
| | 2436 | WaterUScale = 4.0f/(float)MeshXScale; |
| | 2437 | WaterVScale = 4.0f/(float)MeshZScale; |
| | 2438 | MeshXScale /= 2; |
| | 2439 | MeshZScale /= 2; |
| | 2440 | |
| | 2441 | CurrTextureHandle = ImageHeaderArray[ChromeImageNumber].Texture; |
| | 2442 | CheckTriangleBuffer(0, 0, 0, CurrTextureHandle, TRANSLUCENCY_NORMAL); |
| | 2443 | DrawWaterPatch(x, y, z); |
| | 2444 | DrawWaterPatch(x+MeshXScale, y, z); |
| | 2445 | DrawWaterPatch(x, y, z+MeshZScale); |
| | 2446 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale); |
| | 2447 | break; |
| | 2448 | } |
| | 2449 | } |
| | 2450 | } |
| | 2451 | } |
| | 2452 | else if(!strcmp(AvP.LevelName, "genshd1")) |
| | 2453 | { |
| | 2454 | while(numOfModules--) |
| | 2455 | { |
| | 2456 | DISPLAYBLOCK *objectPtr = VisibleModules[numOfModules].DispPtr; |
| | 2457 | MODULE *modulePtr = objectPtr->Module; |
| | 2458 | |
| | 2459 | if (modulePtr->name) |
| | 2460 | { |
| | 2461 | if( !strcasecmp(modulePtr->name,"largespace") |
| | 2462 | || !strcasecmp(modulePtr->name,"proc13") |
| | 2463 | || !strcasecmp(modulePtr->name,"trench01") |
| | 2464 | || !strcasecmp(modulePtr->name,"trench02") |
| | 2465 | || !strcasecmp(modulePtr->name,"trench03") |
| | 2466 | || !strcasecmp(modulePtr->name,"trench04") |
| | 2467 | || !strcasecmp(modulePtr->name,"trench05") |
| | 2468 | || !strcasecmp(modulePtr->name,"trench06") |
| | 2469 | || !strcasecmp(modulePtr->name,"trench07") |
| | 2470 | || !strcasecmp(modulePtr->name,"trench08") |
| | 2471 | || !strcasecmp(modulePtr->name,"trench09")) |
| | 2472 | { |
| | 2473 | extern void HandleRain(int numberOfRaindrops); |
| | 2474 | HandleRain(999); |
| | 2475 | break; |
| | 2476 | } |
| | 2477 | else if (!strcmp(modulePtr->name,"05")) |
| | 2478 | { |
| | 2479 | int y = modulePtr->m_maxy+modulePtr->m_world.vy-500; |
| | 2480 | int x = modulePtr->m_minx+modulePtr->m_world.vx; |
| | 2481 | int z = modulePtr->m_minz+modulePtr->m_world.vz; |
| | 2482 | MeshXScale = (7791 - -7794); |
| | 2483 | MeshZScale = (23378 - 7793); |
| | 2484 | |
| | 2485 | CheckForObjectsInWater(x, x+MeshXScale, z, z+MeshZScale, y); |
| | 2486 | |
| | 2487 | CurrTextureHandle = ImageHeaderArray[WaterShaftImageNumber].Texture; |
| | 2488 | CheckBoundTextureIsCorrect(CurrTextureHandle); |
| | 2489 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_NORMAL); |
| | 2490 | |
| | 2491 | WaterXOrigin=x; |
| | 2492 | WaterZOrigin=z; |
| | 2493 | WaterUScale = 4.0f/(float)(MeshXScale); |
| | 2494 | WaterVScale = 4.0f/(float)MeshZScale; |
| | 2495 | #if 0 |
| | 2496 | #if 1 |
| | 2497 | MeshXScale/=2; |
| | 2498 | MeshZScale/=2; |
| | 2499 | |
| | 2500 | CurrTextureHandle = ImageHeaderArray[WaterShaftImageNumber].Texture; |
| | 2501 | CheckTriangleBuffer(0, 0, 0, CurrTextureHandle, TRANSLUCENCY_NORMAL); |
| | 2502 | DrawWaterPatch(x, y, z); |
| | 2503 | DrawWaterPatch(x+MeshXScale, y, z); |
| | 2504 | DrawWaterPatch(x, y, z+MeshZScale); |
| | 2505 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale); |
| | 2506 | |
| | 2507 | HandleRainShaft(modulePtr, y,-21000,1); |
| | 2508 | #else |
| | 2509 | MeshXScale/=4; |
| | 2510 | MeshZScale/=4; |
| | 2511 | DrawWaterPatch(x, y, z); |
| | 2512 | DrawWaterPatch(x, y, z+MeshZScale); |
| | 2513 | DrawWaterPatch(x, y, z+MeshZScale*2); |
| | 2514 | DrawWaterPatch(x, y, z+MeshZScale*3); |
| | 2515 | DrawWaterPatch(x+MeshXScale, y, z); |
| | 2516 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale); |
| | 2517 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale*2); |
| | 2518 | DrawWaterPatch(x+MeshXScale, y, z+MeshZScale*3); |
| | 2519 | DrawWaterPatch(x+MeshXScale*2, y, z); |
| | 2520 | DrawWaterPatch(x+MeshXScale*2, y, z+MeshZScale); |
| | 2521 | DrawWaterPatch(x+MeshXScale*2, y, z+MeshZScale*2); |
| | 2522 | DrawWaterPatch(x+MeshXScale*2, y, z+MeshZScale*3); |
| | 2523 | DrawWaterPatch(x+MeshXScale*3, y, z); |
| | 2524 | DrawWaterPatch(x+MeshXScale*3, y, z+MeshZScale); |
| | 2525 | DrawWaterPatch(x+MeshXScale*3, y, z+MeshZScale*2); |
| | 2526 | DrawWaterPatch(x+MeshXScale*3, y, z+MeshZScale*3); |
| | 2527 | HandleRainDrops(modulePtr, 2); |
| | 2528 | #endif |
| | 2529 | #endif |
| | 2530 | } |
| | 2531 | } |
| | 2532 | } |
| | 2533 | } |
| | 2534 | #if 0 // not yet |
| | 2535 | else if(!strcmp(AvP.LevelName, "hangar")) |
| | 2536 | { |
| | 2537 | VECTORCH v = {49937,-4000,-37709}; |
| | 2538 | DrawCable(&v); |
| | 2539 | } |
| | 2540 | #endif |
| | 2541 | } |
| | 2542 | |
| | 2543 | void DrawCable(VECTORCH *centrePtr, MATRIXCH *orientationPtr) |
| | 2544 | { |
| | 2545 | int field,x,z,i; |
| | 2546 | |
| | 2547 | CurrTextureHandle = NULL; |
| | 2548 | CheckBoundTextureIsCorrect(NULL); |
| | 2549 | CheckTranslucencyModeIsCorrect(TRANSLUCENCY_GLOWING); |
| | 2550 | |
| | 2551 | MeshXScale = 4096/16; |
| | 2552 | MeshZScale = 4096/16; |
| | 2553 | |
| | 2554 | glDepthMask(GL_FALSE); |
| | 2555 | |
| | 2556 | for (field=0; field < 3; field++) |
| | 2557 | { |
| | 2558 | for (x=(field*15), i=0; x < (16+field*15); x++) |
| | 2559 | { |
| | 2560 | for(z=0; z < 16; z++, i++) |
| | 2561 | { |
| | 2562 | VECTORCH *point = &MeshVertex[i]; |
| | 2563 | VECTORCH radius; |
| | 2564 | |
| | 2565 | int innerRadius = 20; |
| | 2566 | int theta = ((4096*z)/15)&4095; |
| | 2567 | int rOffset = GetSin((x*64+theta/32-CloakingPhase)&4095); |
| | 2568 | rOffset = MUL_FIXED(rOffset, rOffset)/512; |
| | 2569 | |
| | 2570 | radius.vx = MUL_FIXED(innerRadius+rOffset/8,GetSin(theta)); |
| | 2571 | radius.vy = MUL_FIXED(innerRadius+rOffset/8,GetCos(theta)); |
| | 2572 | radius.vz = 0; |
| | 2573 | |
| | 2574 | RotateVector(&radius, orientationPtr); |
| | 2575 | |
| | 2576 | point->vx = centrePtr[x].vx + radius.vx; |
| | 2577 | point->vy = centrePtr[x].vy + radius.vy; |
| | 2578 | point->vz = centrePtr[x].vz + radius.vz; |
| | 2579 | |
| | 2580 | MeshVertexColour[i] = RGBA_MAKE(0,rOffset,255,128); |
| | 2581 | |
| | 2582 | TranslatePointIntoViewspace(point); |
| | 2583 | |
| | 2584 | /* is particle within normal view frustrum ? */ |
| | 2585 | if(AvP.PlayerType == I_Alien) /* wide frustrum */ |
| | 2586 | { |
| | 2587 | MeshVertexOutcode[i] = |
| | 2588 | (( (-point->vx <= point->vz*2) |
| | 2589 | &&(point->vx <= point->vz*2) |
| | 2590 | &&(-point->vy <= point->vz*2) |
| | 2591 | &&(point->vy <= point->vz*2) )); |
| | 2592 | } |
| | 2593 | else |
| | 2594 | { |
| | 2595 | MeshVertexOutcode[i] = (( (-point->vx <= point->vz) |
| | 2596 | &&(point->vx <= point->vz) |
| | 2597 | &&(-point->vy <= point->vz) |
| | 2598 | &&(point->vy <= point->vz) )); |
| | 2599 | } |
| | 2600 | } |
| | 2601 | } |
| | 2602 | |
| | 2603 | DrawMoltenMetalMesh_Unclipped(); |
| | 2604 | } |
| | 2605 | |
| | 2606 | glDepthMask(GL_TRUE); |
| | 2607 | } |
| | 2608 | |
| | 2609 | void DeallocateAllImages() |
| | 2610 | { |
| | 2611 | if (NumImages > 0) |
| | 2612 | { |
| | 2613 | int i; |
| | 2614 | |
| | 2615 | if (NumImages > 1) |
| | 2616 | if(NULL != ImageHeaderArray[StaticImageNumber].Texture->buf) |
| | 2617 | { |
| | 2618 | free(ImageHeaderArray[StaticImageNumber].Texture->buf); |
| | 2619 | ImageHeaderArray[StaticImageNumber].Texture->buf = NULL; |
| | 2620 | } |
| | 2621 | |
| | 2622 | for (i=0; i <= NumImages; i++) |
| | 2623 | { |
| | 2624 | glDeleteTextures(1, &ImageHeaderArray[i].Texture->id); |
| | 2625 | free(ImageHeaderArray[i].Texture); |
| | 2626 | ImageHeaderArray[i].Texture = NULL; |
| | 2627 | //printf("%d %s\n",i, ImageHeaderArray[i].ImageName); |
| | 2628 | free(ImageHeaderArray[i].ImageName); |
| | 2629 | ImageHeaderArray[i].ImageName = NULL; |
| | 2630 | } |
| | 2631 | } |
| | 2632 | } |
| | 2633 | |
| | 2634 | void DeallocateEnvImages() |
| | 2635 | { |
| | 2636 | extern int number_of_level_textures; |
| | 2637 | |
| | 2638 | for(; number_of_level_textures > 0; number_of_level_textures--, NumImages--) |
| | 2639 | { |
| | 2640 | glDeleteTextures(1, &ImageHeaderArray[NumImages].Texture->id); |
| | 2641 | free(ImageHeaderArray[NumImages].Texture); |
| | 2642 | ImageHeaderArray[NumImages].Texture = NULL; |
| | 2643 | //printf("Deleteing ENV %s\n", ImageHeaderArray[NumImages].ImageName); |
| | 2644 | free(ImageHeaderArray[NumImages].ImageName); |
| | 2645 | ImageHeaderArray[NumImages].ImageName = NULL; |
| | 2646 | } |
| | 2647 | |
| | 2648 | number_of_level_textures = 0; |
| | 2649 | } |
| | 2650 | |
| | 2651 | #include "files.h" |
| | 2652 | extern unsigned char *png_get_image_data(FILE *infile, unsigned int *width, unsigned int*height); |
| | 2653 | |
| | 2654 | static struct TEXTURE * Create_png_Texture(const char * file_name) |
| | 2655 | { |
| | 2656 | char *file_name_and_full_path = malloc(strlen("graphics/") + strlen(file_name) + 1); |
| | 2657 | struct TEXTURE *Tex = malloc(sizeof(struct TEXTURE)); |
| | 2658 | |
| | 2659 | if ((NULL == Tex) || (NULL == file_name_and_full_path)) |
| | 2660 | { |
| | 2661 | free(file_name_and_full_path); |
| | 2662 | free(Tex); |
| | 2663 | return NULL; |
| | 2664 | } |
| | 2665 | |
| | 2666 | sprintf(file_name_and_full_path, "graphics/%s", file_name); |
| | 2667 | |
| | 2668 | FILE * fileH = OpenGameFile(file_name_and_full_path, 1, FILETYPE_GAMEDATA); |
| | 2669 | free(file_name_and_full_path); |
| | 2670 | |
| | 2671 | if (NULL != fileH) |
| | 2672 | { |
| | 2673 | Tex->id = 0; |
| | 2674 | Tex->filter = 0; |
| | 2675 | Tex->buf = png_get_image_data(fileH, &Tex->w, &Tex->h); |
| | 2676 | fclose(fileH); |
| | 2677 | |
| | 2678 | if (NULL != Tex->buf) |
| | 2679 | return Tex; |
| | 2680 | |
| | 2681 | printf("ERROR Create_png_Texture(): reading file \"%s\"\n", file_name); |
| | 2682 | } |
| | 2683 | else |
| | 2684 | { |
| | 2685 | printf("\nMissing file '%s'\n", file_name); |
| | 2686 | } |
| | 2687 | |
| | 2688 | free(Tex); |
| | 2689 | |
| | 2690 | return NULL; |
| | 2691 | } |
| | 2692 | |
| | 2693 | int CL_LoadImageOnce(char const * FileName) |
| | 2694 | { |
| | 2695 | //assert(NumImages < MaxImages); |
| | 2696 | |
| | 2697 | if(strstr(FileName, "fmvs/")) |
| | 2698 | return StaticImageNumber; |
| | 2699 | |
| | 2700 | int i = NumImages; |
| | 2701 | |
| | 2702 | for (; i >= 0; i--) |
| | 2703 | { |
| | 2704 | if (!strcmp(ImageHeaderArray[i].ImageName, FileName)) |
| | 2705 | { |
| | 2706 | //printf("\t Image %s is already loaded to image number %d\n", FileName, i); |
| | 2707 | return i; |
| | 2708 | } |
| | 2709 | } |
| | 2710 | |
| | 2711 | ImageHeaderArray[++NumImages].Texture = Create_png_Texture(FileName); |
| | 2712 | |
| | 2713 | if (NULL != ImageHeaderArray[NumImages].Texture) |
| | 2714 | { |
| | 2715 | char *new_file_name = malloc(strlen(FileName) + 1); |
| | 2716 | |
| | 2717 | if (NULL != new_file_name) |
| | 2718 | { |
| | 2719 | strcpy(new_file_name, FileName); |
| | 2720 | ImageHeaderArray[NumImages].ImageName = new_file_name; |
| | 2721 | //printf("%s\t loaded to image number %d\n", ImageHeaderArray[NumImages].ImageName, NumImages); |
| | 2722 | return NumImages; |
| | 2723 | } |
| | 2724 | } |
| | 2725 | else |
| | 2726 | { |
| | 2727 | // this only happens once or twice with bonus levels; not fatal |
| | 2728 | --NumImages; |
| | 2729 | } |
| | 2730 | |
| | 2731 | return -1; |
| | 2732 | } |
| | 2733 | |
| | 2734 | static int load_font() |
| | 2735 | { |
| | 2736 | AAFontImageNumber = CL_LoadImageOnce("common/aa_font.png"); |
| | 2737 | |
| | 2738 | if( -1 != AAFontImageNumber) |
| | 2739 | { |
| | 2740 | struct TEXTURE *image = ImageHeaderArray[AAFontImageNumber].Texture; |
| | 2741 | |
| | 2742 | unsigned char *srcPtr = image->buf; |
| | 2743 | int c = 33; |
| | 2744 | |
| | 2745 | AAFontWidths[32] = 3; |
| | 2746 | |
| | 2747 | for (; c < 255; c++) |
| | 2748 | { |
| | 2749 | int x1 = 1 + ((c-32) & 15) * 16; |
| | 2750 | int y1 = 1 + ((c-32) >> 4) * 16; |
| | 2751 | int x = x1 + HUD_FONT_WIDTH; |
| | 2752 | |
| | 2753 | AAFontWidths[c] = 17; |
| | 2754 | |
| | 2755 | for (; x > x1; x--) |
| | 2756 | { |
| | 2757 | int blank = 1; |
| | 2758 | int y = y1; |
| | 2759 | |
| | 2760 | for (; y < y1 + HUD_FONT_HEIGHT; y++) |
| | 2761 | { |
| | 2762 | unsigned char *s = &srcPtr[(x + y * image->w) * 4]; |
| | 2763 | |
| | 2764 | if (s[2] >= 0x80) |
| | 2765 | { |
| | 2766 | blank = 0; |
| | 2767 | break; |
| | 2768 | } |
| | 2769 | } |
| | 2770 | |
| | 2771 | if (blank) |
| | 2772 | AAFontWidths[c]--; |
| | 2773 | else |
| | 2774 | break; |
| | 2775 | } |
| | 2776 | } |
| | 2777 | |
| | 2778 | CreateOGLTexture(image); |
| | 2779 | free(image->buf); |
| | 2780 | image->buf = NULL; |
| | 2781 | return 1; |
| | 2782 | } |
| | 2783 | |
| | 2784 | return 0; |
| | 2785 | } |
| | 2786 | |
| | 2787 | static int make_static_texture() |
| | 2788 | { |
| | 2789 | struct TEXTURE *temp = malloc(sizeof(struct TEXTURE)); |
| | 2790 | |
| | 2791 | if(NULL != temp) |
| | 2792 | { |
| | 2793 | temp->buf = malloc(128*128*3); |
| | 2794 | |
| | 2795 | if(NULL != temp->buf) |
| | 2796 | { |
| | 2797 | char *new_file_name = malloc(15); |
| | 2798 | |
| | 2799 | if(NULL != new_file_name) |
| | 2800 | { |
| | 2801 | temp->w = temp->h = 128; |
| | 2802 | strcpy(new_file_name, "fmvs/static"); |
| | 2803 | StaticImageNumber = ++NumImages; |
| | 2804 | ImageHeaderArray[StaticImageNumber].ImageName = new_file_name; |
| | 2805 | ImageHeaderArray[StaticImageNumber].Texture = temp; |
| | 2806 | return 1; |
| | 2807 | } |
| | 2808 | |
| | 2809 | free(temp->buf); |
| | 2810 | |
| | 2811 | } |
| | 2812 | |
| | 2813 | free(temp); |
| | 2814 | } |
| | 2815 | |
| | 2816 | return 0; |
| | 2817 | } |
| | 2818 | |
| | 2819 | int LoadCommonTextures() |
| | 2820 | { |
| | 2821 | if(load_font() && make_static_texture()) |
| | 2822 | { |
| | 2823 | HUDImageNumber = CL_LoadImageOnce("huds/marine/marinehud.png"); |
| | 2824 | PredatorNumbersImageNumber = CL_LoadImageOnce("huds/predator/prednumbers.png"); |
| | 2825 | AlienTongueImageNumber = CL_LoadImageOnce("huds/alien/alientongue.png"); |
| | 2826 | HUDFontsImageNumber = CL_LoadImageOnce("common/hudfonts.png"); |
| | 2827 | SpecialFXImageNumber = CL_LoadImageOnce("common/partclfx.png"); |
| | 2828 | CloudyImageNumber = CL_LoadImageOnce("common/cloudy.png"); |
| | 2829 | BurningImageNumber = CL_LoadImageOnce("common/burn.png"); |
| | 2830 | |
| | 2831 | return |
| | 2832 | ( |
| | 2833 | (-1 != HUDImageNumber) |
| | 2834 | && |
| | 2835 | (-1 != PredatorNumbersImageNumber) |
| | 2836 | && |
| | 2837 | (-1 != AlienTongueImageNumber) |
| | 2838 | && |
| | 2839 | (-1 != HUDFontsImageNumber) |
| | 2840 | && |
| | 2841 | (-1 != SpecialFXImageNumber) |
| | 2842 | && |
| | 2843 | (-1 != CloudyImageNumber) |
| | 2844 | && |
| | 2845 | (-1 != BurningImageNumber) |
| | 2846 | ); |
| | 2847 | } |
| | 2848 | |
| | 2849 | return 0; |
| | 2850 | } |
| | 2851 | |
| | 2852 | void shuffle_textures() |
| | 2853 | { |
| | 2854 | static int * int_array = NULL; |
| | 2855 | |
| | 2856 | if (NULL == int_array) |
| | 2857 | { |
| | 2858 | int_array = malloc(sizeof(int) * (NumImages + 1)); |
| | 2859 | |
| | 2860 | if (NULL != int_array) |
| | 2861 | { |
| | 2862 | int_array[0] = ImageHeaderArray[0].Texture->id; |
| | 2863 | int i = 1; // font texture is at 0 |
| | 2864 | |
| | 2865 | srand(time(NULL)); |
| | 2866 | |
| | 2867 | for (; i <= NumImages; i++) |
| | 2868 | { |
| | 2869 | int_array[i] = ImageHeaderArray[i].Texture->id; |
| | 2870 | ImageHeaderArray[i].Texture->id = ImageHeaderArray[rand() % NumImages].Texture->id; |
| | 2871 | } |
| | 2872 | } |
| | 2873 | } |
| | 2874 | else |
| | 2875 | { |
| | 2876 | int i = 1; |
| | 2877 | |
| | 2878 | for (; i <= NumImages; i++) |
| | 2879 | ImageHeaderArray[i].Texture->id = int_array[i]; |
| | 2880 | |
| | 2881 | free(int_array); |
| | 2882 | int_array = NULL; |
| | 2883 | } |
| | 2884 | } |
| | 2885 | |
| | 2886 | extern uint8_t GotAnyKey; |
| | 2887 | |
| | 2888 | void fade_text(const char *textPtr) |
| | 2889 | { |
| | 2890 | int timeRemaining = 7 * ONE_FIXED; |
| | 2891 | int y = ScreenDescriptorBlock.SDB_CentreY; |
| | 2892 | |
| | 2893 | do |
| | 2894 | { |
| | 2895 | read_user_input(); |
| | 2896 | |
| | 2897 | if (timeRemaining > 13*ONE_FIXED/2) |
| | 2898 | { |
| | 2899 | RenderSmallMenuText(textPtr,ScreenDescriptorBlock.SDB_CentreX, y, 14*ONE_FIXED-timeRemaining*2,MENUFORMAT_CENTREJUSTIFIED); |
| | 2900 | } |
| | 2901 | else if (timeRemaining > 5*ONE_FIXED) |
| | 2902 | { |
| | 2903 | RenderSmallMenuText(textPtr,ScreenDescriptorBlock.SDB_CentreX, y, ONE_FIXED,MENUFORMAT_CENTREJUSTIFIED); |
| | 2904 | } |
| | 2905 | else if (timeRemaining > 3*ONE_FIXED) |
| | 2906 | { |
| | 2907 | RenderSmallMenuText(textPtr,ScreenDescriptorBlock.SDB_CentreX, y,(timeRemaining-3*ONE_FIXED)/2,MENUFORMAT_CENTREJUSTIFIED); |
| | 2908 | } |
| | 2909 | |
| | 2910 | SDL_GL_SwapBuffers(); |
| | 2911 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| | 2912 | |
| | 2913 | FrameCounterHandler(); |
| | 2914 | timeRemaining -= NormalFrameTime; |
| | 2915 | |
| | 2916 | } while((timeRemaining > 0) && !GotAnyKey); |
| | 2917 | } |
| | 2918 | |
| | 2919 | void roll_credits() |
| | 2920 | { |
| | 2921 | extern const char * credits_text[]; |
| | 2922 | const char ** char_ptr = credits_text; |
| | 2923 | int j = 0; |
| | 2924 | int y = ScreenDescriptorBlock.SDB_Height; |
| | 2925 | int font_height = 30; |
| | 2926 | int scroll_speed = ONE_FIXED/64; |
| | 2927 | int move_text_timer = scroll_speed; |
| | 2928 | |
| | 2929 | do |
| | 2930 | { |
| | 2931 | read_user_input(); |
| | 2932 | |
| | 2933 | if ( '\n' == char_ptr[j] ) |
| | 2934 | { |
| | 2935 | if (j == 0) |
| | 2936 | break; |
| | 2937 | else |
| | 2938 | j--; |
| | 2939 | } |
| | 2940 | |
| | 2941 | if (y > font_height) |
| | 2942 | { |
| | 2943 | int i = j; |
| | 2944 | float fade = ONE_FIXED; |
| | 2945 | |
| | 2946 | for (; i >= 0; i--) |
| | 2947 | { |
| | 2948 | if (NULL != char_ptr[i]) |
| | 2949 | { |
| | 2950 | RenderSmallMenuText(char_ptr[i], ScreenDescriptorBlock.SDB_CentreX, (y + i * font_height) , fade, MENUFORMAT_CENTREJUSTIFIED); |
| | 2951 | fade *= 0.80; |
| | 2952 | } |
| | 2953 | } |
| | 2954 | |
| | 2955 | if (move_text_timer < 0) |
| | 2956 | { |
| | 2957 | y--; |
| | 2958 | move_text_timer = scroll_speed; |
| | 2959 | |
| | 2960 | if (y % font_height == 0) |
| | 2961 | j++; |
| | 2962 | } |
| | 2963 | |
| | 2964 | SDL_GL_SwapBuffers(); |
| | 2965 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| | 2966 | |
| | 2967 | } |
| | 2968 | else |
| | 2969 | { |
| | 2970 | y += font_height; |
| | 2971 | char_ptr++; |
| | 2972 | j--; |
| | 2973 | } |
| | 2974 | |
| | 2975 | FrameCounterHandler(); |
| | 2976 | move_text_timer -= NormalFrameTime; |
| | 2977 | |
| | 2978 | } while(!got_any_key()); |
| | 2979 | } |
| | 2980 | |
| | 2981 | void PlayIntroSequence() |
| | 2982 | { |
| | 2983 | fade_text("Fox Interactive"); |
| | 2984 | fade_text("And"); |
| | 2985 | fade_text("Rebellion"); |
| | 2986 | |
| | 2987 | if (!GotAnyKey) |
| | 2988 | { |
| | 2989 | fade_text("Presents"); |
| | 2990 | fade_text("Aliens versus Predator Gold Edition"); |
| | 2991 | } |
| | 2992 | } |