13 #include "sound.h" // snd_vol
14 #include "music.h" // mus_vol
22 #include "switch.h" // sw_secrets
25 # include <OpenGL/gl.h>
29 #include <stdlib.h> // malloc free abs
30 #include <assert.h> // assert
33 #define VGA_TRANSPARENT_COLOR 0
34 #define DEFAULT_SKY_COLOR 0x97
36 #define PLAYER_COLOR_OFFSET 7
42 typedef struct vgaimg
{
59 struct node
*left
, *right
;
64 typedef struct cache
{
70 typedef struct image
{
78 int SCRW
= 320; // public
79 int SCRH
= 200; // public
81 static int fullscreen
;
82 static SDL_Surface
*surf
;
83 static rgb playpal
[256];
84 static byte bright
[256];
88 static image scrnh
[3]; // TITLEPIC INTERPIC ENDPIC
89 static image ltn
[2][2];
92 static image smk_spr
[SMSN
];
93 static image smk_fspr
[FLSN
];
96 static image fx_spr
[15];
97 static char fx_sprd
[15];
100 static image wp_spr
[49*2];
101 static char wp_sprd
[49*2];
104 static image item_spr
[58];
105 static char item_sprd
[58];
108 static image plr_spr
[27*2];
109 static image plr_msk
[27*2];
110 static char plr_sprd
[27*2];
111 static image plr_wpn
[11][6];
114 static image pl_spr
[2];
115 static image pl_msk
[2];
116 static image mn_spr
[MN_TN
][29*2];
117 static image mn_man_msk
[29*2];
118 static char mn_sprd
[MN_TN
][29*2];
119 static image mn_fspr
[8];
120 static image mn_sgun
[2];
123 static image sth
[22];
124 static image bfh
[160 - '!'];
125 static image sfh
[160 - '!'];
128 static image keys
[3];
134 static image msklh
[2];
144 static const char *anm
[ANIT
- 1][5] = {
145 {"WALL22_1", "WALL23_1", "WALL23_2", NULL
, NULL
},
146 {"WALL58_1", "WALL58_2", "WALL58_3", NULL
, NULL
},
147 {"W73A_1", "W73A_2", NULL
, NULL
, NULL
},
148 {"RP2_1", "RP2_2", "RP2_3", "RP2_4", NULL
}
150 static int max_wall_width
;
151 static int max_wall_height
;
152 static int max_textures
;
153 static image walp
[256];
154 static byte walani
[256];
155 static image anip
[ANIT
][5];
156 static byte anic
[ANIT
];
161 // https://blackpawn.com/texts/lightmaps/
162 static node
*R_node_alloc (node
*p
, int w
, int h
) {
168 node
*n
= R_node_alloc(p
->left
, w
, h
);
169 return n
? n
: R_node_alloc(p
->right
, w
, h
);
171 int pw
= p
->r
- p
->l
+ 1;
172 int ph
= p
->b
- p
->t
+ 1;
173 if (p
->leaf
|| pw
< w
|| ph
< h
) {
175 } else if (pw
== w
&& ph
== h
) {
179 p
->left
= malloc(sizeof(node
));
180 p
->right
= malloc(sizeof(node
));
181 if (pw
- w
> ph
- h
) {
208 return R_node_alloc(p
->left
, w
, h
);
213 static cache
*R_cache_new (void) {
217 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &size
);
218 size
/= 2; // TODO remove hack or detect ibook bug
220 glGenTextures(1, &id
);
222 glBindTexture(GL_TEXTURE_2D
, id
);
223 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
224 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
225 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, size
, size
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
226 int ok
= glGetError() == GL_NO_ERROR
;
227 glBindTexture(GL_TEXTURE_2D
, 0);
229 c
= malloc(sizeof(cache
));
239 glDeleteTextures(1, &id
);
243 logo("new cache %p\n", c
);
247 static node
*R_cache_alloc (cache
*root
, int w
, int h
) {
249 assert(w
> 0 && h
> 0);
254 n
= R_node_alloc(&c
->root
, w
, h
);
265 n
= R_node_alloc(&c
->root
, w
, h
);
274 static void R_cache_update (node
*n
, const void *data
, int w
, int h
) {
278 int nw
= n
->r
- n
->l
+ 1;
279 int nh
= n
->b
- n
->t
+ 1;
282 glBindTexture(GL_TEXTURE_2D
, n
->base
->id
);
283 glTexSubImage2D(GL_TEXTURE_2D
, 0, n
->l
, n
->t
, nw
, nh
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
284 assert(glGetError() == GL_NO_ERROR
);
285 glBindTexture(GL_TEXTURE_2D
, 0);
288 /* Generic helpers */
290 static void R_init_playpal (void) {
292 byte
*vgapal
= M_lock(F_getresid("PLAYPAL"));
293 for (i
= 0; i
< 256; i
++) {
295 .r
= vgapal
[i
* 3 + 0] * 255 / 63,
296 .g
= vgapal
[i
* 3 + 1] * 255 / 63,
297 .b
= vgapal
[i
* 3 + 2] * 255 / 63,
299 bright
[i
] = ((int)vgapal
[i
* 3 + 0] + vgapal
[i
* 3 + 1] + vgapal
[i
* 3 + 2]) * 8 / (63 * 3);
304 static vgaimg
*R_getvga (int id
) {
305 int loaded
= M_was_locked(id
);
306 vgaimg
*v
= M_lock(id
);
307 if (v
!= NULL
&& !loaded
) {
308 v
->w
= short2host(v
->w
);
309 v
->h
= short2host(v
->h
);
310 v
->x
= short2host(v
->x
);
311 v
->y
= short2host(v
->y
);
316 static rgba
*R_extract_flame_spr (vgaimg
*v
) {
317 static const byte flametab
[16] = {
318 0xBC, 0xBA, 0xB8, 0xB6, 0xB4, 0xB2, 0xB0, 0xD5,
319 0xD6, 0xD7, 0xA1, 0xA0, 0xE3, 0xE2, 0xE1, 0xE0
322 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
324 for (j
= 0; j
< v
->h
; j
++) {
325 for (i
= 0; i
< v
->w
; i
++) {
326 int k
= j
* v
->w
+ i
;
327 byte c
= v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
];
329 .r
= playpal
[flametab
[c
]].r
,
330 .g
= playpal
[flametab
[c
]].g
,
331 .b
= playpal
[flametab
[c
]].b
,
332 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
340 static rgba
*R_extract_smoke_spr (vgaimg
*v
) {
342 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
344 for (j
= 0; j
< v
->h
; j
++) {
345 for (i
= 0; i
< v
->w
; i
++) {
346 int k
= j
* v
->w
+ i
;
347 byte c
= ((v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
]) + 0x60) ^ 0x0F;
348 byte a
= 0xFF - ((int)playpal
[c
].r
+ playpal
[c
].g
+ playpal
[c
].b
) / 3;
353 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : a
,
361 static rgba
*R_extract_mask_spr (vgaimg
*v
) {
363 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
365 for (j
= 0; j
< v
->h
; j
++) {
366 for (i
= 0; i
< v
->w
; i
++) {
367 int k
= j
* v
->w
+ i
;
369 if (c
>= 0x70 && c
<= 0x7F) {
370 byte mask
= c
- 0x70;
371 mask
= 0xFF - ((mask
<< 4) | mask
);
392 static rgba
*R_extract_rgba_spr (vgaimg
*v
) {
394 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
396 for (j
= 0; j
< v
->h
; j
++) {
397 for (i
= 0; i
< v
->w
; i
++) {
398 int k
= j
* v
->w
+ i
;
404 .a
= c
== VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
414 static image
R_gl_create_image (const rgba
*buf
, int w
, int h
) {
415 node
*n
= R_cache_alloc(root
, w
, h
);
417 R_cache_update(n
, buf
, w
, h
);
427 static image
R_gl_get_special_image (int id
, rgba
*(*fn
)(vgaimg
*)) {
428 image img
= (image
) { .res
= -1 };
429 vgaimg
*v
= R_getvga(id
);
431 rgba
*buf
= (*fn
)(v
);
432 img
= R_gl_create_image(buf
, v
->w
, v
->h
);
442 static image
R_gl_getimage (int id
) {
443 return R_gl_get_special_image(id
, &R_extract_rgba_spr
);
446 static image
R_gl_loadimage (const char name
[8]) {
447 return R_gl_getimage(F_getresid(name
));
450 static image
R_gl_get_special_spr (const char n
[4], int s
, int d
, rgba
*(*fn
)(vgaimg
*)) {
451 return R_gl_get_special_image(F_getsprid(n
, s
, d
), fn
);
454 static void R_gl_free_image (image
*img
) {
455 if (img
->n
!= NULL
&& img
->res
>= 0) {
461 static void R_gl_draw_quad (int x
, int y
, int w
, int h
) {
463 glVertex2i(x
+ w
, y
);
465 glVertex2i(x
, y
+ h
);
466 glVertex2i(x
+ w
, y
+ h
);
470 static void R_gl_draw_textured (image
*img
, int x
, int y
, int w
, int h
, int flip
) {
472 GLfloat nw
= img
->n
->base
->root
.r
+ 1;
473 GLfloat nh
= img
->n
->base
->root
.b
+ 1;
474 GLfloat ax
= (flip
? img
->n
->l
: img
->n
->r
+ 1) / nw
;
475 GLfloat bx
= (flip
? img
->n
->r
+ 1 : img
->n
->l
) / nh
;
476 GLfloat ay
= (img
->n
->t
) / nw
;
477 GLfloat by
= (img
->n
->b
+ 1) / nh
;
478 glBindTexture(GL_TEXTURE_2D
, img
->n
->base
->id
);
479 glEnable(GL_TEXTURE_2D
);
481 glTexCoord2f(ax
, ay
); glVertex2i(x
+ w
, y
);
482 glTexCoord2f(bx
, ay
); glVertex2i(x
, y
);
483 glTexCoord2f(bx
, by
); glVertex2i(x
, y
+ h
);
484 glTexCoord2f(ax
, by
); glVertex2i(x
+ w
, y
+ h
);
486 glDisable(GL_TEXTURE_2D
);
487 glBindTexture(GL_TEXTURE_2D
, 0);
489 glColor3ub(255, 0, 0);
491 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
492 R_gl_draw_quad(x
, y
, w
, h
);
496 /* fit image into rectangle without applying offset and transparency */
497 static void R_gl_draw_image_ext (image
*img
, int x
, int y
, int w
, int h
) {
499 glColor3ub(255, 255, 255);
500 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
501 R_gl_draw_textured(img
, x
, y
, w
, h
, 0);
504 /* draw sprite with offset and coloring */
505 static void R_gl_draw_image_color (image
*img
, int x
, int y
, int flip
) {
506 int xx
= flip
? x
- img
->w
+ img
->x
: x
- img
->x
;
508 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
509 R_gl_draw_textured(img
, xx
, y
- img
->y
, img
->w
, img
->h
, flip
);
513 /* draw sprite with offset */
514 static void R_gl_draw_image (image
*img
, int x
, int y
, int flip
) {
515 int xx
= flip
? x
- img
->w
+ img
->x
: x
- img
->x
;
517 glColor3ub(255, 255, 255);
518 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
519 R_gl_draw_textured(img
, xx
, y
- img
->y
, img
->w
, img
->h
, flip
);
522 static void R_gl_set_color (byte c
) {
523 glColor3ub(playpal
[c
].r
, playpal
[c
].g
, playpal
[c
].b
);
526 static void R_gl_setclip (int x
, int y
, int w
, int h
) {
527 glScissor(x
, SCRH
- h
- y
, w
, h
);
530 static void R_gl_setmatrix (void) {
531 glScissor(0, 0, SCRW
, SCRH
);
532 glViewport(0, 0, SCRW
, SCRH
);
533 glMatrixMode(GL_PROJECTION
);
535 glOrtho(0, SCRW
, SCRH
, 0, 0, 1);
536 glMatrixMode(GL_MODELVIEW
);
542 static image
Z_getspr (const char n
[4], int s
, int d
, char *dir
) {
543 int h
= F_getsprid(n
, s
, d
);
545 *dir
= (h
& 0x8000) ? 1 : 0;
547 return R_gl_getimage(h
);
550 static void Z_putch_generic (image img
[], int off
, int ch
) {
552 if (ch
> 32 && ch
< 160) {
556 R_gl_draw_image(p
, prx
, pry
, 0);
563 static void Z_printf_generic (image img
[], int off
, const char *fmt
, va_list ap
) {
566 vsprintf(buf
, fmt
, ap
);
567 for (i
= 0; buf
[i
]; ++i
) {
575 Z_putch_generic(img
, off
, (byte
)buf
[i
]);
580 static void Z_gotoxy (int x
, int y
) {
585 static void Z_printbf (const char *fmt
, ...) {
588 Z_printf_generic(bfh
, 12, fmt
, a
);
592 static void Z_printsf (const char *fmt
, ...) {
595 Z_printf_generic(sfh
, 7, fmt
, a
);
599 static void Z_printhf (const char *fmt
, ...) {
604 vsprintf(buf
, fmt
, a
);
606 for (i
= 0; buf
[i
]; ++i
) {
637 R_gl_draw_image(&sth
[c
], prx
, pry
, 0);
645 static image
*PL_getspr (int s
, int d
, int msk
) {
646 int i
= (s
- 'A') * 2 + d
;
647 return msk
? &plr_msk
[i
] : &plr_spr
[i
];
650 static void GM_draw (void) {
651 enum {MENU
, MSG
}; // copypasted from menu.c!
653 CANCEL
, NEWGAME
, LOADGAME
, SAVEGAME
, OPTIONS
, QUITGAME
, QUIT
, ENDGAME
, ENDGM
,
654 PLR1
, PLR2
, COOP
, DM
, VOLUME
, GAMMA
, LOAD
, SAVE
, PLCOLOR
, PLCEND
, MUSIC
, INTERP
,
655 SVOLM
, SVOLP
, MVOLM
, MVOLP
, GAMMAM
, GAMMAP
, PL1CM
, PL1CP
, PL2CM
, PL2CP
656 }; // copypasted from menu.c!
657 int i
, j
, k
, x
, y
, cx
, cy
;
663 if (mnu
->type
== MENU
) {
664 y
= cy
- (mnu
->n
* 16 - 20) / 2;
665 Z_gotoxy(cx
- mnu
->x
, y
- 10); Z_printbf("%s", mnu
->ttl
);
666 for (i
= 0; i
< mnu
->n
; i
++) {
667 if (mnu
->t
[i
] == LOAD
|| mnu
->t
[i
] == SAVE
) {
669 R_gl_draw_image(&mslotl
, cx
- mnu
->x
, j
, 0);
670 for (k
= 8; k
< 184; k
+= 8) {
671 R_gl_draw_image(&mslotm
, cx
- mnu
->x
+ k
, j
, 0);
673 R_gl_draw_image(&mslotr
, cx
- mnu
->x
+ 184, j
, 0);
674 Z_gotoxy(cx
- mnu
->x
+ 4, j
- 8);
675 if (input
&& i
== save_mnu
.cur
) {
676 Z_printsf("%s_", ibuf
);
678 Z_printsf("%s", savname
[i
]);
681 x
= mnu
->t
[i
] >= SVOLM
? (mnu
->t
[i
] >= PL1CM
? 50 : 152) : 0;
682 Z_gotoxy(cx
- mnu
->x
+ x
, y
+ i
* 16 + 20);
683 Z_printbf("%s", mnu
->m
[i
]);
686 Z_printbf(" '%s'", g_music
);
689 Z_printbf("%s", fullscreen
? "ON" : "OFF");
695 img
= PL_getspr(*panimp
, 0, 0);
696 R_gl_draw_image(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
697 img
= PL_getspr(*panimp
, 0, 1);
698 R_gl_set_color(pcolortab
[(mnu
->t
[i
] == PL1CM
) ? p1color
: p2color
] + PLAYER_COLOR_OFFSET
);
699 R_gl_draw_image_color(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
708 R_gl_draw_image(&mbarl
, cx
- mnu
->x
, j
, 0);
709 for (k
= 8; k
< 144; k
+= 8) {
710 R_gl_draw_image(&mbarm
, cx
- mnu
->x
+ k
, j
, 0);
712 R_gl_draw_image(&mbarr
, cx
- mnu
->x
+ 144, j
, 0);
727 R_gl_draw_image(&mbaro
, cx
- mnu
->x
+ 8 + k
, j
, 0);
732 R_gl_draw_image(&msklh
[(gm_tm
/ 6) & 1], cx
- mnu
->x
- 25, y
+ mnu
->cur
* 16 + 20 - 8, 0);
733 } else if (mnu
->type
== MSG
) {
734 Z_gotoxy(cx
- strlen(mnu
->ttl
) * 7 / 2, cy
- 10); Z_printsf(mnu
->ttl
);
735 Z_gotoxy(cx
- 24, SCRH
/ 2); Z_printsf("(Y/N)");
737 ERR_fatal("Unknown menu type %i\n", mnu
->type
);
744 static void R_draw_fld (byte
*fld
, int minx
, int miny
, int maxx
, int maxy
, int fg
) {
746 assert(minx
>= 0 && minx
<= FLDW
);
747 assert(miny
>= 0 && miny
<= FLDH
);
748 assert(maxx
>= 0 && maxx
<= FLDW
);
749 assert(maxy
>= 0 && maxy
<= FLDH
);
750 for (j
= miny
; j
< maxy
; j
++) {
751 for (i
= minx
; i
< maxx
; i
++) {
752 byte id
= fld
[j
* FLDW
+ i
];
754 if (walp
[id
].res
< 0) {
756 switch (R_get_special_id(id
)) {
758 glColor4ub(0, 0, 255, 127);
761 glColor4ub(0, 127, 0, 127);
764 glColor4ub(127, 0, 0, 127);
767 glColor4ub(0, 0, 0, 127);
771 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
772 R_gl_draw_quad(i
* CELW
, j
* CELW
, CELW
, CELH
);
775 R_gl_draw_image(&walp
[id
], i
* CELW
, j
* CELH
, 0);
782 static void R_draw_dots (void) {
785 for (i
= 0; i
< MAXDOT
; i
++) {
787 R_gl_set_color(dot
[i
].c
);
788 glVertex2i(dot
[i
].o
.x
, dot
[i
].o
.y
+ 1);
794 static void R_draw_items (void) {
796 for (i
= 0; i
< MAXITEM
; ++i
) {
798 if (it
[i
].t
&& it
[i
].s
>= 0) {
799 switch (it
[i
].t
& 0x7FFF) {
801 s
= it
[i
].s
/ 9 + 18;
804 s
= it
[i
].s
/ 9 + 20;
807 s
= it
[i
].s
/ 2 + 22;
810 s
= it
[i
].s
/ 2 + 26;
816 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_SUPER
) * 4 + 35;
818 case I_GOR1
: case I_FCAN
:
819 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_GOR1
) * 3 + 51;
830 s
= (it
[i
].t
& 0x7FFF) - I_KEYR
+ 31;
836 s
= (it
[i
].t
& 0x7FFF) - 1;
840 R_gl_draw_image(&item_spr
[s
], it
[i
].o
.x
, it
[i
].o
.y
, item_sprd
[s
]);
845 static int standspr (player_t
*p
) {
848 } else if (p
->f
& PLF_DOWN
) {
855 static int wpnspr (player_t
*p
) {
858 } else if(p
->f
& PLF_DOWN
) {
865 static void R_draw_player (player_t
*p
) {
866 enum {STAND
, GO
, DIE
, SLOP
, DEAD
, MESS
, OUT
, FALL
}; // copypasted from player.c!
867 static const int wytab
[] = {-1, -2, -1, 0};
874 if (p
->f
& PLF_FIRE
) {
877 } else if (p
->pain
) {
900 s
= plr_goanim
[p
->s
/ 8];
901 w
= (p
->f
& PLF_FIRE
) ? 'B' : 'A';
903 wy
= 1 + wytab
[s
- 'A'];
907 s
= plr_dieanim
[p
->s
];
910 s
= plr_slopanim
[p
->s
];
920 R_gl_draw_image(&plr_wpn
[(int)p
->wpn
][w
-'A'], p
->o
.x
+ wx
, p
->o
.y
+ wy
, p
->d
);
923 R_gl_draw_image(&plr_spr
[(s
- 'A') * 2 + p
->d
], p
->o
.x
, p
->o
.y
, plr_sprd
[(s
- 'A') * 2 + p
->d
]);
924 R_gl_set_color(p
->color
+ PLAYER_COLOR_OFFSET
);
925 R_gl_draw_image_color(&plr_msk
[(s
- 'A') * 2 + p
->d
], p
->o
.x
, p
->o
.y
, plr_sprd
[(s
- 'A') * 2 + p
->d
]);
929 static void R_draw_monsters (void) {
930 enum {SLEEP
, GO
, RUN
, CLIMB
, DIE
, DEAD
, ATTACK
, SHOOT
, PAIN
, WAIT
, REVIVE
, RUNOUT
}; // copypasted from monster.c!
932 for (i
= 0; i
< MAXMN
; i
++) {
933 if (mn
[i
].t
!= MN_NONE
) {
936 if (mn
[i
].t
< MN__LAST
) {
937 if ((mn
[i
].t
!= MN_SOUL
&& mn
[i
].t
!= MN_PAIN
) || mn
[i
].st
!= DEAD
) {
938 int ap
= mn
[i
].ap
[mn
[i
].ac
];
939 int d
= (ap
- 'A') * 2 + mn
[i
].d
;
940 int dir
= mn_sprd
[mn
[i
].t
- 1][d
];
941 if (mn
[i
].t
== MN_MAN
&& (ap
== 'E' || ap
== 'F')) {
942 R_gl_draw_image(&mn_sgun
[ap
- 'E'], x
, y
, mn
[i
].d
);
944 R_gl_draw_image(&mn_spr
[mn
[i
].t
- 1][d
], x
, y
, dir
);
945 if (mn
[i
].t
== MN_MAN
) {
946 R_gl_set_color(MANCOLOR
+ PLAYER_COLOR_OFFSET
);
947 R_gl_draw_image_color(&mn_man_msk
[d
], x
, y
, dir
);
950 if (mn
[i
].t
== MN_VILE
&& mn
[i
].st
== SHOOT
) {
951 R_gl_draw_image(&mn_fspr
[mn
[i
].ac
/ 3], mn
[i
].tx
, mn
[i
].ty
, 0);
953 } else if (mn
[i
].t
== MN_PL_DEAD
|| mn
[i
].t
== MN_PL_MESS
) {
954 int type
= mn
[i
].t
- MN_PL_DEAD
;
955 R_gl_draw_image(&pl_spr
[type
], x
, y
, 0);
956 R_gl_set_color(mn
[i
].d
);
957 R_gl_draw_image_color(&pl_msk
[type
], x
, y
, 0);
963 static void R_draw_weapons (void) {
964 enum {NONE
, ROCKET
, PLASMA
, APLASMA
, BALL1
, BALL2
, BALL7
, BFGBALL
, BFGHIT
, MANF
, REVF
, FIRE
}; // copypasted from weapons.c!
966 for (i
= 0; i
< MAXWPN
; ++i
) {
974 d
= wp
[i
].o
.xv
> 0 ? 1 : 0;
1022 d
= wp
[i
].o
.xv
>= 0 ? 1 : 0;
1026 d
= wp
[i
].o
.xv
>=0 ? 1 : 0;
1038 s
= wp
[i
].s
/ 2 + 26;
1042 R_gl_draw_image(&wp_spr
[s
* 2 + d
], wp
[i
].o
.x
, wp
[i
].o
.y
, wp_sprd
[s
* 2 + d
]);
1047 static void R_draw_smoke (void) {
1049 for (i
= 0; i
< MAXSMOK
; ++i
) {
1054 if (s
>= (SMSN
- 1) * 3) {
1057 s
= SMSN
- 1 - s
/ 3;
1059 R_gl_draw_image(&smk_spr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1063 if (s
>= FLSN
- 1) {
1068 R_gl_draw_image(&smk_fspr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1075 static void R_draw_effects (void) {
1076 enum {NONE
, TFOG
, IFOG
, BUBL
}; // copypasted from fx.c
1078 for (i
= 0; i
< MAXFX
; ++i
) {
1082 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1085 s
= fx
[i
].s
/ 2 + 10;
1086 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1090 R_gl_set_color(0xC0 + fx
[i
].s
);
1091 glVertex2i(fx
[i
].x
>> 8, (fx
[i
].y
>> 8) + 1);
1098 static int get_pu_st (int t
) {
1099 if (t
>= PL_FLASH
) {
1101 } else if((t
/ 9) & 1) {
1108 static void R_draw_view (int x
, int y
, int w
, int h
, int camx
, int camy
) {
1110 R_gl_setclip(x
, y
, w
, h
);
1111 glTranslatef(x
, y
, 0);
1112 if (w_horiz
&& horiz
.n
!= NULL
) {
1113 R_gl_draw_image_ext(&horiz
, 0, 0, w
, h
);
1114 if (sky_type
== 2 && lt_time
< 0) {
1115 image
*tanderbolt
= <n
[lt_type
][lt_time
< -5 ? 0 : 1];
1117 R_gl_draw_image(tanderbolt
, 0, lt_ypos
, 0);
1119 R_gl_draw_image(tanderbolt
, w
- 1, lt_ypos
, 1);
1123 glDisable(GL_BLEND
);
1124 R_gl_set_color(DEFAULT_SKY_COLOR
);
1125 R_gl_draw_quad(0, 0, w
, h
);
1127 int maxx
= min((camx
+ w
) / CELW
+ 1, FLDW
);
1128 int maxy
= min((camy
+ h
) / CELH
+ 1, FLDH
);
1129 int minx
= max((camx
- max_wall_width
) / CELW
, 0);
1130 int miny
= max((camy
- max_wall_height
) / CELH
, 0);
1131 glTranslatef(-camx
, -camy
, 0);
1132 R_draw_fld((byte
*)fldb
, minx
, miny
, maxx
, maxy
, 0);
1135 R_draw_player(&pl1
);
1137 R_draw_player(&pl2
);
1143 R_draw_fld((byte
*)fldf
, minx
, miny
, maxx
, maxy
, 1);
1144 glTranslatef(camx
, camy
, 0);
1145 if (sky_type
== 2 && (lt_time
== -4 || lt_time
== -2)) {
1146 glColor4ub(255, 255, 255, 255);
1148 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
1149 R_gl_draw_quad(0, 0, w
, h
);
1154 static void R_draw_player_view (player_t
*p
, int x
, int y
, int w
, int h
) {
1155 p
->looky
= min(max(p
->looky
, -SCRH
/ 4), SCRH
/ 4); // TODO remove writeback
1158 int cx
= min(max(p
->o
.x
, cw
/ 2), FLDW
* CELW
- cw
/ 2);
1159 int cy
= min(max(p
->o
.y
- 12 + p
->looky
, h
/ 2), FLDH
* CELH
- h
/ 2);
1160 int camx
= max(cx
- cw
/ 2, 0);
1161 int camy
= max(cy
- h
/ 2, 0);
1163 R_draw_view(x
, y
+ 1, cw
, h
- 2, camx
, camy
);
1164 glTranslatef(x
, y
, 0);
1166 if (get_pu_st(p
->invl
)) {
1168 glColor4ub(191, 191, 191, 255);
1169 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
);
1170 R_gl_draw_quad(0, 0, cw
, h
);
1173 if (p
->suit
&& get_pu_st(p
->suit
)) {
1175 glColor4ub(0, 255, 0, 192);
1176 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1177 R_gl_draw_quad(0, 0, cw
, h
);
1179 int f
= min(max(p
->pain
* 3, 0), 255);
1182 glColor4ub(255, 0, 0, f
);
1183 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1184 R_gl_draw_quad(0, 0, cw
, h
);
1187 R_gl_setclip(x
, y
, w
, h
);
1188 glTranslatef(-x
+ cw
, 0, 0);
1189 R_gl_draw_image(&stone
, 0, 0, 0);
1192 R_gl_draw_image(&stone2
, 0, i
, 0);
1195 if (p
->drawst
& PL_DRAWAIR
) {
1196 if (p
->air
< PL_AIR
) {
1197 int a
= min(max(p
->air
, 0), MAXAIR
) * 100 / MAXAIR
;
1198 glDisable(GL_BLEND
);
1199 R_gl_set_color(0xC8);
1200 R_gl_draw_quad(10, 49, a
, 2);
1203 if (p
->drawst
& PL_DRAWLIFE
) {
1205 Z_printhf("%3d%%", p
->life
);
1207 if (p
->drawst
& PL_DRAWARMOR
) {
1208 Z_gotoxy(10, 7 + 19);
1209 Z_printhf("%3d%%", p
->armor
);
1211 if (p
->drawst
& PL_DRAWWPN
) {
1238 R_gl_draw_image(&sth
[12 + p
->wpn
], st
- 88, 58 + 19, 0);
1242 Z_gotoxy(st
- 10 - 5 * 14, 58 + 2);
1243 Z_printhf("%5d", i
);
1246 if (p
->drawst
& PL_DRAWFRAG
&& g_dm
) {
1247 Z_gotoxy(st
- 5 - 5 * 14, 77 + 5);
1248 Z_printhf("%5d", p
->frag
);
1250 if (p
->drawst
& PL_DRAWKEYS
) {
1252 for (k
= p
->keys
>> 4, n
= 0, x
= st
- 75; n
< 3; n
++, k
>>= 1, x
+= 9) {
1254 R_gl_draw_image(&keys
[n
], x
, 91, 0);
1258 if (p
->drawst
& PL_DRAWLIVES
&& !_2pl
) {
1259 Z_gotoxy(st
- 35, 17);
1260 Z_printhf("%d", p
->lives
);
1267 static void pl_info (player_t
*p
, int x
, int y
) {
1268 dword t
= p
->kills
* 10920 / g_time
;
1269 Z_gotoxy(x
+ 25, y
); Z_printbf("KILLS");
1270 Z_gotoxy(x
+ 25, y
+ 15); Z_printbf("KPM");
1271 Z_gotoxy(x
+ 25, y
+ 30); Z_printbf("SECRETS %u / %u", p
->secrets
, sw_secrets
);
1272 Z_gotoxy(x
+ 255, y
); Z_printbf("%u", p
->kills
);
1273 Z_gotoxy(x
+ 255, y
+ 15); Z_printbf("%u.%u", t
/ 10, t
% 10);
1276 static void R_draw_intermission (void) {
1279 Z_gotoxy(cx
- 14*12/2, 20);
1280 Z_printbf("LEVEL COMPLETE");
1281 Z_calc_time(g_time
, &hr
, &mn
, &sc
);
1282 Z_gotoxy(cx
- 12*12/2, 40);
1283 Z_printbf("TIME %u:%02u:%02u", hr
, mn
, sc
);
1286 Z_gotoxy(cx
- 10*12/2, h
);
1287 Z_printbf("PLAYER ONE");
1290 pl_info(&pl1
, cx
- 160, h
);
1292 h
+= 30 + SCRH
/ 10;
1293 Z_gotoxy(cx
- 10*12/2, h
);
1294 Z_printbf("PLAYER TWO");
1296 pl_info(&pl2
, cx
- 160, h
);
1300 static void W_act (void) {
1302 if (g_time
% 3 == 0) {
1303 for (i
= 1; i
< max_textures
; i
++) {
1307 if (anip
[a
][anic
[a
]].res
== -1) {
1310 walp
[i
] = anip
[a
][anic
[a
]];
1316 void R_draw (void) {
1318 glClearColor(0, 0, 0, 1);
1319 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
1320 glEnable(GL_SCISSOR_TEST
);
1331 R_gl_draw_image_ext(&scrnh
[0], 0, 0, SCRW
, SCRH
);
1334 R_gl_draw_image_ext(&scrnh
[1], 0, 0, SCRW
, SCRH
);
1335 R_draw_intermission();
1338 R_gl_draw_image_ext(&scrnh
[2], 0, 0, SCRW
, SCRH
);
1342 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
/ 2);
1343 R_draw_player_view(&pl2
, 0, SCRH
/ 2, SCRW
, SCRH
/ 2);
1345 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
);
1347 R_gl_setclip(0, 0, SCRW
, SCRH
);
1351 SDL_GL_SwapBuffers();
1354 void R_alloc (void) {
1357 logo("R_alloc: load graphics\n");
1359 scrnh
[0] = R_gl_loadimage("TITLEPIC");
1361 scrnh
[1] = R_gl_loadimage("INTERPIC");
1362 scrnh
[2] = R_gl_loadimage("ENDPIC");
1363 for (i
= 0; i
< 2; i
++) {
1364 sprintf(s
, "LTN%c", '1' + i
);
1365 for (j
= 0; j
< 2; j
++) {
1366 ltn
[i
][j
] = Z_getspr(s
, j
, 0, NULL
);
1370 for (i
= 0; i
< SMSN
; i
++) {
1371 smk_spr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_smoke_spr
);
1373 for (i
= 0; i
< FLSN
; i
++) {
1374 smk_fspr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_flame_spr
);
1377 for (i
= 0; i
< 10; i
++) {
1378 fx_spr
[i
] = Z_getspr("TFOG", i
, 0, fx_sprd
+ i
);
1380 for (; i
< 15; i
++) {
1381 fx_spr
[i
] = Z_getspr("IFOG", i
- 10, 0, fx_sprd
+ i
);
1384 for (i
= 0; i
< 4; i
++) {
1385 wp_spr
[i
* 2] = Z_getspr("MISL", i
, 1, wp_sprd
+ i
* 2);
1386 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
, 2, wp_sprd
+ i
* 2 + 1);
1388 for (; i
< 6; i
++) {
1389 wp_spr
[i
* 2] = Z_getspr("PLSS", i
- 4, 1, wp_sprd
+ i
* 2);
1390 wp_spr
[i
* 2 + 1] = Z_getspr("PLSS", i
- 4, 2, wp_sprd
+ i
* 2 + 1);
1392 for (; i
< 11; i
++) {
1393 wp_spr
[i
* 2] = Z_getspr("PLSE", i
- 6, 1, wp_sprd
+ i
* 2);
1394 wp_spr
[i
* 2 + 1] = Z_getspr("PLSE", i
- 6, 2, wp_sprd
+ i
* 2 + 1);
1396 for (; i
< 13; i
++) {
1397 wp_spr
[i
* 2] = Z_getspr("APLS", i
- 11, 1, wp_sprd
+ i
* 2);
1398 wp_spr
[i
* 2 + 1] = Z_getspr("APLS", i
- 11, 2, wp_sprd
+ i
* 2 + 1);
1400 for (; i
< 18; i
++) {
1401 wp_spr
[i
* 2] = Z_getspr("APBX", i
- 13, 1, wp_sprd
+ i
* 2);
1402 wp_spr
[i
* 2 + 1] = Z_getspr("APBX", i
- 13, 2, wp_sprd
+ i
* 2 + 1);
1404 for(; i
< 20; i
++) {
1405 wp_spr
[i
* 2] = Z_getspr("BFS1", i
- 18, 1, wp_sprd
+ i
* 2);
1406 wp_spr
[i
* 2 + 1] = Z_getspr("BFS1", i
- 18, 2, wp_sprd
+ i
* 2 + 1);
1408 for (; i
< 26; i
++) {
1409 wp_spr
[i
* 2] = Z_getspr("BFE1", i
- 20, 1, wp_sprd
+ i
* 2);
1410 wp_spr
[i
* 2 + 1] = Z_getspr("BFE1", i
- 20, 2, wp_sprd
+ i
* 2 + 1);
1412 for (; i
< 30; i
++) {
1413 wp_spr
[i
* 2] = Z_getspr("BFE2", i
- 26, 1, wp_sprd
+ i
* 2);
1414 wp_spr
[i
* 2 + 1] = Z_getspr("BFE2", i
- 26, 2, wp_sprd
+ i
* 2 + 1);
1416 for (; i
< 32; i
++) {
1417 wp_spr
[i
* 2] = Z_getspr("MISL", i
- 30 + 4, 1, wp_sprd
+ i
* 2);
1418 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
- 30 + 4, 2, wp_sprd
+ i
* 2 + 1);
1420 for (; i
< 37; i
++) {
1421 wp_spr
[i
* 2] = Z_getspr("BAL1", i
- 32, 1, wp_sprd
+ i
* 2);
1422 wp_spr
[i
* 2 + 1] = Z_getspr("BAL1", i
- 32, 2, wp_sprd
+ i
* 2 + 1);
1424 for (; i
< 42; i
++) {
1425 wp_spr
[i
* 2] = Z_getspr("BAL7", i
- 37, 1, wp_sprd
+ i
* 2);
1426 wp_spr
[i
* 2 + 1] = Z_getspr("BAL7", i
- 37, 2, wp_sprd
+ i
* 2 + 1);
1428 for (; i
< 47; i
++) {
1429 wp_spr
[i
* 2] = Z_getspr("BAL2", i
- 42, 1, wp_sprd
+ i
* 2);
1430 wp_spr
[i
* 2 + 1] = Z_getspr("BAL2", i
- 42, 2, wp_sprd
+ i
* 2 + 1);
1432 for (; i
< 49; i
++) {
1433 wp_spr
[i
* 2] = Z_getspr("MANF", i
- 47, 1, wp_sprd
+ i
* 2);
1434 wp_spr
[i
* 2 + 1] = Z_getspr("MANF", i
- 47, 2, wp_sprd
+ i
* 2 + 1);
1437 static const char snm
[18][4] = {
1438 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1439 "STIM", "MEDI", "BPAK",
1440 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1442 static const char n4
[4][4] = {
1443 "SOUL", "SMRT", "SMGT", "SMBT"
1445 static const char n3
[2][4] = {
1448 for (i
= 0; i
< 18; i
++) {
1449 item_spr
[i
] = Z_getspr(snm
[i
], 0, 0, item_sprd
+ i
);
1451 for (; i
< 20; i
++) {
1452 item_spr
[i
] = Z_getspr("ARM1", i
- 18, 0, item_sprd
+ i
);
1453 item_spr
[i
+ 2] = Z_getspr("ARM2", i
- 18, 0, item_sprd
+ i
);
1456 for (; i
< 26; i
++) {
1457 item_spr
[i
] = Z_getspr("MEGA", i
- 22, 0, item_sprd
+ i
);
1459 for (; i
< 30; i
++) {
1460 item_spr
[i
] = Z_getspr("PINV", i
- 26, 0, item_sprd
+ i
);
1462 item_spr
[30] = Z_getspr("AQUA", 0, 0, item_sprd
+ 30);
1463 item_spr
[31] = Z_getspr("KEYR", 0, 0, item_sprd
+ 31);
1464 item_spr
[32] = Z_getspr("KEYG", 0, 0, item_sprd
+ 32);
1465 item_spr
[33] = Z_getspr("KEYB", 0, 0, item_sprd
+ 33);
1466 item_spr
[34] = Z_getspr("SUIT", 0, 0, item_sprd
+ 34);
1467 for (n
= 35, j
= 0; j
< 4; j
++) {
1468 for (i
= 0; i
< 4; i
++, n
++) {
1469 item_spr
[n
] = Z_getspr(n4
[j
], i
, 0, item_sprd
+ n
);
1472 for (j
= 0; j
< 2; j
++) {
1473 for (i
= 0; i
< 3; i
++, n
++) {
1474 item_spr
[n
] = Z_getspr(n3
[j
], i
, 0, item_sprd
+ n
);
1477 item_spr
[57] = Z_getspr("GUN2", 0, 0, item_sprd
+ 57);
1479 for (i
= 0; i
< 27; i
++) {
1480 plr_spr
[i
* 2] = Z_getspr("PLAY", i
, 1, plr_sprd
+ i
* 2);
1481 plr_msk
[i
* 2] = R_gl_get_special_spr("PLAY", i
, 1, &R_extract_mask_spr
);
1482 plr_spr
[i
* 2 + 1] = Z_getspr("PLAY", i
, 2, plr_sprd
+ i
* 2 + 1);
1483 plr_msk
[i
* 2 + 1] = R_gl_get_special_spr("PLAY", i
, 2, &R_extract_mask_spr
);
1485 strncpy(s
, "PWPx", 4);
1486 for (i
= 1; i
< 11; i
++) {
1487 s
[3] = (i
< 10 ? '0' : 'A' - 10) + i
;
1488 for (j
= 0; j
< 6; j
++) {
1489 plr_wpn
[i
][j
] = Z_getspr(s
, j
, 1, NULL
);
1493 static const char msn
[MN_TN
][4] = {
1494 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1495 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1497 static const int mms
[MN_TN
] = {
1498 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1499 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1501 mn_sgun
[0] = Z_getspr("PWP4", 0, 1, NULL
);
1502 mn_sgun
[1] = Z_getspr("PWP4", 1, 1, NULL
);
1503 for (j
= 0; j
< MN_TN
; j
++) {
1504 for (i
= 0; i
< mms
[j
]; i
++) {
1505 mn_spr
[j
][i
] = Z_getspr(msn
[j
], i
/ 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1506 if (j
== MN_MAN
- 1) {
1507 mn_man_msk
[i
] = R_gl_get_special_spr(msn
[j
], i
/ 2, (i
& 1) + 1, &R_extract_mask_spr
);
1510 if (j
== MN_BARREL
- 1) {
1511 for (i
= 4; i
< 14; i
++) {
1512 mn_spr
[j
][i
] = Z_getspr("BEXP", i
/ 2 - 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1516 for (i
= 0; i
< 8; i
++) {
1517 mn_fspr
[i
] = Z_getspr("FIRE", i
, 0, NULL
);
1519 pl_spr
[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL
);
1520 pl_msk
[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr
);
1521 pl_spr
[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL
);
1522 pl_msk
[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr
);
1524 static const char mnm
[22][8]={
1525 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1526 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1527 "STTMINUS", "STTPRCNT",
1528 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1529 "PLASA0", "BFUGA0", "GUN2A0"
1531 stone
= R_gl_loadimage("STONE");
1532 stone2
= R_gl_loadimage("STONE2");
1533 keys
[0] = R_gl_loadimage("KEYRA0");
1534 keys
[1] = R_gl_loadimage("KEYGA0");
1535 keys
[2] = R_gl_loadimage("KEYBA0");
1536 for (i
= 0; i
< 22; i
++) {
1537 sth
[i
] = R_gl_loadimage(mnm
[i
]);
1539 strcpy(s
, "STBF_*");
1540 for (i
= '!'; i
< 160; i
++) {
1542 bfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1544 for (i
= '!'; i
< 160; i
++) {
1545 sprintf(s
, "STCFN%03d", i
);
1546 sfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1548 strcpy(s
, "WINUM*");
1549 for (i
= '0'; i
<= '9'; i
++) {
1551 bfh
[i
- '!'] = R_gl_loadimage(s
);
1553 bfh
[':' - '!'] = R_gl_loadimage("WICOLON");
1555 msklh
[0] = R_gl_loadimage("M_SKULL1");
1556 msklh
[1] = R_gl_loadimage("M_SKULL2");
1557 mbarl
= R_gl_loadimage("M_THERML");
1558 mbarm
= R_gl_loadimage("M_THERMM");
1559 mbarr
= R_gl_loadimage("M_THERMR");
1560 mbaro
= R_gl_loadimage("M_THERMO");
1561 mslotl
= R_gl_loadimage("M_LSLEFT");
1562 mslotm
= R_gl_loadimage("M_LSCNTR");
1563 mslotr
= R_gl_loadimage("M_LSRGHT");
1565 for (i
= 1; i
< ANIT
; i
++) {
1566 for (j
= 0; anm
[i
- 1][j
]; j
++) {
1567 anip
[i
][j
] = R_gl_loadimage(anm
[i
- 1][j
]);
1570 anip
[i
][j
] = (image
) {
1580 void R_init (void) {
1581 Uint32 flags
= SDL_OPENGL
;
1583 flags
= flags
| SDL_FULLSCREEN
;
1585 if (SCRW
<= 0 || SCRH
<= 0) {
1586 ERR_failinit("Invalid screen size %ix%i\n", SCRW
, SCRH
);
1589 R_init_playpal(); // only onece
1591 surf
= SDL_SetVideoMode(SCRW
, SCRH
, 0, flags
);
1593 ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
1595 root
= R_cache_new();
1600 void R_done (void) {
1604 void R_setgamma (int g
) {
1605 gamma
= g
< 0 ? 0 : (g
> 4 ? 4 : g
);
1608 int R_getgamma (void) {
1612 void R_toggle_fullscreen (void) {
1613 fullscreen
= !fullscreen
;
1615 R_init(); // recreate window
1619 void R_get_name (int n
, char s
[8]) {
1620 assert(n
>= 0 && n
< 256);
1621 if (walp
[n
].res
== -1) {
1623 } else if (walp
[n
].res
== -2) {
1624 memcpy(s
, "_WATER_", 8);
1625 s
[7] = '0' + (intptr_t)walp
[n
].n
- 1;
1626 } else if (walani
[n
] > 0) {
1627 memcpy(s
, anm
[walani
[n
] - 1][0], 8);
1629 F_getresname(s
, walp
[n
].res
& 0x7FFF);
1633 static short getani (char n
[8]) {
1635 while (i
< ANIT
- 1 && strncasecmp(n
, anm
[i
][0], 8) != 0) {
1638 return i
< ANIT
- 1 ? i
+ 1 : 0;
1641 int R_get_special_id (int n
) {
1642 assert(n
>= 0 && n
<= 256);
1643 return walp
[n
].res
== -2 ? (intptr_t)walp
[n
].n
: -1;
1646 void R_begin_load (void) {
1648 for (i
= 0; i
< 256; i
++) {
1649 if (walp
[i
].n
!= NULL
&& walp
[i
].res
>= 0 && walani
[i
] == 0) {
1650 R_gl_free_image(&walp
[i
]);
1652 memset(&walp
[i
], 0, sizeof(image
));
1657 memset(anic
, 0, sizeof(anic
));
1659 max_wall_height
= 0;
1663 void R_load (char s
[8], int f
) {
1664 assert(max_textures
< 256);
1666 walp
[max_textures
] = (image
) {
1674 } else if (strncasecmp(s
, "_WATER_", 7) == 0) {
1675 walp
[max_textures
] = (image
) {
1676 .n
= (void*)((intptr_t)s
[7] - '0' + 1),
1684 walp
[max_textures
] = R_gl_loadimage(s
);
1686 walp
[max_textures
].res
|= 0x8000;
1688 if (s
[0] == 'S' && s
[1] == 'W' && s
[4] == '_') {
1689 walswp
[max_textures
] = 0;
1691 walani
[max_textures
] = getani(s
);
1693 max_wall_width
= max(max_wall_width
, walp
[max_textures
].w
);
1694 max_wall_height
= max(max_wall_height
, walp
[max_textures
].h
);
1698 void R_end_load (void) {
1702 for (i
= 1; i
< 256 && j
< 256; i
++) {
1703 if (walswp
[i
] == 0) {
1706 g
= F_getresid(s
) | (walp
[i
].res
& 0x8000);
1708 while (k
< 256 && walp
[k
].res
!= g
) {
1714 walp
[k
] = R_gl_getimage(g
);
1715 walf
[k
] = g
& 0x8000 ? 1 : 0;
1723 void R_loadsky (int sky
) {
1725 logo("R_loadsky(%i)\n", sky
);
1728 R_gl_free_image(&horiz
);
1729 horiz
= R_gl_loadimage(s
);