14 #include "sound.h" // snd_vol
15 #include "music.h" // mus_vol
23 #include "switch.h" // sw_secrets
28 # include <OpenGL/gl.h>
37 #define VGA_TRANSPARENT_COLOR 0
38 #define DEFAULT_SKY_COLOR 0x97
40 #define PLAYER_COLOR_OFFSET 7
46 typedef struct vgaimg
{
63 struct node
*left
, *right
;
69 typedef struct cache
{
75 typedef struct image
{
83 int SCRW
= 320; // public
84 int SCRH
= 200; // public
85 static rgb playpal
[256];
86 static byte bright
[256];
87 static GLuint lastTexture
;
91 static image scrnh
[3]; // TITLEPIC INTERPIC ENDPIC
92 static image ltn
[2][2];
95 static image smk_spr
[SMSN
];
96 static image smk_fspr
[FLSN
];
99 static image fx_spr
[15];
100 static char fx_sprd
[15];
103 static image wp_spr
[49*2];
104 static char wp_sprd
[49*2];
107 static image item_spr
[58];
108 static char item_sprd
[58];
111 static image plr_spr
[27*2];
112 static image plr_msk
[27*2];
113 static char plr_sprd
[27*2];
114 static image plr_wpn
[11][6];
117 static image pl_spr
[2];
118 static image pl_msk
[2];
119 static image mn_spr
[MN_TN
][29*2];
120 static image mn_man_msk
[29*2];
121 static char mn_sprd
[MN_TN
][29*2];
122 static image mn_fspr
[8];
123 static image mn_sgun
[2];
126 static image sth
[22];
127 static image bfh
[160 - '!'];
128 static image sfh
[160 - '!'];
131 static image keys
[3];
137 static image msklh
[2];
147 static const char *anm
[ANIT
- 1][5] = {
148 {"WALL22_1", "WALL23_1", "WALL23_2", NULL
, NULL
},
149 {"WALL58_1", "WALL58_2", "WALL58_3", NULL
, NULL
},
150 {"W73A_1", "W73A_2", NULL
, NULL
, NULL
},
151 {"RP2_1", "RP2_2", "RP2_3", "RP2_4", NULL
}
153 static int max_wall_width
;
154 static int max_wall_height
;
155 static int max_textures
;
156 static image walp
[256];
157 static byte walani
[256];
158 static image anip
[ANIT
][5];
159 static byte anic
[ANIT
];
164 // https://blackpawn.com/texts/lightmaps/
165 static node
*R_node_alloc (node
*p
, int w
, int h
) {
171 node
*n
= R_node_alloc(p
->left
, w
, h
);
172 return n
? n
: R_node_alloc(p
->right
, w
, h
);
174 int pw
= p
->r
- p
->l
+ 1;
175 int ph
= p
->b
- p
->t
+ 1;
176 if (p
->leaf
|| pw
< w
|| ph
< h
) {
178 } else if (pw
== w
&& ph
== h
) {
182 p
->left
= malloc(sizeof(node
));
183 p
->right
= malloc(sizeof(node
));
184 if (pw
- w
> ph
- h
) {
215 return R_node_alloc(p
->left
, w
, h
);
220 static int R_node_have_leaf (node
*n
) {
221 return n
&& (n
->leaf
|| R_node_have_leaf(n
->left
) || R_node_have_leaf(n
->right
));
224 static void R_node_free_recursive (node
*n
) {
226 R_node_free_recursive(n
->left
);
227 R_node_free_recursive(n
->right
);
232 static void R_node_free (node
*n
) {
234 //logo("free node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
236 assert(n
->left
== NULL
);
237 assert(n
->right
== NULL
);
242 assert(p
->leaf
== 0);
245 if (R_node_have_leaf(p
) == 0) {
246 R_node_free_recursive(p
->left
);
248 R_node_free_recursive(p
->right
);
258 static void R_cache_get_max_texture_size (int *w
, int *h
) {
260 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &size
);
261 size
= min(max(size
, 0), 512); // more can be buggy on older hardware
266 static void R_gl_bind_texture (GLuint id
) {
267 if (id
!= lastTexture
) {
268 glBindTexture(GL_TEXTURE_2D
, id
);
272 static cache
*R_cache_new (void) {
276 R_cache_get_max_texture_size(&w
, &h
);
278 glGenTextures(1, &id
);
280 R_gl_bind_texture(id
);
281 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
282 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
283 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, w
, h
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
284 c
= malloc(sizeof(cache
));
292 glDeleteTextures(1, &id
);
296 //logo("new cache %p\n", c);
300 static void R_cache_free (cache
*root
, int freetexture
) {
305 R_node_free_recursive(c
->root
.left
);
306 R_node_free_recursive(c
->root
.right
);
307 if (freetexture
&& c
->id
!= 0) {
308 glDeleteTextures(1, &c
->id
);
315 static node
*R_cache_alloc (cache
*root
, int w
, int h
) {
317 assert(w
> 0 && h
> 0);
322 R_cache_get_max_texture_size(&maxw
, &maxh
);
323 if (w
<= maxw
&& h
<= maxh
) {
325 n
= R_node_alloc(&c
->root
, w
, h
);
337 n
= R_node_alloc(&c
->root
, w
, h
);
346 //logo("new node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
348 logo("new node failed {%i:%i}\n", w
, h
);
353 static void R_cache_update (node
*n
, const void *data
, int x
, int y
, int w
, int h
) {
360 assert(n
->l
+ x
+ w
- 1 <= n
->r
);
361 assert(n
->t
+ y
+ h
- 1 <= n
->b
);
362 R_gl_bind_texture(n
->base
->id
);
363 glTexSubImage2D(GL_TEXTURE_2D
, 0, n
->l
+ x
, n
->t
+ y
, w
, h
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
366 /* Generic helpers */
368 static void R_init_playpal (void) {
370 byte
*vgapal
= M_lock(F_getresid("PLAYPAL"));
371 for (i
= 0; i
< 256; i
++) {
373 .r
= vgapal
[i
* 3 + 0] * 255 / 63,
374 .g
= vgapal
[i
* 3 + 1] * 255 / 63,
375 .b
= vgapal
[i
* 3 + 2] * 255 / 63,
377 bright
[i
] = ((int)vgapal
[i
* 3 + 0] + vgapal
[i
* 3 + 1] + vgapal
[i
* 3 + 2]) * 8 / (63 * 3);
382 static vgaimg
*R_getvga (int id
) {
383 int loaded
= M_was_locked(id
);
384 vgaimg
*v
= M_lock(id
);
385 if (v
!= NULL
&& !loaded
) {
386 v
->w
= short2host(v
->w
);
387 v
->h
= short2host(v
->h
);
388 v
->x
= short2host(v
->x
);
389 v
->y
= short2host(v
->y
);
394 static rgba
*R_extract_flame_spr (vgaimg
*v
) {
395 static const byte flametab
[16] = {
396 0xBC, 0xBA, 0xB8, 0xB6, 0xB4, 0xB2, 0xB0, 0xD5,
397 0xD6, 0xD7, 0xA1, 0xA0, 0xE3, 0xE2, 0xE1, 0xE0
400 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
402 for (j
= 0; j
< v
->h
; j
++) {
403 for (i
= 0; i
< v
->w
; i
++) {
404 int k
= j
* v
->w
+ i
;
405 byte c
= v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
];
407 .r
= playpal
[flametab
[c
]].r
,
408 .g
= playpal
[flametab
[c
]].g
,
409 .b
= playpal
[flametab
[c
]].b
,
410 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
418 static rgba
*R_extract_smoke_spr (vgaimg
*v
) {
420 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
422 for (j
= 0; j
< v
->h
; j
++) {
423 for (i
= 0; i
< v
->w
; i
++) {
424 int k
= j
* v
->w
+ i
;
425 byte c
= ((v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
]) + 0x60) ^ 0x0F;
426 byte a
= 0xFF - ((int)playpal
[c
].r
+ playpal
[c
].g
+ playpal
[c
].b
) / 3;
431 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : a
,
439 static rgba
*R_extract_mask_spr (vgaimg
*v
) {
441 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
443 for (j
= 0; j
< v
->h
; j
++) {
444 for (i
= 0; i
< v
->w
; i
++) {
445 int k
= j
* v
->w
+ i
;
447 if (c
>= 0x70 && c
<= 0x7F) {
448 byte mask
= c
- 0x70;
449 mask
= 0xFF - ((mask
<< 4) | mask
);
470 static rgba
*R_extract_rgba_spr (vgaimg
*v
) {
472 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
474 for (j
= 0; j
< v
->h
; j
++) {
475 for (i
= 0; i
< v
->w
; i
++) {
476 int k
= j
* v
->w
+ i
;
482 .a
= c
== VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
492 static image
R_gl_create_image (const rgba
*buf
, int w
, int h
) {
493 node
*n
= R_cache_alloc(root
, w
, h
);
495 R_cache_update(n
, buf
, 0, 0, w
, h
);
505 static image
R_gl_get_special_image (int id
, rgba
*(*fn
)(vgaimg
*)) {
508 //F_getresname(name, id);
509 //logo("load image: %.8s\n", name);
510 vgaimg
*v
= R_getvga(id
);
512 rgba
*buf
= (*fn
)(v
);
513 img
= R_gl_create_image(buf
, v
->w
, v
->h
);
527 static image
R_gl_getimage (int id
) {
528 return R_gl_get_special_image(id
, &R_extract_rgba_spr
);
531 static image
R_gl_loadimage (const char name
[8]) {
532 return R_gl_getimage(F_getresid(name
));
535 static image
R_gl_get_special_spr (const char n
[4], int s
, int d
, rgba
*(*fn
)(vgaimg
*)) {
536 return R_gl_get_special_image(F_getsprid(n
, s
, d
), fn
);
539 static void R_gl_free_image (image
*img
) {
540 if (img
->n
!= NULL
&& img
->res
>= 0) {
547 static void R_gl_draw_quad (int x
, int y
, int w
, int h
) {
549 glVertex2i(x
+ w
, y
);
551 glVertex2i(x
, y
+ h
);
552 glVertex2i(x
+ w
, y
+ h
);
556 static void R_gl_draw_textured (image
*img
, int x
, int y
, int w
, int h
, int flip
) {
558 GLfloat nw
= img
->n
->base
->root
.r
+ 1;
559 GLfloat nh
= img
->n
->base
->root
.b
+ 1;
560 GLfloat ax
= (flip
? img
->n
->l
: img
->n
->r
+ 1) / nw
;
561 GLfloat bx
= (flip
? img
->n
->r
+ 1 : img
->n
->l
) / nh
;
562 GLfloat ay
= (img
->n
->t
) / nw
;
563 GLfloat by
= (img
->n
->b
+ 1) / nh
;
564 R_gl_bind_texture(img
->n
->base
->id
);
565 glEnable(GL_TEXTURE_2D
);
567 glTexCoord2f(ax
, ay
); glVertex2i(x
+ w
, y
);
568 glTexCoord2f(bx
, ay
); glVertex2i(x
, y
);
569 glTexCoord2f(bx
, by
); glVertex2i(x
, y
+ h
);
570 glTexCoord2f(ax
, by
); glVertex2i(x
+ w
, y
+ h
);
573 glColor3ub(255, 0, 0);
575 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
576 glDisable(GL_TEXTURE_2D
);
577 R_gl_draw_quad(x
, y
, w
, h
);
581 /* fit image into rectangle without applying offset and transparency */
582 static void R_gl_draw_image_ext (image
*img
, int x
, int y
, int w
, int h
) {
584 glColor3ub(255, 255, 255);
585 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
586 R_gl_draw_textured(img
, x
, y
, w
, h
, 0);
589 /* draw sprite with offset and coloring */
590 static void R_gl_draw_image_color (image
*img
, int x
, int y
, int flip
) {
591 int xx
= flip
? x
- img
->w
+ img
->x
: x
- img
->x
;
593 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
594 R_gl_draw_textured(img
, xx
, y
- img
->y
, img
->w
, img
->h
, flip
);
597 /* draw sprite with offset */
598 static void R_gl_draw_image (image
*img
, int x
, int y
, int flip
) {
599 glColor3ub(255, 255, 255);
600 R_gl_draw_image_color(img
, x
, y
, flip
);
603 static void R_gl_set_color (byte c
) {
604 glColor3ub(playpal
[c
].r
, playpal
[c
].g
, playpal
[c
].b
);
607 static void R_gl_setclip (int x
, int y
, int w
, int h
) {
608 glScissor(x
, SCRH
- h
- y
, w
, h
);
611 static void R_gl_setmatrix (void) {
612 glScissor(0, 0, SCRW
, SCRH
);
613 glViewport(0, 0, SCRW
, SCRH
);
614 glMatrixMode(GL_PROJECTION
);
616 glOrtho(0, SCRW
, SCRH
, 0, 0, 1);
617 glMatrixMode(GL_MODELVIEW
);
623 static image
Z_getspr (const char n
[4], int s
, int d
, char *dir
) {
624 int h
= F_getsprid(n
, s
, d
);
626 *dir
= (h
& 0x8000) ? 1 : 0;
628 return R_gl_getimage(h
);
631 static image
*Z_get_char_image (image
*img
, int ch
) {
633 ch
= cp866_toupper(ch
);
634 if (ch
> 32 && ch
< 160) {
640 static int Z_get_char_width_generic (image
*img
, int off
, int ch
) {
641 image
*p
= Z_get_char_image(img
, ch
);
642 return p
== NULL
? off
: p
->w
- 1;
645 static int Z_putch_generic (image
*img
, int off
, int ch
) {
646 image
*p
= Z_get_char_image(img
, ch
);
647 int w
= p
== NULL
? off
: p
->w
- 1;
648 if (p
!= NULL
&& p
->n
!= NULL
) {
649 R_gl_draw_image(p
, prx
, pry
, 0);
655 static int Z_get_string_width_generic (image
*img
, int off
, const char *fmt
, va_list ap
) {
658 vsprintf(buf
, fmt
, ap
);
659 for (i
= w
= ww
= 0; buf
[i
]; ++i
) {
667 w
+= Z_get_char_width_generic(img
, off
, (byte
)buf
[i
]);
673 static int Z_printf_generic (image
*img
, int off
, const char *fmt
, va_list ap
) {
676 vsprintf(buf
, fmt
, ap
);
677 for (i
= w
= ww
= 0; buf
[i
]; ++i
) {
687 w
+= Z_putch_generic(img
, off
, (byte
)buf
[i
]);
693 static void Z_gotoxy (int x
, int y
) {
698 static int Z_get_big_string_width (const char *fmt
, ...) {
701 int w
= Z_get_string_width_generic(bfh
, 12, fmt
, a
);
706 static int Z_printbf (const char *fmt
, ...) {
709 int w
= Z_printf_generic(bfh
, 12, fmt
, a
);
714 static int Z_get_small_string_width (const char *fmt
, ...) {
717 int w
= Z_get_string_width_generic(sfh
, 7, fmt
, a
);
722 static int Z_printsf (const char *fmt
, ...) {
725 int w
=Z_printf_generic(sfh
, 7, fmt
, a
);
730 static void Z_printhf (const char *fmt
, ...) {
735 vsprintf(buf
, fmt
, a
);
737 for (i
= 0; buf
[i
]; ++i
) {
768 R_gl_draw_image(&sth
[c
], prx
, pry
, 0);
776 static image
*PL_getspr (int s
, int d
, int msk
) {
777 int i
= (s
- 'A') * 2 + d
;
778 return msk
? &plr_msk
[i
] : &plr_spr
[i
];
781 #define SCROLLER_MIDDLE 10
782 #define TEXTFIELD_MIDDLE 2
784 static void get_entry_size (const menu_t
*m
, int i
, int *w
, int *h
) {
793 msg
.type
= GM_GETENTRY
;
794 assert(GM_send(m
, i
, &msg
));
795 type
= msg
.integer
.i
;
800 case GM_TEXTFIELD_BUTTON
:
801 msg
.type
= GM_GETCAPTION
;
802 if (GM_send(m
, i
, &msg
)) {
803 x
= Z_get_big_string_width("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
806 case GM_SMALL_BUTTON
:
807 msg
.type
= GM_GETCAPTION
;
808 if (GM_send(m
, i
, &msg
)) {
809 x
= Z_get_small_string_width("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
817 msg
.type
= GM_GETSTR
;
818 if (GM_send(m
, i
, &msg
)) {
819 x
+= Z_get_big_string_width("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
823 case GM_SMALL_BUTTON
:
824 msg
.type
= GM_GETSTR
;
825 if (GM_send(m
, i
, &msg
)) {
826 x
+= Z_get_big_string_width("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
831 x
+= (SCROLLER_MIDDLE
+ 2) * 8;
835 case GM_TEXTFIELD_BUTTON
:
836 msg
.type
= GM_GETSTR
;
837 if (GM_send(m
, i
, &msg
)) {
838 x
+= (msg
.string
.maxlen
+ 2) * 8;
840 x
+= (TEXTFIELD_MIDDLE
+ 2) * 8;
851 static void get_menu_size (const menu_t
*m
, int *w
, int *h
) {
855 int i
, n
, x
, y
, xx
, yy
, type
;
858 if (GM_send_this(m
, &msg
)) {
860 type
= msg
.integer
.s
;
863 msg
.type
= GM_GETTITLE
;
864 if (GM_send_this(m
, &msg
)) {
866 case GM_BIG
: x
= Z_get_big_string_width("%.*s", msg
.string
.maxlen
, msg
.string
.s
); break;
867 case GM_SMALL
: x
= Z_get_small_string_width("%.*s", msg
.string
.maxlen
, msg
.string
.s
); break;
871 for (i
= 0; i
< n
; i
++) {
872 get_entry_size(m
, i
, &xx
, &yy
);
884 static int GM_draw (void) {
885 int i
, j
, n
, x
, y
, xoff
, yoff
, cur
, w
, type
, recv
;
886 const menu_t
*m
= GM_get();
889 get_menu_size(m
, &x
, &y
);
890 x
= SCRW
/ 2 - x
/ 2;
891 y
= SCRH
/ 2 - y
/ 2;
894 if (GM_send_this(m
, &msg
)) {
897 type
= msg
.integer
.s
;
898 msg
.type
= GM_GETTITLE
;
899 if (GM_send_this(m
, &msg
)) {
902 case GM_SMALL
: yoff
= 8; Z_printsf("%.*s", msg
.string
.maxlen
, msg
.string
.s
); break;
903 case GM_BIG
: yoff
= 20; Z_printbf("%.*s", msg
.string
.maxlen
, msg
.string
.s
); break;
909 for (i
= 0; i
< n
; i
++) {
910 msg
.type
= GM_GETENTRY
;
911 if (GM_send(m
, i
, &msg
)) {
912 type
= msg
.integer
.i
;
914 if (type
== GM_SMALL_BUTTON
) {
915 Z_gotoxy(x
- 8, y
+ yoff
);
918 R_gl_draw_image(&msklh
[(gm_tm
/ 6) & 1], x
- 25, y
+ yoff
- 8, 0);
921 msg
.type
= GM_GETCAPTION
;
922 if (GM_send(m
, i
, &msg
)) {
923 Z_gotoxy(x
, y
+ yoff
);
924 if (type
== GM_SMALL_BUTTON
) {
925 xoff
= Z_printsf("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
927 xoff
= Z_printbf("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
934 case GM_SMALL_BUTTON
:
935 msg
.type
= GM_GETSTR
;
936 if (GM_send(m
, i
, &msg
)) {
937 Z_gotoxy(x
+ xoff
, y
+ yoff
);
938 if (type
== GM_SMALL_BUTTON
) {
939 Z_printsf("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
941 Z_printbf("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
944 yoff
+= type
== GM_BUTTON
? 16 : 12;
947 case GM_TEXTFIELD_BUTTON
:
949 msg
.type
= GM_GETSTR
;
950 recv
= GM_send(m
, i
, &msg
);
951 w
= recv
? msg
.string
.maxlen
: TEXTFIELD_MIDDLE
;
952 R_gl_draw_image(&mslotl
, x
+ xoff
, y
+ yoff
, 0);
953 for (j
= 1; j
<= w
; j
++) {
954 R_gl_draw_image(&mslotm
, x
+ xoff
+ j
* 8, y
+ yoff
, 0);
956 R_gl_draw_image(&mslotr
, x
+ xoff
+ j
* 8, y
+ yoff
, 0);
957 Z_gotoxy(x
+ xoff
+ 4, y
+ yoff
- 7);
958 if (input
&& i
== cur
) {
959 Z_printsf("%.*s_", imax
, ibuf
);
961 Z_printsf("%.*s", msg
.string
.maxlen
, msg
.string
.s
);
966 R_gl_draw_image(&mbarl
, x
+ xoff
, y
+ yoff
, 0);
967 for (j
= 1; j
< SCROLLER_MIDDLE
; j
++) {
968 R_gl_draw_image(&mbarm
, x
+ xoff
+ j
* 8, y
+ yoff
, 0);
970 R_gl_draw_image(&mbarr
, x
+ xoff
+ j
* 8, y
+ yoff
, 0);
971 msg
.type
= GM_GETINT
;
972 if (GM_send(m
, i
, &msg
)) {
973 int lev
= (msg
.integer
.i
- msg
.integer
.a
) * ((SCROLLER_MIDDLE
- 2) * 8) / msg
.integer
.b
;
974 R_gl_draw_image(&mbaro
, x
+ xoff
+ lev
+ 8, y
+ yoff
, 0);
990 static void R_draw_fld (byte
*fld
, int minx
, int miny
, int maxx
, int maxy
, int fg
) {
992 assert(minx
>= 0 && minx
<= FLDW
);
993 assert(miny
>= 0 && miny
<= FLDH
);
994 assert(maxx
>= 0 && maxx
<= FLDW
);
995 assert(maxy
>= 0 && maxy
<= FLDH
);
996 for (j
= miny
; j
< maxy
; j
++) {
997 for (i
= minx
; i
< maxx
; i
++) {
998 byte id
= fld
[j
* FLDW
+ i
];
1000 if (walp
[id
].res
< 0) {
1002 switch (R_get_special_id(id
)) {
1004 glColor4ub(0, 0, 255, 127);
1007 glColor4ub(0, 127, 0, 127);
1010 glColor4ub(127, 0, 0, 127);
1013 glColor4ub(0, 0, 0, 127);
1017 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
1018 glDisable(GL_TEXTURE_2D
);
1019 R_gl_draw_quad(i
* CELW
, j
* CELW
, CELW
, CELH
);
1022 R_gl_draw_image(&walp
[id
], i
* CELW
, j
* CELH
, 0);
1029 static void R_draw_dots (void) {
1031 glDisable(GL_BLEND
);
1032 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1033 glDisable(GL_TEXTURE_2D
);
1035 for (i
= 0; i
< MAXDOT
; i
++) {
1036 if (dot
[i
].t
!= 0) {
1037 R_gl_set_color(dot
[i
].c
);
1038 glVertex2i(dot
[i
].o
.x
, dot
[i
].o
.y
+ 1);
1044 static void R_draw_items (void) {
1046 for (i
= 0; i
< MAXITEM
; ++i
) {
1048 if (it
[i
].t
&& it
[i
].s
>= 0) {
1049 switch (it
[i
].t
& 0x7FFF) {
1051 s
= it
[i
].s
/ 9 + 18;
1054 s
= it
[i
].s
/ 9 + 20;
1057 s
= it
[i
].s
/ 2 + 22;
1060 s
= it
[i
].s
/ 2 + 26;
1066 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_SUPER
) * 4 + 35;
1068 case I_GOR1
: case I_FCAN
:
1069 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_GOR1
) * 3 + 51;
1080 s
= (it
[i
].t
& 0x7FFF) - I_KEYR
+ 31;
1086 s
= (it
[i
].t
& 0x7FFF) - 1;
1090 R_gl_draw_image(&item_spr
[s
], it
[i
].o
.x
, it
[i
].o
.y
, item_sprd
[s
]);
1095 static int standspr (player_t
*p
) {
1096 if (p
->f
& PLF_UP
) {
1098 } else if (p
->f
& PLF_DOWN
) {
1105 static int wpnspr (player_t
*p
) {
1106 if (p
->f
& PLF_UP
) {
1108 } else if(p
->f
& PLF_DOWN
) {
1115 static void R_draw_player (player_t
*p
) {
1116 enum {STAND
, GO
, DIE
, SLOP
, DEAD
, MESS
, OUT
, FALL
}; // copypasted from player.c!
1117 static const int wytab
[] = {-1, -2, -1, 0};
1124 if (p
->f
& PLF_FIRE
) {
1125 s
= standspr(p
) + 1;
1127 } else if (p
->pain
) {
1150 s
= plr_goanim
[p
->s
/ 8];
1151 w
= (p
->f
& PLF_FIRE
) ? 'B' : 'A';
1153 wy
= 1 + wytab
[s
- 'A'];
1157 s
= plr_dieanim
[p
->s
];
1160 s
= plr_slopanim
[p
->s
];
1170 R_gl_draw_image(&plr_wpn
[(int)p
->wpn
][w
-'A'], p
->o
.x
+ wx
, p
->o
.y
+ wy
, p
->d
);
1173 R_gl_draw_image(&plr_spr
[(s
- 'A') * 2 + p
->d
], p
->o
.x
, p
->o
.y
, plr_sprd
[(s
- 'A') * 2 + p
->d
]);
1174 R_gl_set_color(p
->color
+ PLAYER_COLOR_OFFSET
);
1175 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
]);
1179 static void R_draw_monsters (void) {
1180 enum {SLEEP
, GO
, RUN
, CLIMB
, DIE
, DEAD
, ATTACK
, SHOOT
, PAIN
, WAIT
, REVIVE
, RUNOUT
}; // copypasted from monster.c!
1182 for (i
= 0; i
< MAXMN
; i
++) {
1183 if (mn
[i
].t
!= MN_NONE
) {
1186 if (mn
[i
].t
< MN__LAST
) {
1187 if ((mn
[i
].t
!= MN_SOUL
&& mn
[i
].t
!= MN_PAIN
) || mn
[i
].st
!= DEAD
) {
1188 int ap
= mn
[i
].ap
[mn
[i
].ac
];
1189 int d
= (ap
- 'A') * 2 + mn
[i
].d
;
1190 int dir
= mn_sprd
[mn
[i
].t
- 1][d
];
1191 if (mn
[i
].t
== MN_MAN
&& (ap
== 'E' || ap
== 'F')) {
1192 R_gl_draw_image(&mn_sgun
[ap
- 'E'], x
, y
, mn
[i
].d
);
1194 R_gl_draw_image(&mn_spr
[mn
[i
].t
- 1][d
], x
, y
, dir
);
1195 if (mn
[i
].t
== MN_MAN
) {
1196 R_gl_set_color(MANCOLOR
+ PLAYER_COLOR_OFFSET
);
1197 R_gl_draw_image_color(&mn_man_msk
[d
], x
, y
, dir
);
1200 if (mn
[i
].t
== MN_VILE
&& mn
[i
].st
== SHOOT
) {
1201 R_gl_draw_image(&mn_fspr
[mn
[i
].ac
/ 3], mn
[i
].tx
, mn
[i
].ty
, 0);
1203 } else if (mn
[i
].t
== MN_PL_DEAD
|| mn
[i
].t
== MN_PL_MESS
) {
1204 int type
= mn
[i
].t
- MN_PL_DEAD
;
1205 R_gl_draw_image(&pl_spr
[type
], x
, y
, 0);
1206 R_gl_set_color(mn
[i
].d
);
1207 R_gl_draw_image_color(&pl_msk
[type
], x
, y
, 0);
1213 static void R_draw_weapons (void) {
1214 enum {NONE
, ROCKET
, PLASMA
, APLASMA
, BALL1
, BALL2
, BALL7
, BFGBALL
, BFGHIT
, MANF
, REVF
, FIRE
}; // copypasted from weapons.c!
1216 for (i
= 0; i
< MAXWPN
; ++i
) {
1224 d
= wp
[i
].o
.xv
> 0 ? 1 : 0;
1225 x
= abs(wp
[i
].o
.xv
);
1238 s
= (d
- 2) / 2 + 1;
1272 d
= wp
[i
].o
.xv
>= 0 ? 1 : 0;
1276 d
= wp
[i
].o
.xv
>=0 ? 1 : 0;
1288 s
= wp
[i
].s
/ 2 + 26;
1292 R_gl_draw_image(&wp_spr
[s
* 2 + d
], wp
[i
].o
.x
, wp
[i
].o
.y
, wp_sprd
[s
* 2 + d
]);
1297 static void R_draw_smoke (void) {
1299 for (i
= 0; i
< MAXSMOK
; ++i
) {
1304 if (s
>= (SMSN
- 1) * 3) {
1307 s
= SMSN
- 1 - s
/ 3;
1309 R_gl_draw_image(&smk_spr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1313 if (s
>= FLSN
- 1) {
1318 R_gl_draw_image(&smk_fspr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1325 static void R_draw_effects (void) {
1326 enum {NONE
, TFOG
, IFOG
, BUBL
}; // copypasted from fx.c
1328 for (i
= 0; i
< MAXFX
; ++i
) {
1332 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1335 s
= fx
[i
].s
/ 2 + 10;
1336 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1339 glDisable(GL_BLEND
);
1340 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1341 glDisable(GL_TEXTURE_2D
);
1343 R_gl_set_color(0xC0 + fx
[i
].s
);
1344 glVertex2i(fx
[i
].x
>> 8, (fx
[i
].y
>> 8) + 1);
1351 static int get_pu_st (int t
) {
1352 if (t
>= PL_FLASH
) {
1354 } else if((t
/ 9) & 1) {
1361 static void R_draw_view (int x
, int y
, int w
, int h
, int camx
, int camy
) {
1363 R_gl_setclip(x
, y
, w
, h
);
1364 glTranslatef(x
, y
, 0);
1365 if (w_horiz
&& horiz
.n
!= NULL
) {
1366 R_gl_draw_image_ext(&horiz
, 0, 0, w
, h
);
1367 if (sky_type
== 2 && lt_time
< 0) {
1368 image
*tanderbolt
= <n
[lt_type
][lt_time
< -5 ? 0 : 1];
1370 R_gl_draw_image(tanderbolt
, 0, lt_ypos
, 0);
1372 R_gl_draw_image(tanderbolt
, w
- 1, lt_ypos
, 1);
1376 glDisable(GL_BLEND
);
1377 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1378 glDisable(GL_TEXTURE_2D
);
1379 R_gl_set_color(DEFAULT_SKY_COLOR
);
1380 R_gl_draw_quad(0, 0, w
, h
);
1382 int maxx
= min((camx
+ w
) / CELW
+ 1, FLDW
);
1383 int maxy
= min((camy
+ h
) / CELH
+ 1, FLDH
);
1384 int minx
= max((camx
- max_wall_width
) / CELW
, 0);
1385 int miny
= max((camy
- max_wall_height
) / CELH
, 0);
1386 glTranslatef(-camx
, -camy
, 0);
1387 R_draw_fld((byte
*)fldb
, minx
, miny
, maxx
, maxy
, 0);
1390 R_draw_player(&pl1
);
1392 R_draw_player(&pl2
);
1398 R_draw_fld((byte
*)fldf
, minx
, miny
, maxx
, maxy
, 1);
1399 glTranslatef(camx
, camy
, 0);
1400 if (sky_type
== 2 && (lt_time
== -4 || lt_time
== -2)) {
1401 glColor4ub(255, 255, 255, 255);
1403 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
1404 glDisable(GL_TEXTURE_2D
);
1405 R_gl_draw_quad(0, 0, w
, h
);
1410 static void R_draw_player_view (player_t
*p
, int x
, int y
, int w
, int h
) {
1411 p
->looky
= min(max(p
->looky
, -SCRH
/ 4), SCRH
/ 4); // TODO remove writeback
1414 int cx
= min(max(p
->o
.x
, cw
/ 2), FLDW
* CELW
- cw
/ 2);
1415 int cy
= min(max(p
->o
.y
- 12 + p
->looky
, h
/ 2), FLDH
* CELH
- h
/ 2);
1416 int camx
= max(cx
- cw
/ 2, 0);
1417 int camy
= max(cy
- h
/ 2, 0);
1419 R_draw_view(x
, y
+ 1, cw
, h
- 2, camx
, camy
);
1420 glTranslatef(x
, y
, 0);
1422 if (get_pu_st(p
->invl
)) {
1424 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
);
1425 glDisable(GL_TEXTURE_2D
);
1426 glColor4ub(191, 191, 191, 255);
1427 R_gl_draw_quad(0, 0, cw
, h
);
1430 if (p
->suit
&& get_pu_st(p
->suit
)) {
1432 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1433 glDisable(GL_TEXTURE_2D
);
1434 glColor4ub(0, 255, 0, 192);
1435 R_gl_draw_quad(0, 0, cw
, h
);
1437 int f
= min(max(p
->pain
* 3, 0), 255);
1440 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1441 glDisable(GL_TEXTURE_2D
);
1442 glColor4ub(255, 0, 0, f
);
1443 R_gl_draw_quad(0, 0, cw
, h
);
1446 R_gl_setclip(x
, y
, w
, h
);
1447 glTranslatef(-x
+ cw
, 0, 0);
1448 R_gl_draw_image(&stone
, 0, 0, 0);
1451 R_gl_draw_image(&stone2
, 0, i
, 0);
1454 if (p
->drawst
& PL_DRAWAIR
) {
1455 if (p
->air
< PL_AIR
) {
1456 int a
= min(max(p
->air
, 0), MAXAIR
) * 100 / MAXAIR
;
1457 glDisable(GL_BLEND
);
1458 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1459 glDisable(GL_TEXTURE_2D
);
1460 R_gl_set_color(0xC8);
1461 R_gl_draw_quad(10, 49, a
, 2);
1464 if (p
->drawst
& PL_DRAWLIFE
) {
1466 Z_printhf("%3d%%", p
->life
);
1468 if (p
->drawst
& PL_DRAWARMOR
) {
1469 Z_gotoxy(10, 7 + 19);
1470 Z_printhf("%3d%%", p
->armor
);
1472 if (p
->drawst
& PL_DRAWWPN
) {
1499 R_gl_draw_image(&sth
[12 + p
->wpn
], st
- 88, 58 + 19, 0);
1503 Z_gotoxy(st
- 10 - 5 * 14, 58 + 2);
1504 Z_printhf("%5d", i
);
1507 if (p
->drawst
& PL_DRAWFRAG
&& g_dm
) {
1508 Z_gotoxy(st
- 5 - 5 * 14, 77 + 5);
1509 Z_printhf("%5d", p
->frag
);
1511 if (p
->drawst
& PL_DRAWKEYS
) {
1513 for (k
= p
->keys
>> 4, n
= 0, x
= st
- 75; n
< 3; n
++, k
>>= 1, x
+= 9) {
1515 R_gl_draw_image(&keys
[n
], x
, 91, 0);
1519 if (p
->drawst
& PL_DRAWLIVES
&& !_2pl
) {
1520 Z_gotoxy(st
- 35, 17);
1521 Z_printhf("%d", p
->lives
);
1528 static void pl_info (player_t
*p
, int x
, int y
) {
1529 dword t
= p
->kills
* 10920 / g_time
;
1530 Z_gotoxy(x
+ 25, y
); Z_printbf("KILLS");
1531 Z_gotoxy(x
+ 25, y
+ 15); Z_printbf("KPM");
1532 Z_gotoxy(x
+ 25, y
+ 30); Z_printbf("SECRETS %u / %u", p
->secrets
, sw_secrets
);
1533 Z_gotoxy(x
+ 255, y
); Z_printbf("%u", p
->kills
);
1534 Z_gotoxy(x
+ 255, y
+ 15); Z_printbf("%u.%u", t
/ 10, t
% 10);
1537 static void R_draw_intermission (void) {
1540 Z_gotoxy(cx
- 14*12/2, 20);
1541 Z_printbf("LEVEL COMPLETE");
1542 Z_calc_time(g_time
, &hr
, &mn
, &sc
);
1543 Z_gotoxy(cx
- 12*12/2, 40);
1544 Z_printbf("TIME %u:%02u:%02u", hr
, mn
, sc
);
1547 Z_gotoxy(cx
- 10*12/2, h
);
1548 Z_printbf("PLAYER ONE");
1551 pl_info(&pl1
, cx
- 160, h
);
1553 h
+= 30 + SCRH
/ 10;
1554 Z_gotoxy(cx
- 10*12/2, h
);
1555 Z_printbf("PLAYER TWO");
1557 pl_info(&pl2
, cx
- 160, h
);
1561 static void W_act (void) {
1563 if (g_time
% 3 == 0) {
1564 for (i
= 1; i
< max_textures
; i
++) {
1568 if (anip
[a
][anic
[a
]].res
== -1) {
1571 walp
[i
] = anip
[a
][anic
[a
]];
1577 void R_draw (void) {
1579 glClearColor(0, 0, 0, 1);
1580 glClear(GL_COLOR_BUFFER_BIT
);
1581 glEnable(GL_SCISSOR_TEST
);
1592 R_gl_draw_image_ext(&scrnh
[0], 0, 0, SCRW
, SCRH
);
1595 R_gl_draw_image_ext(&scrnh
[1], 0, 0, SCRW
, SCRH
);
1596 R_draw_intermission();
1599 R_gl_draw_image_ext(&scrnh
[2], 0, 0, SCRW
, SCRH
);
1603 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
/ 2);
1604 R_draw_player_view(&pl2
, 0, SCRH
/ 2, SCRW
, SCRH
/ 2);
1606 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
);
1608 R_gl_setclip(0, 0, SCRW
, SCRH
);
1615 static void R_alloc (void) {
1618 logo("R_alloc: load graphics\n");
1620 scrnh
[0] = R_gl_loadimage("TITLEPIC");
1621 scrnh
[1] = R_gl_loadimage("INTERPIC");
1622 scrnh
[2] = R_gl_loadimage("ENDPIC");
1623 for (i
= 0; i
< 2; i
++) {
1624 sprintf(s
, "LTN%c", '1' + i
);
1625 for (j
= 0; j
< 2; j
++) {
1626 ltn
[i
][j
] = Z_getspr(s
, j
, 0, NULL
);
1630 for (i
= 0; i
< SMSN
; i
++) {
1631 smk_spr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_smoke_spr
);
1633 for (i
= 0; i
< FLSN
; i
++) {
1634 smk_fspr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_flame_spr
);
1637 for (i
= 0; i
< 10; i
++) {
1638 fx_spr
[i
] = Z_getspr("TFOG", i
, 0, fx_sprd
+ i
);
1640 for (; i
< 15; i
++) {
1641 fx_spr
[i
] = Z_getspr("IFOG", i
- 10, 0, fx_sprd
+ i
);
1644 for (i
= 0; i
< 4; i
++) {
1645 wp_spr
[i
* 2] = Z_getspr("MISL", i
, 1, wp_sprd
+ i
* 2);
1646 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
, 2, wp_sprd
+ i
* 2 + 1);
1648 for (; i
< 6; i
++) {
1649 wp_spr
[i
* 2] = Z_getspr("PLSS", i
- 4, 1, wp_sprd
+ i
* 2);
1650 wp_spr
[i
* 2 + 1] = Z_getspr("PLSS", i
- 4, 2, wp_sprd
+ i
* 2 + 1);
1652 for (; i
< 11; i
++) {
1653 wp_spr
[i
* 2] = Z_getspr("PLSE", i
- 6, 1, wp_sprd
+ i
* 2);
1654 wp_spr
[i
* 2 + 1] = Z_getspr("PLSE", i
- 6, 2, wp_sprd
+ i
* 2 + 1);
1656 for (; i
< 13; i
++) {
1657 wp_spr
[i
* 2] = Z_getspr("APLS", i
- 11, 1, wp_sprd
+ i
* 2);
1658 wp_spr
[i
* 2 + 1] = Z_getspr("APLS", i
- 11, 2, wp_sprd
+ i
* 2 + 1);
1660 for (; i
< 18; i
++) {
1661 wp_spr
[i
* 2] = Z_getspr("APBX", i
- 13, 1, wp_sprd
+ i
* 2);
1662 wp_spr
[i
* 2 + 1] = Z_getspr("APBX", i
- 13, 2, wp_sprd
+ i
* 2 + 1);
1664 for(; i
< 20; i
++) {
1665 wp_spr
[i
* 2] = Z_getspr("BFS1", i
- 18, 1, wp_sprd
+ i
* 2);
1666 wp_spr
[i
* 2 + 1] = Z_getspr("BFS1", i
- 18, 2, wp_sprd
+ i
* 2 + 1);
1668 for (; i
< 26; i
++) {
1669 wp_spr
[i
* 2] = Z_getspr("BFE1", i
- 20, 1, wp_sprd
+ i
* 2);
1670 wp_spr
[i
* 2 + 1] = Z_getspr("BFE1", i
- 20, 2, wp_sprd
+ i
* 2 + 1);
1672 for (; i
< 30; i
++) {
1673 wp_spr
[i
* 2] = Z_getspr("BFE2", i
- 26, 1, wp_sprd
+ i
* 2);
1674 wp_spr
[i
* 2 + 1] = Z_getspr("BFE2", i
- 26, 2, wp_sprd
+ i
* 2 + 1);
1676 for (; i
< 32; i
++) {
1677 wp_spr
[i
* 2] = Z_getspr("MISL", i
- 30 + 4, 1, wp_sprd
+ i
* 2);
1678 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
- 30 + 4, 2, wp_sprd
+ i
* 2 + 1);
1680 for (; i
< 37; i
++) {
1681 wp_spr
[i
* 2] = Z_getspr("BAL1", i
- 32, 1, wp_sprd
+ i
* 2);
1682 wp_spr
[i
* 2 + 1] = Z_getspr("BAL1", i
- 32, 2, wp_sprd
+ i
* 2 + 1);
1684 for (; i
< 42; i
++) {
1685 wp_spr
[i
* 2] = Z_getspr("BAL7", i
- 37, 1, wp_sprd
+ i
* 2);
1686 wp_spr
[i
* 2 + 1] = Z_getspr("BAL7", i
- 37, 2, wp_sprd
+ i
* 2 + 1);
1688 for (; i
< 47; i
++) {
1689 wp_spr
[i
* 2] = Z_getspr("BAL2", i
- 42, 1, wp_sprd
+ i
* 2);
1690 wp_spr
[i
* 2 + 1] = Z_getspr("BAL2", i
- 42, 2, wp_sprd
+ i
* 2 + 1);
1692 for (; i
< 49; i
++) {
1693 wp_spr
[i
* 2] = Z_getspr("MANF", i
- 47, 1, wp_sprd
+ i
* 2);
1694 wp_spr
[i
* 2 + 1] = Z_getspr("MANF", i
- 47, 2, wp_sprd
+ i
* 2 + 1);
1697 static const char snm
[18][4] = {
1698 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1699 "STIM", "MEDI", "BPAK",
1700 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1702 static const char n4
[4][4] = {
1703 "SOUL", "SMRT", "SMGT", "SMBT"
1705 static const char n3
[2][4] = {
1708 for (i
= 0; i
< 18; i
++) {
1709 item_spr
[i
] = Z_getspr(snm
[i
], 0, 0, item_sprd
+ i
);
1711 for (; i
< 20; i
++) {
1712 item_spr
[i
] = Z_getspr("ARM1", i
- 18, 0, item_sprd
+ i
);
1713 item_spr
[i
+ 2] = Z_getspr("ARM2", i
- 18, 0, item_sprd
+ i
);
1716 for (; i
< 26; i
++) {
1717 item_spr
[i
] = Z_getspr("MEGA", i
- 22, 0, item_sprd
+ i
);
1719 for (; i
< 30; i
++) {
1720 item_spr
[i
] = Z_getspr("PINV", i
- 26, 0, item_sprd
+ i
);
1722 item_spr
[30] = Z_getspr("AQUA", 0, 0, item_sprd
+ 30);
1723 item_spr
[31] = Z_getspr("KEYR", 0, 0, item_sprd
+ 31);
1724 item_spr
[32] = Z_getspr("KEYG", 0, 0, item_sprd
+ 32);
1725 item_spr
[33] = Z_getspr("KEYB", 0, 0, item_sprd
+ 33);
1726 item_spr
[34] = Z_getspr("SUIT", 0, 0, item_sprd
+ 34);
1727 for (n
= 35, j
= 0; j
< 4; j
++) {
1728 for (i
= 0; i
< 4; i
++, n
++) {
1729 item_spr
[n
] = Z_getspr(n4
[j
], i
, 0, item_sprd
+ n
);
1732 for (j
= 0; j
< 2; j
++) {
1733 for (i
= 0; i
< 3; i
++, n
++) {
1734 item_spr
[n
] = Z_getspr(n3
[j
], i
, 0, item_sprd
+ n
);
1737 item_spr
[57] = Z_getspr("GUN2", 0, 0, item_sprd
+ 57);
1739 for (i
= 0; i
< 27; i
++) {
1740 plr_spr
[i
* 2] = Z_getspr("PLAY", i
, 1, plr_sprd
+ i
* 2);
1741 plr_msk
[i
* 2] = R_gl_get_special_spr("PLAY", i
, 1, &R_extract_mask_spr
);
1742 plr_spr
[i
* 2 + 1] = Z_getspr("PLAY", i
, 2, plr_sprd
+ i
* 2 + 1);
1743 plr_msk
[i
* 2 + 1] = R_gl_get_special_spr("PLAY", i
, 2, &R_extract_mask_spr
);
1745 strncpy(s
, "PWPx", 4);
1746 for (i
= 1; i
< 11; i
++) {
1747 s
[3] = (i
< 10 ? '0' : 'A' - 10) + i
;
1748 for (j
= 0; j
< 6; j
++) {
1749 plr_wpn
[i
][j
] = Z_getspr(s
, j
, 1, NULL
);
1753 static const char msn
[MN_TN
][4] = {
1754 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1755 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1757 static const int mms
[MN_TN
] = {
1758 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1759 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1761 mn_sgun
[0] = Z_getspr("PWP4", 0, 1, NULL
);
1762 mn_sgun
[1] = Z_getspr("PWP4", 1, 1, NULL
);
1763 for (j
= 0; j
< MN_TN
; j
++) {
1764 for (i
= 0; i
< mms
[j
]; i
++) {
1765 mn_spr
[j
][i
] = Z_getspr(msn
[j
], i
/ 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1766 if (j
== MN_MAN
- 1) {
1767 mn_man_msk
[i
] = R_gl_get_special_spr(msn
[j
], i
/ 2, (i
& 1) + 1, &R_extract_mask_spr
);
1770 if (j
== MN_BARREL
- 1) {
1771 for (i
= 4; i
< 14; i
++) {
1772 mn_spr
[j
][i
] = Z_getspr("BEXP", i
/ 2 - 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1776 for (i
= 0; i
< 8; i
++) {
1777 mn_fspr
[i
] = Z_getspr("FIRE", i
, 0, NULL
);
1779 pl_spr
[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL
);
1780 pl_msk
[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr
);
1781 pl_spr
[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL
);
1782 pl_msk
[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr
);
1784 static const char mnm
[22][8]={
1785 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1786 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1787 "STTMINUS", "STTPRCNT",
1788 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1789 "PLASA0", "BFUGA0", "GUN2A0"
1791 stone
= R_gl_loadimage("STONE");
1792 stone2
= R_gl_loadimage("STONE2");
1793 keys
[0] = R_gl_loadimage("KEYRA0");
1794 keys
[1] = R_gl_loadimage("KEYGA0");
1795 keys
[2] = R_gl_loadimage("KEYBA0");
1796 for (i
= 0; i
< 22; i
++) {
1797 sth
[i
] = R_gl_loadimage(mnm
[i
]);
1799 strcpy(s
, "STBF_*");
1800 for (i
= '!'; i
< 160; i
++) {
1802 bfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1804 for (i
= '!'; i
< 160; i
++) {
1805 sprintf(s
, "STCFN%03d", i
);
1806 sfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1808 strcpy(s
, "WINUM*");
1809 for (i
= '0'; i
<= '9'; i
++) {
1811 bfh
[i
- '!'] = R_gl_loadimage(s
);
1813 bfh
[':' - '!'] = R_gl_loadimage("WICOLON");
1815 msklh
[0] = R_gl_loadimage("M_SKULL1");
1816 msklh
[1] = R_gl_loadimage("M_SKULL2");
1817 mbarl
= R_gl_loadimage("M_THERML");
1818 mbarm
= R_gl_loadimage("M_THERMM");
1819 mbarr
= R_gl_loadimage("M_THERMR");
1820 mbaro
= R_gl_loadimage("M_THERMO");
1821 mslotl
= R_gl_loadimage("M_LSLEFT");
1822 mslotm
= R_gl_loadimage("M_LSCNTR");
1823 mslotr
= R_gl_loadimage("M_LSRGHT");
1825 for (i
= 1; i
< ANIT
; i
++) {
1826 for (j
= 0; j
< 5 && anm
[i
- 1][j
]; j
++) {
1827 anip
[i
][j
] = R_gl_loadimage(anm
[i
- 1][j
]);
1830 anip
[i
][j
] = (image
) {
1840 static void R_reload_textures (void);
1842 void R_set_videomode (int w
, int h
, int fullscreen
) {
1845 int was
= Y_videomode_setted();
1847 R_cache_free(root
, 0);
1850 int res
= Y_set_videomode_opengl(w
, h
, fullscreen
);
1853 ERR_failinit("Unable to set video mode\n");
1856 Y_get_videomode(&SCRW
, &SCRH
);
1857 root
= R_cache_new();
1860 R_reload_textures();
1863 static int video_menu_handler (menu_msg_t
*msg
, const menu_t
*m
, void *data
, int i
) {
1865 static int w
, h
, fullscreen
;
1866 static char buf
[16];
1869 const videomode_t
*v
;
1870 enum { VIDEOMODE
, FULLSCREEN
, APPLY
, __NUM__
};
1871 static const simple_menu_t sm
= {
1872 GM_BIG
, "Video", NULL
,
1875 { "Fullscreen: ", NULL
},
1879 if (msg
->type
== GM_ENTER
) {
1880 Y_get_videomode(&w
, &h
);
1881 fullscreen
= Y_get_fullscreen();
1882 v
= Y_get_videomode_list_opengl(fullscreen
);
1884 while (vmode
< v
->n
&& v
->modes
[vmode
].w
!= w
&& v
->modes
[vmode
].h
!= h
) {
1888 w
= v
->modes
[vmode
].w
;
1889 h
= v
->modes
[vmode
].h
;
1891 snprintf(buf
, 16, "%ix%i", w
, h
);
1892 buflen
= strlen(buf
);
1895 if (i
== VIDEOMODE
) {
1896 switch (msg
->type
) {
1897 case GM_GETSTR
: return GM_init_str(msg
, buf
, buflen
);
1899 v
= Y_get_videomode_list_opengl(fullscreen
);
1900 vmode
= vmode
+ 1 >= v
->n
? 0 : vmode
+ 1;
1902 w
= v
->modes
[vmode
].w
;
1903 h
= v
->modes
[vmode
].h
;
1905 Y_get_videomode(&w
, &h
);
1907 snprintf(buf
, 16, "%ix%i", w
, h
);
1908 buflen
= strlen(buf
);
1911 } else if (i
== FULLSCREEN
) {
1912 switch (msg
->type
) {
1913 case GM_GETSTR
: return GM_init_str(msg
, fullscreen
? "Yes" : "No ", 3);
1914 case GM_SELECT
: fullscreen
= !fullscreen
; return 1;
1916 } else if (i
== APPLY
) {
1917 switch (msg
->type
) {
1918 case GM_SELECT
: R_set_videomode(w
, h
, fullscreen
); return 1;
1921 return simple_menu_handler(msg
, i
, __NUM__
, &sm
, &cur
);
1924 static const menu_t video_menu
= {
1925 NULL
, &video_menu_handler
1928 const menu_t
*R_menu (void) {
1932 void R_init (void) {
1933 logo("R_init: intialize opengl render\n");
1935 R_set_videomode(SCRW
, SCRH
, 0);
1938 void R_done (void) {
1939 R_cache_free(root
, 1);
1940 Y_unset_videomode();
1944 void R_get_name (int n
, char s
[8]) {
1945 assert(n
>= 0 && n
< 256);
1946 if (walp
[n
].res
== -1) {
1948 } else if (walp
[n
].res
== -2) {
1949 memcpy(s
, "_WATER_", 8);
1950 s
[7] = '0' + (intptr_t)walp
[n
].n
- 1;
1951 } else if (walani
[n
] > 0) {
1952 memcpy(s
, anm
[walani
[n
] - 1][0], 8);
1954 F_getresname(s
, walp
[n
].res
& 0x7FFF);
1958 static short getani (char n
[8]) {
1960 while (i
< ANIT
- 1 && strncasecmp(n
, anm
[i
][0], 8) != 0) {
1963 return i
< ANIT
- 1 ? i
+ 1 : 0;
1966 int R_get_special_id (int n
) {
1967 assert(n
>= 0 && n
<= 256);
1968 return walp
[n
].res
== -2 ? (intptr_t)walp
[n
].n
: -1;
1971 static void R_reload_textures (void) {
1974 for (i
= 0; i
< max_textures
; i
++) {
1976 if (walp
[i
].res
>= 0) {
1977 walp
[i
] = R_gl_getimage(walp
[i
].res
);
1981 horiz
= R_gl_getimage(horiz
.res
);
1985 void R_begin_load (void) {
1987 for (i
= 0; i
< 256; i
++) {
1988 if (walp
[i
].n
!= NULL
&& walp
[i
].res
>= 0 && walani
[i
] == 0) {
1989 R_gl_free_image(&walp
[i
]);
1991 memset(&walp
[i
], 0, sizeof(image
));
1996 memset(anic
, 0, sizeof(anic
));
1998 max_wall_height
= 0;
2002 void R_load (char s
[8], int f
) {
2003 assert(max_textures
< 256);
2005 walp
[max_textures
] = (image
) {
2013 } else if (strncasecmp(s
, "_WATER_", 7) == 0) {
2014 walp
[max_textures
] = (image
) {
2015 .n
= (void*)((intptr_t)s
[7] - '0' + 1),
2023 walp
[max_textures
] = R_gl_loadimage(s
);
2025 walp
[max_textures
].res
|= 0x8000;
2027 if (s
[0] == 'S' && s
[1] == 'W' && s
[4] == '_') {
2028 walswp
[max_textures
] = 0;
2030 walani
[max_textures
] = getani(s
);
2032 max_wall_width
= max(max_wall_width
, walp
[max_textures
].w
);
2033 max_wall_height
= max(max_wall_height
, walp
[max_textures
].h
);
2037 void R_end_load (void) {
2041 for (i
= 1; i
< 256 && j
< 256; i
++) {
2042 if (walswp
[i
] == 0) {
2045 g
= F_getresid(s
) | (walp
[i
].res
& 0x8000);
2047 while (k
< 256 && walp
[k
].res
!= g
) {
2054 walp
[k
] = R_gl_getimage(g
);
2055 walf
[k
] = g
& 0x8000 ? 1 : 0;
2063 void R_loadsky (int sky
) {
2067 R_gl_free_image(&horiz
);
2068 horiz
= R_gl_loadimage(s
);