13 #include "sound.h" // snd_vol
14 #include "music.h" // mus_vol
22 #include "switch.h" // sw_secrets
24 #include <OpenGL/GL.h>
25 #include <stdlib.h> // malloc free abs
26 #include <assert.h> // assert
29 #define VGA_TRANSPARENT_COLOR 0
30 #define DEFAULT_SKY_COLOR 0x97
32 #define PLAYER_COLOR_OFFSET 7
38 typedef struct vgaimg
{
55 struct node
*left
, *right
;
60 typedef struct cache
{
66 typedef struct image
{
74 int SCRW
= 320; // public
75 int SCRH
= 200; // public
77 static int fullscreen
;
78 static SDL_Surface
*surf
;
79 static rgb playpal
[256];
80 static byte bright
[256];
84 static image scrnh
[3]; // TITLEPIC INTERPIC ENDPIC
85 static image ltn
[2][2];
88 static image smk_spr
[SMSN
];
89 static image smk_fspr
[FLSN
];
92 static image fx_spr
[15];
93 static char fx_sprd
[15];
96 static image wp_spr
[49*2];
97 static char wp_sprd
[49*2];
100 static image item_spr
[58];
101 static char item_sprd
[58];
104 static image plr_spr
[27*2];
105 static image plr_msk
[27*2];
106 static char plr_sprd
[27*2];
107 static image plr_wpn
[11][6];
110 static image pl_spr
[2];
111 static image pl_msk
[2];
112 static image mn_spr
[MN_TN
][29*2];
113 static image mn_man_msk
[29*2];
114 static char mn_sprd
[MN_TN
][29*2];
115 static image mn_fspr
[8];
116 static image mn_sgun
[2];
119 static image sth
[22];
120 static image bfh
[160 - '!'];
121 static image sfh
[160 - '!'];
124 static image keys
[3];
130 static image msklh
[2];
140 static const char *anm
[ANIT
- 1][5] = {
141 {"WALL22_1", "WALL23_1", "WALL23_2", NULL
, NULL
},
142 {"WALL58_1", "WALL58_2", "WALL58_3", NULL
, NULL
},
143 {"W73A_1", "W73A_2", NULL
, NULL
, NULL
},
144 {"RP2_1", "RP2_2", "RP2_3", "RP2_4", NULL
}
146 static int max_wall_width
;
147 static int max_wall_height
;
148 static int max_textures
;
149 static image walp
[256];
150 static byte walani
[256];
151 static image anip
[ANIT
][5];
152 static byte anic
[ANIT
];
157 // https://blackpawn.com/texts/lightmaps/
158 static node
*R_node_alloc (node
*p
, int w
, int h
) {
164 node
*n
= R_node_alloc(p
->left
, w
, h
);
165 return n
? n
: R_node_alloc(p
->right
, w
, h
);
167 int pw
= p
->r
- p
->l
+ 1;
168 int ph
= p
->b
- p
->t
+ 1;
169 if (p
->leaf
|| pw
< w
|| ph
< h
) {
171 } else if (pw
== w
&& ph
== h
) {
175 p
->left
= malloc(sizeof(node
));
176 p
->right
= malloc(sizeof(node
));
177 if (pw
- w
> ph
- h
) {
204 return R_node_alloc(p
->left
, w
, h
);
209 static cache
*R_cache_new (void) {
213 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &size
);
214 size
/= 2; // TODO remove hack or detect ibook bug
216 glGenTextures(1, &id
);
218 glBindTexture(GL_TEXTURE_2D
, id
);
219 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
220 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
221 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, size
, size
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
222 int ok
= glGetError() == GL_NO_ERROR
;
223 glBindTexture(GL_TEXTURE_2D
, 0);
225 c
= malloc(sizeof(cache
));
235 glDeleteTextures(1, &id
);
239 logo("new cache %p\n", c
);
243 static node
*R_cache_alloc (cache
*root
, int w
, int h
) {
245 assert(w
> 0 && h
> 0);
250 n
= R_node_alloc(&c
->root
, w
, h
);
261 n
= R_node_alloc(&c
->root
, w
, h
);
270 static void R_cache_update (node
*n
, const void *data
, int w
, int h
) {
274 int nw
= n
->r
- n
->l
+ 1;
275 int nh
= n
->b
- n
->t
+ 1;
278 glBindTexture(GL_TEXTURE_2D
, n
->base
->id
);
279 glTexSubImage2D(GL_TEXTURE_2D
, 0, n
->l
, n
->t
, nw
, nh
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
280 assert(glGetError() == GL_NO_ERROR
);
281 glBindTexture(GL_TEXTURE_2D
, 0);
284 /* Generic helpers */
286 static void R_init_playpal (void) {
288 byte
*vgapal
= M_lock(F_getresid("PLAYPAL"));
289 for (i
= 0; i
< 256; i
++) {
291 .r
= vgapal
[i
* 3 + 0] * 255 / 63,
292 .g
= vgapal
[i
* 3 + 1] * 255 / 63,
293 .b
= vgapal
[i
* 3 + 2] * 255 / 63,
295 bright
[i
] = ((int)vgapal
[i
* 3 + 0] + vgapal
[i
* 3 + 1] + vgapal
[i
* 3 + 2]) * 8 / (63 * 3);
300 static vgaimg
*R_getvga (int id
) {
301 int loaded
= M_was_locked(id
);
302 vgaimg
*v
= M_lock(id
);
303 if (v
!= NULL
&& !loaded
) {
304 v
->w
= short2host(v
->w
);
305 v
->h
= short2host(v
->h
);
306 v
->x
= short2host(v
->x
);
307 v
->y
= short2host(v
->y
);
312 static rgba
*R_extract_flame_spr (vgaimg
*v
) {
313 static const byte flametab
[16] = {
314 0xBC, 0xBA, 0xB8, 0xB6, 0xB4, 0xB2, 0xB0, 0xD5,
315 0xD6, 0xD7, 0xA1, 0xA0, 0xE3, 0xE2, 0xE1, 0xE0
318 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
320 for (j
= 0; j
< v
->h
; j
++) {
321 for (i
= 0; i
< v
->w
; i
++) {
322 int k
= j
* v
->w
+ i
;
323 byte c
= v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
];
325 .r
= playpal
[flametab
[c
]].r
,
326 .g
= playpal
[flametab
[c
]].g
,
327 .b
= playpal
[flametab
[c
]].b
,
328 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
336 static rgba
*R_extract_smoke_spr (vgaimg
*v
) {
338 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
340 for (j
= 0; j
< v
->h
; j
++) {
341 for (i
= 0; i
< v
->w
; i
++) {
342 int k
= j
* v
->w
+ i
;
343 byte c
= ((v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
]) + 0x60) ^ 0x0F;
344 byte a
= 0xFF - ((int)playpal
[c
].r
+ playpal
[c
].g
+ playpal
[c
].b
) / 3;
349 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : a
,
357 static rgba
*R_extract_mask_spr (vgaimg
*v
) {
359 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
361 for (j
= 0; j
< v
->h
; j
++) {
362 for (i
= 0; i
< v
->w
; i
++) {
363 int k
= j
* v
->w
+ i
;
365 if (c
>= 0x70 && c
<= 0x7F) {
366 byte mask
= c
- 0x70;
367 mask
= 0xFF - ((mask
<< 4) | mask
);
388 static rgba
*R_extract_rgba_spr (vgaimg
*v
) {
390 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
392 for (j
= 0; j
< v
->h
; j
++) {
393 for (i
= 0; i
< v
->w
; i
++) {
394 int k
= j
* v
->w
+ i
;
400 .a
= c
== VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
410 static image
R_gl_create_image (const rgba
*buf
, int w
, int h
) {
411 node
*n
= R_cache_alloc(root
, w
, h
);
413 R_cache_update(n
, buf
, w
, h
);
423 static image
R_gl_get_special_image (int id
, rgba
*(*fn
)(vgaimg
*)) {
424 image img
= (image
) { .res
= -1 };
425 vgaimg
*v
= R_getvga(id
);
427 rgba
*buf
= (*fn
)(v
);
428 img
= R_gl_create_image(buf
, v
->w
, v
->h
);
438 static image
R_gl_getimage (int id
) {
439 return R_gl_get_special_image(id
, &R_extract_rgba_spr
);
442 static image
R_gl_loadimage (const char name
[8]) {
443 return R_gl_getimage(F_getresid(name
));
446 static image
R_gl_get_special_spr (const char n
[4], int s
, int d
, rgba
*(*fn
)(vgaimg
*)) {
447 return R_gl_get_special_image(F_getsprid(n
, s
, d
), fn
);
450 static void R_gl_free_image (image
*img
) {
451 if (img
->n
!= NULL
&& img
->res
>= 0) {
457 static void R_gl_draw_quad (int x
, int y
, int w
, int h
) {
459 glVertex2i(x
+ w
, y
);
461 glVertex2i(x
, y
+ h
);
462 glVertex2i(x
+ w
, y
+ h
);
466 static void R_gl_draw_textured (image
*img
, int x
, int y
, int w
, int h
, int flip
) {
468 GLfloat nw
= img
->n
->base
->root
.r
+ 1;
469 GLfloat nh
= img
->n
->base
->root
.b
+ 1;
470 GLfloat ax
= (flip
? img
->n
->l
: img
->n
->r
+ 1) / nw
;
471 GLfloat bx
= (flip
? img
->n
->r
+ 1 : img
->n
->l
) / nh
;
472 GLfloat ay
= (img
->n
->t
) / nw
;
473 GLfloat by
= (img
->n
->b
+ 1) / nh
;
474 glBindTexture(GL_TEXTURE_2D
, img
->n
->base
->id
);
475 glEnable(GL_TEXTURE_2D
);
477 glTexCoord2f(ax
, ay
); glVertex2i(x
+ w
, y
);
478 glTexCoord2f(bx
, ay
); glVertex2i(x
, y
);
479 glTexCoord2f(bx
, by
); glVertex2i(x
, y
+ h
);
480 glTexCoord2f(ax
, by
); glVertex2i(x
+ w
, y
+ h
);
482 glDisable(GL_TEXTURE_2D
);
483 glBindTexture(GL_TEXTURE_2D
, 0);
485 glColor3ub(255, 0, 0);
487 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
488 R_gl_draw_quad(x
, y
, w
, h
);
492 /* fit image into rectangle without applying offset and transparency */
493 static void R_gl_draw_image_ext (image
*img
, int x
, int y
, int w
, int h
) {
495 glColor3ub(255, 255, 255);
496 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
497 R_gl_draw_textured(img
, x
, y
, w
, h
, 0);
500 /* draw sprite with offset and coloring */
501 static void R_gl_draw_image_color (image
*img
, int x
, int y
, int flip
) {
502 int xx
= flip
? x
- img
->w
+ img
->x
: x
- img
->x
;
504 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
505 R_gl_draw_textured(img
, xx
, y
- img
->y
, img
->w
, img
->h
, flip
);
509 /* draw sprite with offset */
510 static void R_gl_draw_image (image
*img
, int x
, int y
, int flip
) {
511 int xx
= flip
? x
- img
->w
+ img
->x
: x
- img
->x
;
513 glColor3ub(255, 255, 255);
514 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
515 R_gl_draw_textured(img
, xx
, y
- img
->y
, img
->w
, img
->h
, flip
);
518 static void R_gl_set_color (byte c
) {
519 glColor3ub(playpal
[c
].r
, playpal
[c
].g
, playpal
[c
].b
);
522 static void R_gl_setclip (int x
, int y
, int w
, int h
) {
523 glScissor(x
, SCRH
- h
- y
, w
, h
);
526 static void R_gl_setmatrix (void) {
527 glScissor(0, 0, SCRW
, SCRH
);
528 glViewport(0, 0, SCRW
, SCRH
);
529 glMatrixMode(GL_PROJECTION
);
531 glOrtho(0, SCRW
, SCRH
, 0, 0, 1);
532 glMatrixMode(GL_MODELVIEW
);
538 static image
Z_getspr (const char n
[4], int s
, int d
, char *dir
) {
539 int h
= F_getsprid(n
, s
, d
);
541 *dir
= (h
& 0x8000) ? 1 : 0;
543 return R_gl_getimage(h
);
546 static void Z_putch_generic (image img
[], int off
, int ch
) {
548 if (ch
> 32 && ch
< 160) {
552 R_gl_draw_image(p
, prx
, pry
, 0);
559 static void Z_printf_generic (image img
[], int off
, const char *fmt
, va_list ap
) {
562 vsprintf(buf
, fmt
, ap
);
563 for (i
= 0; buf
[i
]; ++i
) {
571 Z_putch_generic(img
, off
, (byte
)buf
[i
]);
576 static void Z_gotoxy (int x
, int y
) {
581 static void Z_printbf (const char *fmt
, ...) {
584 Z_printf_generic(bfh
, 12, fmt
, a
);
588 static void Z_printsf (const char *fmt
, ...) {
591 Z_printf_generic(sfh
, 7, fmt
, a
);
595 static void Z_printhf (const char *fmt
, ...) {
600 vsprintf(buf
, fmt
, a
);
602 for (i
= 0; buf
[i
]; ++i
) {
633 R_gl_draw_image(&sth
[c
], prx
, pry
, 0);
641 static image
*PL_getspr (int s
, int d
, int msk
) {
642 int i
= (s
- 'A') * 2 + d
;
643 return msk
? &plr_msk
[i
] : &plr_spr
[i
];
646 static void GM_draw (void) {
647 enum {MENU
, MSG
}; // copypasted from menu.c!
649 CANCEL
, NEWGAME
, LOADGAME
, SAVEGAME
, OPTIONS
, QUITGAME
, QUIT
, ENDGAME
, ENDGM
,
650 PLR1
, PLR2
, COOP
, DM
, VOLUME
, GAMMA
, LOAD
, SAVE
, PLCOLOR
, PLCEND
, MUSIC
, INTERP
,
651 SVOLM
, SVOLP
, MVOLM
, MVOLP
, GAMMAM
, GAMMAP
, PL1CM
, PL1CP
, PL2CM
, PL2CP
652 }; // copypasted from menu.c!
653 int i
, j
, k
, x
, y
, cx
, cy
;
659 if (mnu
->type
== MENU
) {
660 y
= cy
- (mnu
->n
* 16 - 20) / 2;
661 Z_gotoxy(cx
- mnu
->x
, y
- 10); Z_printbf("%s", mnu
->ttl
);
662 for (i
= 0; i
< mnu
->n
; i
++) {
663 if (mnu
->t
[i
] == LOAD
|| mnu
->t
[i
] == SAVE
) {
665 R_gl_draw_image(&mslotl
, cx
- mnu
->x
, j
, 0);
666 for (k
= 8; k
< 184; k
+= 8) {
667 R_gl_draw_image(&mslotm
, cx
- mnu
->x
+ k
, j
, 0);
669 R_gl_draw_image(&mslotr
, cx
- mnu
->x
+ 184, j
, 0);
670 Z_gotoxy(cx
- mnu
->x
+ 4, j
- 8);
671 if (input
&& i
== save_mnu
.cur
) {
672 Z_printsf("%s_", ibuf
);
674 Z_printsf("%s", savname
[i
]);
677 x
= mnu
->t
[i
] >= SVOLM
? (mnu
->t
[i
] >= PL1CM
? 50 : 152) : 0;
678 Z_gotoxy(cx
- mnu
->x
+ x
, y
+ i
* 16 + 20);
679 Z_printbf("%s", mnu
->m
[i
]);
682 Z_printbf(" '%s'", g_music
);
685 Z_printbf("%s", fullscreen
? "ON" : "OFF");
691 img
= PL_getspr(*panimp
, 0, 0);
692 R_gl_draw_image(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
693 img
= PL_getspr(*panimp
, 0, 1);
694 R_gl_set_color(pcolortab
[(mnu
->t
[i
] == PL1CM
) ? p1color
: p2color
] + PLAYER_COLOR_OFFSET
);
695 R_gl_draw_image_color(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
704 R_gl_draw_image(&mbarl
, cx
- mnu
->x
, j
, 0);
705 for (k
= 8; k
< 144; k
+= 8) {
706 R_gl_draw_image(&mbarm
, cx
- mnu
->x
+ k
, j
, 0);
708 R_gl_draw_image(&mbarr
, cx
- mnu
->x
+ 144, j
, 0);
723 R_gl_draw_image(&mbaro
, cx
- mnu
->x
+ 8 + k
, j
, 0);
728 R_gl_draw_image(&msklh
[(gm_tm
/ 6) & 1], cx
- mnu
->x
- 25, y
+ mnu
->cur
* 16 + 20 - 8, 0);
729 } else if (mnu
->type
== MSG
) {
730 Z_gotoxy(cx
- strlen(mnu
->ttl
) * 7 / 2, cy
- 10); Z_printsf(mnu
->ttl
);
731 Z_gotoxy(cx
- 24, SCRH
/ 2); Z_printsf("(Y/N)");
733 ERR_fatal("Unknown menu type %i\n", mnu
->type
);
740 static void R_draw_fld (byte
*fld
, int minx
, int miny
, int maxx
, int maxy
, int fg
) {
742 assert(minx
>= 0 && minx
<= FLDW
);
743 assert(miny
>= 0 && miny
<= FLDH
);
744 assert(maxx
>= 0 && maxx
<= FLDW
);
745 assert(maxy
>= 0 && maxy
<= FLDH
);
746 for (j
= miny
; j
< maxy
; j
++) {
747 for (i
= minx
; i
< maxx
; i
++) {
748 byte id
= fld
[j
* FLDW
+ i
];
750 if (walp
[id
].res
< 0) {
752 switch (R_get_special_id(id
)) {
754 glColor4ub(0, 0, 255, 127);
757 glColor4ub(0, 127, 0, 127);
760 glColor4ub(127, 0, 0, 127);
763 glColor4ub(0, 0, 0, 127);
767 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
768 R_gl_draw_quad(i
* CELW
, j
* CELW
, CELW
, CELH
);
771 R_gl_draw_image(&walp
[id
], i
* CELW
, j
* CELH
, 0);
778 static void R_draw_dots (void) {
781 for (i
= 0; i
< MAXDOT
; i
++) {
783 R_gl_set_color(dot
[i
].c
);
784 glVertex2i(dot
[i
].o
.x
, dot
[i
].o
.y
+ 1);
790 static void R_draw_items (void) {
792 for (i
= 0; i
< MAXITEM
; ++i
) {
794 if (it
[i
].t
&& it
[i
].s
>= 0) {
795 switch (it
[i
].t
& 0x7FFF) {
797 s
= it
[i
].s
/ 9 + 18;
800 s
= it
[i
].s
/ 9 + 20;
803 s
= it
[i
].s
/ 2 + 22;
806 s
= it
[i
].s
/ 2 + 26;
812 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_SUPER
) * 4 + 35;
814 case I_GOR1
: case I_FCAN
:
815 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_GOR1
) * 3 + 51;
826 s
= (it
[i
].t
& 0x7FFF) - I_KEYR
+ 31;
832 s
= (it
[i
].t
& 0x7FFF) - 1;
836 R_gl_draw_image(&item_spr
[s
], it
[i
].o
.x
, it
[i
].o
.y
, item_sprd
[s
]);
841 static int standspr (player_t
*p
) {
844 } else if (p
->f
& PLF_DOWN
) {
851 static int wpnspr (player_t
*p
) {
854 } else if(p
->f
& PLF_DOWN
) {
861 static void R_draw_player (player_t
*p
) {
862 enum {STAND
, GO
, DIE
, SLOP
, DEAD
, MESS
, OUT
, FALL
}; // copypasted from player.c!
863 static const int wytab
[] = {-1, -2, -1, 0};
870 if (p
->f
& PLF_FIRE
) {
873 } else if (p
->pain
) {
896 s
= plr_goanim
[p
->s
/ 8];
897 w
= (p
->f
& PLF_FIRE
) ? 'B' : 'A';
899 wy
= 1 + wytab
[s
- 'A'];
903 s
= plr_dieanim
[p
->s
];
906 s
= plr_slopanim
[p
->s
];
916 R_gl_draw_image(&plr_wpn
[(int)p
->wpn
][w
-'A'], p
->o
.x
+ wx
, p
->o
.y
+ wy
, p
->d
);
919 R_gl_draw_image(&plr_spr
[(s
- 'A') * 2 + p
->d
], p
->o
.x
, p
->o
.y
, plr_sprd
[(s
- 'A') * 2 + p
->d
]);
920 R_gl_set_color(p
->color
+ PLAYER_COLOR_OFFSET
);
921 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
]);
925 static void R_draw_monsters (void) {
926 enum {SLEEP
, GO
, RUN
, CLIMB
, DIE
, DEAD
, ATTACK
, SHOOT
, PAIN
, WAIT
, REVIVE
, RUNOUT
}; // copypasted from monster.c!
928 for (i
= 0; i
< MAXMN
; i
++) {
929 if (mn
[i
].t
!= MN_NONE
) {
932 if (mn
[i
].t
< MN__LAST
) {
933 if ((mn
[i
].t
!= MN_SOUL
&& mn
[i
].t
!= MN_PAIN
) || mn
[i
].st
!= DEAD
) {
934 int ap
= mn
[i
].ap
[mn
[i
].ac
];
935 int d
= (ap
- 'A') * 2 + mn
[i
].d
;
936 int dir
= mn_sprd
[mn
[i
].t
- 1][d
];
937 if (mn
[i
].t
== MN_MAN
&& (ap
== 'E' || ap
== 'F')) {
938 R_gl_draw_image(&mn_sgun
[ap
- 'E'], x
, y
, mn
[i
].d
);
940 R_gl_draw_image(&mn_spr
[mn
[i
].t
- 1][d
], x
, y
, dir
);
941 if (mn
[i
].t
== MN_MAN
) {
942 R_gl_set_color(MANCOLOR
+ PLAYER_COLOR_OFFSET
);
943 R_gl_draw_image_color(&mn_man_msk
[d
], x
, y
, dir
);
946 if (mn
[i
].t
== MN_VILE
&& mn
[i
].st
== SHOOT
) {
947 R_gl_draw_image(&mn_fspr
[mn
[i
].ac
/ 3], mn
[i
].tx
, mn
[i
].ty
, 0);
949 } else if (mn
[i
].t
== MN_PL_DEAD
|| mn
[i
].t
== MN_PL_MESS
) {
950 int type
= mn
[i
].t
- MN_PL_DEAD
;
951 R_gl_draw_image(&pl_spr
[type
], x
, y
, 0);
952 R_gl_set_color(mn
[i
].d
);
953 R_gl_draw_image_color(&pl_msk
[type
], x
, y
, 0);
959 static void R_draw_weapons (void) {
960 enum {NONE
, ROCKET
, PLASMA
, APLASMA
, BALL1
, BALL2
, BALL7
, BFGBALL
, BFGHIT
, MANF
, REVF
, FIRE
}; // copypasted from weapons.c!
962 for (i
= 0; i
< MAXWPN
; ++i
) {
970 d
= wp
[i
].o
.xv
> 0 ? 1 : 0;
1018 d
= wp
[i
].o
.xv
>= 0 ? 1 : 0;
1022 d
= wp
[i
].o
.xv
>=0 ? 1 : 0;
1034 s
= wp
[i
].s
/ 2 + 26;
1038 R_gl_draw_image(&wp_spr
[s
* 2 + d
], wp
[i
].o
.x
, wp
[i
].o
.y
, wp_sprd
[s
* 2 + d
]);
1043 static void R_draw_smoke (void) {
1045 for (i
= 0; i
< MAXSMOK
; ++i
) {
1050 if (s
>= (SMSN
- 1) * 3) {
1053 s
= SMSN
- 1 - s
/ 3;
1055 R_gl_draw_image(&smk_spr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1059 if (s
>= FLSN
- 1) {
1064 R_gl_draw_image(&smk_fspr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1071 static void R_draw_effects (void) {
1072 enum {NONE
, TFOG
, IFOG
, BUBL
}; // copypasted from fx.c
1074 for (i
= 0; i
< MAXFX
; ++i
) {
1078 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1081 s
= fx
[i
].s
/ 2 + 10;
1082 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1086 R_gl_set_color(0xC0 + fx
[i
].s
);
1087 glVertex2i(fx
[i
].x
>> 8, (fx
[i
].y
>> 8) + 1);
1094 static int get_pu_st (int t
) {
1095 if (t
>= PL_FLASH
) {
1097 } else if((t
/ 9) & 1) {
1104 static void R_draw_view (int x
, int y
, int w
, int h
, int camx
, int camy
) {
1106 R_gl_setclip(x
, y
, w
, h
);
1107 glTranslatef(x
, y
, 0);
1108 if (w_horiz
&& horiz
.n
!= NULL
) {
1109 R_gl_draw_image_ext(&horiz
, 0, 0, w
, h
);
1110 if (sky_type
== 2 && lt_time
< 0) {
1111 image
*tanderbolt
= <n
[lt_type
][lt_time
< -5 ? 0 : 1];
1113 R_gl_draw_image(tanderbolt
, 0, lt_ypos
, 0);
1115 R_gl_draw_image(tanderbolt
, w
- 1, lt_ypos
, 1);
1119 glDisable(GL_BLEND
);
1120 R_gl_set_color(DEFAULT_SKY_COLOR
);
1121 R_gl_draw_quad(0, 0, w
, h
);
1123 int maxx
= min((camx
+ w
) / CELW
+ 1, FLDW
);
1124 int maxy
= min((camy
+ h
) / CELH
+ 1, FLDH
);
1125 int minx
= max((camx
- max_wall_width
) / CELW
, 0);
1126 int miny
= max((camy
- max_wall_height
) / CELH
, 0);
1127 glTranslatef(-camx
, -camy
, 0);
1128 R_draw_fld((byte
*)fldb
, minx
, miny
, maxx
, maxy
, 0);
1131 R_draw_player(&pl1
);
1133 R_draw_player(&pl2
);
1139 R_draw_fld((byte
*)fldf
, minx
, miny
, maxx
, maxy
, 1);
1140 glTranslatef(camx
, camy
, 0);
1141 if (sky_type
== 2 && (lt_time
== -4 || lt_time
== -2)) {
1142 glColor4ub(255, 255, 255, 255);
1144 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
1145 R_gl_draw_quad(0, 0, w
, h
);
1150 static void R_draw_player_view (player_t
*p
, int x
, int y
, int w
, int h
) {
1151 p
->looky
= min(max(p
->looky
, -SCRH
/ 4), SCRH
/ 4); // TODO remove writeback
1154 int cx
= min(max(p
->o
.x
, cw
/ 2), FLDW
* CELW
- cw
/ 2);
1155 int cy
= min(max(p
->o
.y
- 12 + p
->looky
, h
/ 2), FLDH
* CELH
- h
/ 2);
1156 int camx
= max(cx
- cw
/ 2, 0);
1157 int camy
= max(cy
- h
/ 2, 0);
1159 R_draw_view(x
, y
+ 1, cw
, h
- 2, camx
, camy
);
1160 glTranslatef(x
, y
, 0);
1162 if (get_pu_st(p
->invl
)) {
1164 glColor4ub(191, 191, 191, 255);
1165 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
);
1166 R_gl_draw_quad(0, 0, cw
, h
);
1169 if (p
->suit
&& get_pu_st(p
->suit
)) {
1171 glColor4ub(0, 255, 0, 192);
1172 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1173 R_gl_draw_quad(0, 0, cw
, h
);
1175 int f
= min(max(p
->pain
* 3, 0), 255);
1178 glColor4ub(255, 0, 0, f
);
1179 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1180 R_gl_draw_quad(0, 0, cw
, h
);
1183 R_gl_setclip(x
, y
, w
, h
);
1184 glTranslatef(-x
+ cw
, 0, 0);
1185 R_gl_draw_image(&stone
, 0, 0, 0);
1188 R_gl_draw_image(&stone2
, 0, i
, 0);
1191 if (p
->drawst
& PL_DRAWAIR
) {
1192 if (p
->air
< PL_AIR
) {
1193 int a
= min(max(p
->air
, 0), MAXAIR
) * 100 / MAXAIR
;
1194 glDisable(GL_BLEND
);
1195 R_gl_set_color(0xC8);
1196 R_gl_draw_quad(10, 49, a
, 2);
1199 if (p
->drawst
& PL_DRAWLIFE
) {
1201 Z_printhf("%3d%%", p
->life
);
1203 if (p
->drawst
& PL_DRAWARMOR
) {
1204 Z_gotoxy(10, 7 + 19);
1205 Z_printhf("%3d%%", p
->armor
);
1207 if (p
->drawst
& PL_DRAWWPN
) {
1234 R_gl_draw_image(&sth
[12 + p
->wpn
], st
- 88, 58 + 19, 0);
1238 Z_gotoxy(st
- 10 - 5 * 14, 58 + 2);
1239 Z_printhf("%5d", i
);
1242 if (p
->drawst
& PL_DRAWFRAG
&& g_dm
) {
1243 Z_gotoxy(st
- 5 - 5 * 14, 77 + 5);
1244 Z_printhf("%5d", p
->frag
);
1246 if (p
->drawst
& PL_DRAWKEYS
) {
1248 for (k
= p
->keys
>> 4, n
= 0, x
= st
- 75; n
< 3; n
++, k
>>= 1, x
+= 9) {
1250 R_gl_draw_image(&keys
[n
], x
, 91, 0);
1254 if (p
->drawst
& PL_DRAWLIVES
&& !_2pl
) {
1255 Z_gotoxy(st
- 35, 17);
1256 Z_printhf("%d", p
->lives
);
1263 static void pl_info (player_t
*p
, int x
, int y
) {
1264 dword t
= p
->kills
* 10920 / g_time
;
1265 Z_gotoxy(x
+ 25, y
); Z_printbf("KILLS");
1266 Z_gotoxy(x
+ 25, y
+ 15); Z_printbf("KPM");
1267 Z_gotoxy(x
+ 25, y
+ 30); Z_printbf("SECRETS %u / %u", p
->secrets
, sw_secrets
);
1268 Z_gotoxy(x
+ 255, y
); Z_printbf("%u", p
->kills
);
1269 Z_gotoxy(x
+ 255, y
+ 15); Z_printbf("%u.%u", t
/ 10, t
% 10);
1272 static void R_draw_intermission (void) {
1275 Z_gotoxy(cx
- 14*12/2, 20);
1276 Z_printbf("LEVEL COMPLETE");
1277 Z_calc_time(g_time
, &hr
, &mn
, &sc
);
1278 Z_gotoxy(cx
- 12*12/2, 40);
1279 Z_printbf("TIME %u:%02u:%02u", hr
, mn
, sc
);
1282 Z_gotoxy(cx
- 10*12/2, h
);
1283 Z_printbf("PLAYER ONE");
1286 pl_info(&pl1
, cx
- 160, h
);
1288 h
+= 30 + SCRH
/ 10;
1289 Z_gotoxy(cx
- 10*12/2, h
);
1290 Z_printbf("PLAYER TWO");
1292 pl_info(&pl2
, cx
- 160, h
);
1296 static void W_act (void) {
1298 if (g_time
% 3 == 0) {
1299 for (i
= 1; i
< max_textures
; i
++) {
1303 if (anip
[a
][anic
[a
]].res
== -1) {
1306 walp
[i
] = anip
[a
][anic
[a
]];
1312 void R_draw (void) {
1314 glClearColor(0, 0, 0, 1);
1315 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
1316 glEnable(GL_SCISSOR_TEST
);
1327 R_gl_draw_image_ext(&scrnh
[0], 0, 0, SCRW
, SCRH
);
1330 R_gl_draw_image_ext(&scrnh
[1], 0, 0, SCRW
, SCRH
);
1331 R_draw_intermission();
1334 R_gl_draw_image_ext(&scrnh
[2], 0, 0, SCRW
, SCRH
);
1338 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
/ 2);
1339 R_draw_player_view(&pl2
, 0, SCRH
/ 2, SCRW
, SCRH
/ 2);
1341 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
);
1343 R_gl_setclip(0, 0, SCRW
, SCRH
);
1347 SDL_GL_SwapBuffers();
1350 void R_alloc (void) {
1353 logo("R_alloc: load graphics\n");
1355 scrnh
[0] = R_gl_loadimage("TITLEPIC");
1357 scrnh
[1] = R_gl_loadimage("INTERPIC");
1358 scrnh
[2] = R_gl_loadimage("ENDPIC");
1359 for (i
= 0; i
< 2; i
++) {
1360 sprintf(s
, "LTN%c", '1' + i
);
1361 for (j
= 0; j
< 2; j
++) {
1362 ltn
[i
][j
] = Z_getspr(s
, j
, 0, NULL
);
1366 for (i
= 0; i
< SMSN
; i
++) {
1367 smk_spr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_smoke_spr
);
1369 for (i
= 0; i
< FLSN
; i
++) {
1370 smk_fspr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_flame_spr
);
1373 for (i
= 0; i
< 10; i
++) {
1374 fx_spr
[i
] = Z_getspr("TFOG", i
, 0, fx_sprd
+ i
);
1376 for (; i
< 15; i
++) {
1377 fx_spr
[i
] = Z_getspr("IFOG", i
- 10, 0, fx_sprd
+ i
);
1380 for (i
= 0; i
< 4; i
++) {
1381 wp_spr
[i
* 2] = Z_getspr("MISL", i
, 1, wp_sprd
+ i
* 2);
1382 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
, 2, wp_sprd
+ i
* 2 + 1);
1384 for (; i
< 6; i
++) {
1385 wp_spr
[i
* 2] = Z_getspr("PLSS", i
- 4, 1, wp_sprd
+ i
* 2);
1386 wp_spr
[i
* 2 + 1] = Z_getspr("PLSS", i
- 4, 2, wp_sprd
+ i
* 2 + 1);
1388 for (; i
< 11; i
++) {
1389 wp_spr
[i
* 2] = Z_getspr("PLSE", i
- 6, 1, wp_sprd
+ i
* 2);
1390 wp_spr
[i
* 2 + 1] = Z_getspr("PLSE", i
- 6, 2, wp_sprd
+ i
* 2 + 1);
1392 for (; i
< 13; i
++) {
1393 wp_spr
[i
* 2] = Z_getspr("APLS", i
- 11, 1, wp_sprd
+ i
* 2);
1394 wp_spr
[i
* 2 + 1] = Z_getspr("APLS", i
- 11, 2, wp_sprd
+ i
* 2 + 1);
1396 for (; i
< 18; i
++) {
1397 wp_spr
[i
* 2] = Z_getspr("APBX", i
- 13, 1, wp_sprd
+ i
* 2);
1398 wp_spr
[i
* 2 + 1] = Z_getspr("APBX", i
- 13, 2, wp_sprd
+ i
* 2 + 1);
1400 for(; i
< 20; i
++) {
1401 wp_spr
[i
* 2] = Z_getspr("BFS1", i
- 18, 1, wp_sprd
+ i
* 2);
1402 wp_spr
[i
* 2 + 1] = Z_getspr("BFS1", i
- 18, 2, wp_sprd
+ i
* 2 + 1);
1404 for (; i
< 26; i
++) {
1405 wp_spr
[i
* 2] = Z_getspr("BFE1", i
- 20, 1, wp_sprd
+ i
* 2);
1406 wp_spr
[i
* 2 + 1] = Z_getspr("BFE1", i
- 20, 2, wp_sprd
+ i
* 2 + 1);
1408 for (; i
< 30; i
++) {
1409 wp_spr
[i
* 2] = Z_getspr("BFE2", i
- 26, 1, wp_sprd
+ i
* 2);
1410 wp_spr
[i
* 2 + 1] = Z_getspr("BFE2", i
- 26, 2, wp_sprd
+ i
* 2 + 1);
1412 for (; i
< 32; i
++) {
1413 wp_spr
[i
* 2] = Z_getspr("MISL", i
- 30 + 4, 1, wp_sprd
+ i
* 2);
1414 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
- 30 + 4, 2, wp_sprd
+ i
* 2 + 1);
1416 for (; i
< 37; i
++) {
1417 wp_spr
[i
* 2] = Z_getspr("BAL1", i
- 32, 1, wp_sprd
+ i
* 2);
1418 wp_spr
[i
* 2 + 1] = Z_getspr("BAL1", i
- 32, 2, wp_sprd
+ i
* 2 + 1);
1420 for (; i
< 42; i
++) {
1421 wp_spr
[i
* 2] = Z_getspr("BAL7", i
- 37, 1, wp_sprd
+ i
* 2);
1422 wp_spr
[i
* 2 + 1] = Z_getspr("BAL7", i
- 37, 2, wp_sprd
+ i
* 2 + 1);
1424 for (; i
< 47; i
++) {
1425 wp_spr
[i
* 2] = Z_getspr("BAL2", i
- 42, 1, wp_sprd
+ i
* 2);
1426 wp_spr
[i
* 2 + 1] = Z_getspr("BAL2", i
- 42, 2, wp_sprd
+ i
* 2 + 1);
1428 for (; i
< 49; i
++) {
1429 wp_spr
[i
* 2] = Z_getspr("MANF", i
- 47, 1, wp_sprd
+ i
* 2);
1430 wp_spr
[i
* 2 + 1] = Z_getspr("MANF", i
- 47, 2, wp_sprd
+ i
* 2 + 1);
1433 static const char snm
[18][4] = {
1434 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1435 "STIM", "MEDI", "BPAK",
1436 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1438 static const char n4
[4][4] = {
1439 "SOUL", "SMRT", "SMGT", "SMBT"
1441 static const char n3
[2][4] = {
1444 for (i
= 0; i
< 18; i
++) {
1445 item_spr
[i
] = Z_getspr(snm
[i
], 0, 0, item_sprd
+ i
);
1447 for (; i
< 20; i
++) {
1448 item_spr
[i
] = Z_getspr("ARM1", i
- 18, 0, item_sprd
+ i
);
1449 item_spr
[i
+ 2] = Z_getspr("ARM2", i
- 18, 0, item_sprd
+ i
);
1452 for (; i
< 26; i
++) {
1453 item_spr
[i
] = Z_getspr("MEGA", i
- 22, 0, item_sprd
+ i
);
1455 for (; i
< 30; i
++) {
1456 item_spr
[i
] = Z_getspr("PINV", i
- 26, 0, item_sprd
+ i
);
1458 item_spr
[30] = Z_getspr("AQUA", 0, 0, item_sprd
+ 30);
1459 item_spr
[31] = Z_getspr("KEYR", 0, 0, item_sprd
+ 31);
1460 item_spr
[32] = Z_getspr("KEYG", 0, 0, item_sprd
+ 32);
1461 item_spr
[33] = Z_getspr("KEYB", 0, 0, item_sprd
+ 33);
1462 item_spr
[34] = Z_getspr("SUIT", 0, 0, item_sprd
+ 34);
1463 for (n
= 35, j
= 0; j
< 4; j
++) {
1464 for (i
= 0; i
< 4; i
++, n
++) {
1465 item_spr
[n
] = Z_getspr(n4
[j
], i
, 0, item_sprd
+ n
);
1468 for (j
= 0; j
< 2; j
++) {
1469 for (i
= 0; i
< 3; i
++, n
++) {
1470 item_spr
[n
] = Z_getspr(n3
[j
], i
, 0, item_sprd
+ n
);
1473 item_spr
[57] = Z_getspr("GUN2", 0, 0, item_sprd
+ 57);
1475 for (i
= 0; i
< 27; i
++) {
1476 plr_spr
[i
* 2] = Z_getspr("PLAY", i
, 1, plr_sprd
+ i
* 2);
1477 plr_msk
[i
* 2] = R_gl_get_special_spr("PLAY", i
, 1, &R_extract_mask_spr
);
1478 plr_spr
[i
* 2 + 1] = Z_getspr("PLAY", i
, 2, plr_sprd
+ i
* 2 + 1);
1479 plr_msk
[i
* 2 + 1] = R_gl_get_special_spr("PLAY", i
, 2, &R_extract_mask_spr
);
1481 strncpy(s
, "PWPx", 4);
1482 for (i
= 1; i
< 11; i
++) {
1483 s
[3] = (i
< 10 ? '0' : 'A' - 10) + i
;
1484 for (j
= 0; j
< 6; j
++) {
1485 plr_wpn
[i
][j
] = Z_getspr(s
, j
, 1, NULL
);
1489 static const char msn
[MN_TN
][4] = {
1490 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1491 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1493 static const int mms
[MN_TN
] = {
1494 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1495 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1497 mn_sgun
[0] = Z_getspr("PWP4", 0, 1, NULL
);
1498 mn_sgun
[1] = Z_getspr("PWP4", 1, 1, NULL
);
1499 for (j
= 0; j
< MN_TN
; j
++) {
1500 for (i
= 0; i
< mms
[j
]; i
++) {
1501 mn_spr
[j
][i
] = Z_getspr(msn
[j
], i
/ 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1502 if (j
== MN_MAN
- 1) {
1503 mn_man_msk
[i
] = R_gl_get_special_spr(msn
[j
], i
/ 2, (i
& 1) + 1, &R_extract_mask_spr
);
1506 if (j
== MN_BARREL
- 1) {
1507 for (i
= 4; i
< 14; i
++) {
1508 mn_spr
[j
][i
] = Z_getspr("BEXP", i
/ 2 - 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1512 for (i
= 0; i
< 8; i
++) {
1513 mn_fspr
[i
] = Z_getspr("FIRE", i
, 0, NULL
);
1515 pl_spr
[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL
);
1516 pl_msk
[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr
);
1517 pl_spr
[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL
);
1518 pl_msk
[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr
);
1520 static const char mnm
[22][8]={
1521 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1522 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1523 "STTMINUS", "STTPRCNT",
1524 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1525 "PLASA0", "BFUGA0", "GUN2A0"
1527 stone
= R_gl_loadimage("STONE");
1528 stone2
= R_gl_loadimage("STONE2");
1529 keys
[0] = R_gl_loadimage("KEYRA0");
1530 keys
[1] = R_gl_loadimage("KEYGA0");
1531 keys
[2] = R_gl_loadimage("KEYBA0");
1532 for (i
= 0; i
< 22; i
++) {
1533 sth
[i
] = R_gl_loadimage(mnm
[i
]);
1535 strcpy(s
, "STBF_*");
1536 for (i
= '!'; i
< 160; i
++) {
1538 bfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1540 for (i
= '!'; i
< 160; i
++) {
1541 sprintf(s
, "STCFN%03d", i
);
1542 sfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1544 strcpy(s
, "WINUM*");
1545 for (i
= '0'; i
<= '9'; i
++) {
1547 bfh
[i
- '!'] = R_gl_loadimage(s
);
1549 bfh
[':' - '!'] = R_gl_loadimage("WICOLON");
1551 msklh
[0] = R_gl_loadimage("M_SKULL1");
1552 msklh
[1] = R_gl_loadimage("M_SKULL2");
1553 mbarl
= R_gl_loadimage("M_THERML");
1554 mbarm
= R_gl_loadimage("M_THERMM");
1555 mbarr
= R_gl_loadimage("M_THERMR");
1556 mbaro
= R_gl_loadimage("M_THERMO");
1557 mslotl
= R_gl_loadimage("M_LSLEFT");
1558 mslotm
= R_gl_loadimage("M_LSCNTR");
1559 mslotr
= R_gl_loadimage("M_LSRGHT");
1561 for (i
= 1; i
< ANIT
; i
++) {
1562 for (j
= 0; anm
[i
- 1][j
]; j
++) {
1563 anip
[i
][j
] = R_gl_loadimage(anm
[i
- 1][j
]);
1566 anip
[i
][j
] = (image
) {
1576 void R_init (void) {
1577 Uint32 flags
= SDL_OPENGL
;
1579 flags
= flags
| SDL_FULLSCREEN
;
1581 if (SCRW
<= 0 || SCRH
<= 0) {
1582 ERR_failinit("Invalid screen size %ix%i\n", SCRW
, SCRH
);
1585 R_init_playpal(); // only onece
1587 surf
= SDL_SetVideoMode(SCRW
, SCRH
, 0, flags
);
1589 ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
1591 root
= R_cache_new();
1596 void R_done (void) {
1600 void R_setgamma (int g
) {
1601 gamma
= g
< 0 ? 0 : (g
> 4 ? 4 : g
);
1604 int R_getgamma (void) {
1608 void R_toggle_fullscreen (void) {
1609 fullscreen
= !fullscreen
;
1611 R_init(); // recreate window
1615 void R_get_name (int n
, char s
[8]) {
1616 assert(n
>= 0 && n
< 256);
1617 if (walp
[n
].res
== -1) {
1619 } else if (walp
[n
].res
== -2) {
1620 memcpy(s
, "_WATER_", 8);
1621 s
[7] = '0' + (intptr_t)walp
[n
].n
- 1;
1622 } else if (walani
[n
] > 0) {
1623 memcpy(s
, anm
[walani
[n
] - 1][0], 8);
1625 F_getresname(s
, walp
[n
].res
& 0x7FFF);
1629 static short getani (char n
[8]) {
1631 while (i
< ANIT
&& strncasecmp(n
, anm
[i
][0], 8) != 0) {
1634 return i
< ANIT
? i
+ 1 : 0;
1637 int R_get_special_id (int n
) {
1638 assert(n
>= 0 && n
<= 256);
1639 return walp
[n
].res
== -2 ? (intptr_t)walp
[n
].n
: -1;
1642 void R_begin_load (void) {
1644 for (i
= 0; i
< 256; i
++) {
1645 if (walp
[i
].n
!= NULL
&& walp
[i
].res
>= 0 && walani
[i
] == 0) {
1646 R_gl_free_image(&walp
[i
]);
1648 memset(&walp
[i
], 0, sizeof(image
));
1653 memset(anic
, 0, sizeof(anic
));
1655 max_wall_height
= 0;
1659 void R_load (char s
[8], int f
) {
1660 assert(max_textures
< 256);
1662 walp
[max_textures
] = (image
) {
1670 } else if (strncasecmp(s
, "_WATER_", 7) == 0) {
1671 walp
[max_textures
] = (image
) {
1672 .n
= (void*)(s
[7] - '0' + 1),
1680 walp
[max_textures
] = R_gl_loadimage(s
);
1682 walp
[max_textures
].res
|= 0x8000;
1684 if (s
[0] == 'S' && s
[1] == 'W' && s
[4] == '_') {
1685 walswp
[max_textures
] = 0;
1687 walani
[max_textures
] = getani(s
);
1689 max_wall_width
= max(max_wall_width
, walp
[max_textures
].w
);
1690 max_wall_height
= max(max_wall_height
, walp
[max_textures
].h
);
1694 void R_end_load (void) {
1698 for (i
= 1; i
< 256 && j
< 256; i
++) {
1699 if (walswp
[i
] == 0) {
1702 g
= F_getresid(s
) | (walp
[i
].res
& 0x8000);
1704 while (k
< 256 && walp
[k
].res
!= g
) {
1710 walp
[k
] = R_gl_getimage(g
);
1711 walf
[k
] = g
& 0x8000 ? 1 : 0;
1719 void R_loadsky (int sky
) {
1721 logo("R_loadsky(%i)\n", sky
);
1724 R_gl_free_image(&horiz
);
1725 horiz
= R_gl_loadimage(s
);