41670016fa3872969e352ea937bf684c5ba987cb
14 #include "sound.h" // snd_vol
15 #include "music.h" // mus_vol
23 #include "switch.h" // sw_secrets
26 # include <OpenGL/gl.h>
35 #define VGA_TRANSPARENT_COLOR 0
36 #define DEFAULT_SKY_COLOR 0x97
38 #define PLAYER_COLOR_OFFSET 7
44 typedef struct vgaimg
{
61 struct node
*left
, *right
;
67 typedef struct cache
{
73 typedef struct image
{
81 int SCRW
= 320; // public
82 int SCRH
= 200; // public
84 static int fullscreen
;
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\n");
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
*)) {
507 vgaimg
*v
= R_getvga(id
);
509 rgba
*buf
= (*fn
)(v
);
510 img
= R_gl_create_image(buf
, v
->w
, v
->h
);
524 static image
R_gl_getimage (int id
) {
525 return R_gl_get_special_image(id
, &R_extract_rgba_spr
);
528 static image
R_gl_loadimage (const char name
[8]) {
529 return R_gl_getimage(F_getresid(name
));
532 static image
R_gl_get_special_spr (const char n
[4], int s
, int d
, rgba
*(*fn
)(vgaimg
*)) {
533 return R_gl_get_special_image(F_getsprid(n
, s
, d
), fn
);
536 static void R_gl_free_image (image
*img
) {
537 if (img
->n
!= NULL
&& img
->res
>= 0) {
544 static void R_gl_draw_quad (int x
, int y
, int w
, int h
) {
546 glVertex2i(x
+ w
, y
);
548 glVertex2i(x
, y
+ h
);
549 glVertex2i(x
+ w
, y
+ h
);
553 static void R_gl_draw_textured (image
*img
, int x
, int y
, int w
, int h
, int flip
) {
555 GLfloat nw
= img
->n
->base
->root
.r
+ 1;
556 GLfloat nh
= img
->n
->base
->root
.b
+ 1;
557 GLfloat ax
= (flip
? img
->n
->l
: img
->n
->r
+ 1) / nw
;
558 GLfloat bx
= (flip
? img
->n
->r
+ 1 : img
->n
->l
) / nh
;
559 GLfloat ay
= (img
->n
->t
) / nw
;
560 GLfloat by
= (img
->n
->b
+ 1) / nh
;
561 R_gl_bind_texture(img
->n
->base
->id
);
562 glEnable(GL_TEXTURE_2D
);
564 glTexCoord2f(ax
, ay
); glVertex2i(x
+ w
, y
);
565 glTexCoord2f(bx
, ay
); glVertex2i(x
, y
);
566 glTexCoord2f(bx
, by
); glVertex2i(x
, y
+ h
);
567 glTexCoord2f(ax
, by
); glVertex2i(x
+ w
, y
+ h
);
570 glColor3ub(255, 0, 0);
572 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
573 glDisable(GL_TEXTURE_2D
);
574 R_gl_draw_quad(x
, y
, w
, h
);
578 /* fit image into rectangle without applying offset and transparency */
579 static void R_gl_draw_image_ext (image
*img
, int x
, int y
, int w
, int h
) {
581 glColor3ub(255, 255, 255);
582 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
583 R_gl_draw_textured(img
, x
, y
, w
, h
, 0);
586 /* draw sprite with offset and coloring */
587 static void R_gl_draw_image_color (image
*img
, int x
, int y
, int flip
) {
588 int xx
= flip
? x
- img
->w
+ img
->x
: x
- img
->x
;
590 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
591 R_gl_draw_textured(img
, xx
, y
- img
->y
, img
->w
, img
->h
, flip
);
594 /* draw sprite with offset */
595 static void R_gl_draw_image (image
*img
, int x
, int y
, int flip
) {
596 glColor3ub(255, 255, 255);
597 R_gl_draw_image_color(img
, x
, y
, flip
);
600 static void R_gl_set_color (byte c
) {
601 glColor3ub(playpal
[c
].r
, playpal
[c
].g
, playpal
[c
].b
);
604 static void R_gl_setclip (int x
, int y
, int w
, int h
) {
605 glScissor(x
, SCRH
- h
- y
, w
, h
);
608 static void R_gl_setmatrix (void) {
609 glScissor(0, 0, SCRW
, SCRH
);
610 glViewport(0, 0, SCRW
, SCRH
);
611 glMatrixMode(GL_PROJECTION
);
613 glOrtho(0, SCRW
, SCRH
, 0, 0, 1);
614 glMatrixMode(GL_MODELVIEW
);
620 static image
Z_getspr (const char n
[4], int s
, int d
, char *dir
) {
621 int h
= F_getsprid(n
, s
, d
);
623 *dir
= (h
& 0x8000) ? 1 : 0;
625 return R_gl_getimage(h
);
628 static void Z_putch_generic (image img
[], int off
, int ch
) {
630 if (ch
> 32 && ch
< 160) {
634 R_gl_draw_image(p
, prx
, pry
, 0);
641 static void Z_printf_generic (image img
[], int off
, const char *fmt
, va_list ap
) {
644 vsprintf(buf
, fmt
, ap
);
645 for (i
= 0; buf
[i
]; ++i
) {
653 Z_putch_generic(img
, off
, (byte
)buf
[i
]);
658 static void Z_gotoxy (int x
, int y
) {
663 static void Z_printbf (const char *fmt
, ...) {
666 Z_printf_generic(bfh
, 12, fmt
, a
);
670 static void Z_printsf (const char *fmt
, ...) {
673 Z_printf_generic(sfh
, 7, fmt
, a
);
677 static void Z_printhf (const char *fmt
, ...) {
682 vsprintf(buf
, fmt
, a
);
684 for (i
= 0; buf
[i
]; ++i
) {
715 R_gl_draw_image(&sth
[c
], prx
, pry
, 0);
723 static image
*PL_getspr (int s
, int d
, int msk
) {
724 int i
= (s
- 'A') * 2 + d
;
725 return msk
? &plr_msk
[i
] : &plr_spr
[i
];
728 static void GM_draw (void) {
729 enum {MENU
, MSG
}; // copypasted from menu.c!
731 CANCEL
, NEWGAME
, LOADGAME
, SAVEGAME
, OPTIONS
, QUITGAME
, QUIT
, ENDGAME
, ENDGM
,
732 PLR1
, PLR2
, COOP
, DM
, VOLUME
, GAMMA
, LOAD
, SAVE
, PLCOLOR
, PLCEND
, MUSIC
, INTERP
,
733 SVOLM
, SVOLP
, MVOLM
, MVOLP
, GAMMAM
, GAMMAP
, PL1CM
, PL1CP
, PL2CM
, PL2CP
734 }; // copypasted from menu.c!
735 int i
, j
, k
, x
, y
, cx
, cy
;
741 if (mnu
->type
== MENU
) {
742 y
= cy
- (mnu
->n
* 16 - 20) / 2;
743 Z_gotoxy(cx
- mnu
->x
, y
- 10); Z_printbf("%s", mnu
->ttl
);
744 for (i
= 0; i
< mnu
->n
; i
++) {
745 if (mnu
->t
[i
] == LOAD
|| mnu
->t
[i
] == SAVE
) {
747 R_gl_draw_image(&mslotl
, cx
- mnu
->x
, j
, 0);
748 for (k
= 8; k
< 184; k
+= 8) {
749 R_gl_draw_image(&mslotm
, cx
- mnu
->x
+ k
, j
, 0);
751 R_gl_draw_image(&mslotr
, cx
- mnu
->x
+ 184, j
, 0);
752 Z_gotoxy(cx
- mnu
->x
+ 4, j
- 8);
753 if (input
&& i
== save_mnu
.cur
) {
754 Z_printsf("%s_", ibuf
);
756 Z_printsf("%s", savname
[i
]);
759 x
= mnu
->t
[i
] >= SVOLM
? (mnu
->t
[i
] >= PL1CM
? 50 : 152) : 0;
760 Z_gotoxy(cx
- mnu
->x
+ x
, y
+ i
* 16 + 20);
761 Z_printbf("%s", mnu
->m
[i
]);
764 Z_printbf(" '%s'", g_music
);
767 Z_printbf("%s", fullscreen
? "ON" : "OFF");
773 img
= PL_getspr(*panimp
, 0, 0);
774 R_gl_draw_image(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
775 img
= PL_getspr(*panimp
, 0, 1);
776 R_gl_set_color(pcolortab
[(mnu
->t
[i
] == PL1CM
) ? p1color
: p2color
] + PLAYER_COLOR_OFFSET
);
777 R_gl_draw_image_color(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
786 R_gl_draw_image(&mbarl
, cx
- mnu
->x
, j
, 0);
787 for (k
= 8; k
< 144; k
+= 8) {
788 R_gl_draw_image(&mbarm
, cx
- mnu
->x
+ k
, j
, 0);
790 R_gl_draw_image(&mbarr
, cx
- mnu
->x
+ 144, j
, 0);
805 R_gl_draw_image(&mbaro
, cx
- mnu
->x
+ 8 + k
, j
, 0);
810 R_gl_draw_image(&msklh
[(gm_tm
/ 6) & 1], cx
- mnu
->x
- 25, y
+ mnu
->cur
* 16 + 20 - 8, 0);
811 } else if (mnu
->type
== MSG
) {
812 Z_gotoxy(cx
- strlen(mnu
->ttl
) * 7 / 2, cy
- 10); Z_printsf(mnu
->ttl
);
813 Z_gotoxy(cx
- 24, SCRH
/ 2); Z_printsf("(Y/N)");
815 ERR_fatal("Unknown menu type %i\n", mnu
->type
);
822 static void R_draw_fld (byte
*fld
, int minx
, int miny
, int maxx
, int maxy
, int fg
) {
824 assert(minx
>= 0 && minx
<= FLDW
);
825 assert(miny
>= 0 && miny
<= FLDH
);
826 assert(maxx
>= 0 && maxx
<= FLDW
);
827 assert(maxy
>= 0 && maxy
<= FLDH
);
828 for (j
= miny
; j
< maxy
; j
++) {
829 for (i
= minx
; i
< maxx
; i
++) {
830 byte id
= fld
[j
* FLDW
+ i
];
832 if (walp
[id
].res
< 0) {
834 switch (R_get_special_id(id
)) {
836 glColor4ub(0, 0, 255, 127);
839 glColor4ub(0, 127, 0, 127);
842 glColor4ub(127, 0, 0, 127);
845 glColor4ub(0, 0, 0, 127);
849 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
850 glDisable(GL_TEXTURE_2D
);
851 R_gl_draw_quad(i
* CELW
, j
* CELW
, CELW
, CELH
);
854 R_gl_draw_image(&walp
[id
], i
* CELW
, j
* CELH
, 0);
861 static void R_draw_dots (void) {
864 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
865 glDisable(GL_TEXTURE_2D
);
867 for (i
= 0; i
< MAXDOT
; i
++) {
869 R_gl_set_color(dot
[i
].c
);
870 glVertex2i(dot
[i
].o
.x
, dot
[i
].o
.y
+ 1);
876 static void R_draw_items (void) {
878 for (i
= 0; i
< MAXITEM
; ++i
) {
880 if (it
[i
].t
&& it
[i
].s
>= 0) {
881 switch (it
[i
].t
& 0x7FFF) {
883 s
= it
[i
].s
/ 9 + 18;
886 s
= it
[i
].s
/ 9 + 20;
889 s
= it
[i
].s
/ 2 + 22;
892 s
= it
[i
].s
/ 2 + 26;
898 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_SUPER
) * 4 + 35;
900 case I_GOR1
: case I_FCAN
:
901 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_GOR1
) * 3 + 51;
912 s
= (it
[i
].t
& 0x7FFF) - I_KEYR
+ 31;
918 s
= (it
[i
].t
& 0x7FFF) - 1;
922 R_gl_draw_image(&item_spr
[s
], it
[i
].o
.x
, it
[i
].o
.y
, item_sprd
[s
]);
927 static int standspr (player_t
*p
) {
930 } else if (p
->f
& PLF_DOWN
) {
937 static int wpnspr (player_t
*p
) {
940 } else if(p
->f
& PLF_DOWN
) {
947 static void R_draw_player (player_t
*p
) {
948 enum {STAND
, GO
, DIE
, SLOP
, DEAD
, MESS
, OUT
, FALL
}; // copypasted from player.c!
949 static const int wytab
[] = {-1, -2, -1, 0};
956 if (p
->f
& PLF_FIRE
) {
959 } else if (p
->pain
) {
982 s
= plr_goanim
[p
->s
/ 8];
983 w
= (p
->f
& PLF_FIRE
) ? 'B' : 'A';
985 wy
= 1 + wytab
[s
- 'A'];
989 s
= plr_dieanim
[p
->s
];
992 s
= plr_slopanim
[p
->s
];
1002 R_gl_draw_image(&plr_wpn
[(int)p
->wpn
][w
-'A'], p
->o
.x
+ wx
, p
->o
.y
+ wy
, p
->d
);
1005 R_gl_draw_image(&plr_spr
[(s
- 'A') * 2 + p
->d
], p
->o
.x
, p
->o
.y
, plr_sprd
[(s
- 'A') * 2 + p
->d
]);
1006 R_gl_set_color(p
->color
+ PLAYER_COLOR_OFFSET
);
1007 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
]);
1011 static void R_draw_monsters (void) {
1012 enum {SLEEP
, GO
, RUN
, CLIMB
, DIE
, DEAD
, ATTACK
, SHOOT
, PAIN
, WAIT
, REVIVE
, RUNOUT
}; // copypasted from monster.c!
1014 for (i
= 0; i
< MAXMN
; i
++) {
1015 if (mn
[i
].t
!= MN_NONE
) {
1018 if (mn
[i
].t
< MN__LAST
) {
1019 if ((mn
[i
].t
!= MN_SOUL
&& mn
[i
].t
!= MN_PAIN
) || mn
[i
].st
!= DEAD
) {
1020 int ap
= mn
[i
].ap
[mn
[i
].ac
];
1021 int d
= (ap
- 'A') * 2 + mn
[i
].d
;
1022 int dir
= mn_sprd
[mn
[i
].t
- 1][d
];
1023 if (mn
[i
].t
== MN_MAN
&& (ap
== 'E' || ap
== 'F')) {
1024 R_gl_draw_image(&mn_sgun
[ap
- 'E'], x
, y
, mn
[i
].d
);
1026 R_gl_draw_image(&mn_spr
[mn
[i
].t
- 1][d
], x
, y
, dir
);
1027 if (mn
[i
].t
== MN_MAN
) {
1028 R_gl_set_color(MANCOLOR
+ PLAYER_COLOR_OFFSET
);
1029 R_gl_draw_image_color(&mn_man_msk
[d
], x
, y
, dir
);
1032 if (mn
[i
].t
== MN_VILE
&& mn
[i
].st
== SHOOT
) {
1033 R_gl_draw_image(&mn_fspr
[mn
[i
].ac
/ 3], mn
[i
].tx
, mn
[i
].ty
, 0);
1035 } else if (mn
[i
].t
== MN_PL_DEAD
|| mn
[i
].t
== MN_PL_MESS
) {
1036 int type
= mn
[i
].t
- MN_PL_DEAD
;
1037 R_gl_draw_image(&pl_spr
[type
], x
, y
, 0);
1038 R_gl_set_color(mn
[i
].d
);
1039 R_gl_draw_image_color(&pl_msk
[type
], x
, y
, 0);
1045 static void R_draw_weapons (void) {
1046 enum {NONE
, ROCKET
, PLASMA
, APLASMA
, BALL1
, BALL2
, BALL7
, BFGBALL
, BFGHIT
, MANF
, REVF
, FIRE
}; // copypasted from weapons.c!
1048 for (i
= 0; i
< MAXWPN
; ++i
) {
1056 d
= wp
[i
].o
.xv
> 0 ? 1 : 0;
1057 x
= abs(wp
[i
].o
.xv
);
1070 s
= (d
- 2) / 2 + 1;
1104 d
= wp
[i
].o
.xv
>= 0 ? 1 : 0;
1108 d
= wp
[i
].o
.xv
>=0 ? 1 : 0;
1120 s
= wp
[i
].s
/ 2 + 26;
1124 R_gl_draw_image(&wp_spr
[s
* 2 + d
], wp
[i
].o
.x
, wp
[i
].o
.y
, wp_sprd
[s
* 2 + d
]);
1129 static void R_draw_smoke (void) {
1131 for (i
= 0; i
< MAXSMOK
; ++i
) {
1136 if (s
>= (SMSN
- 1) * 3) {
1139 s
= SMSN
- 1 - s
/ 3;
1141 R_gl_draw_image(&smk_spr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1145 if (s
>= FLSN
- 1) {
1150 R_gl_draw_image(&smk_fspr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1157 static void R_draw_effects (void) {
1158 enum {NONE
, TFOG
, IFOG
, BUBL
}; // copypasted from fx.c
1160 for (i
= 0; i
< MAXFX
; ++i
) {
1164 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1167 s
= fx
[i
].s
/ 2 + 10;
1168 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1171 glDisable(GL_BLEND
);
1172 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1173 glDisable(GL_TEXTURE_2D
);
1175 R_gl_set_color(0xC0 + fx
[i
].s
);
1176 glVertex2i(fx
[i
].x
>> 8, (fx
[i
].y
>> 8) + 1);
1183 static int get_pu_st (int t
) {
1184 if (t
>= PL_FLASH
) {
1186 } else if((t
/ 9) & 1) {
1193 static void R_draw_view (int x
, int y
, int w
, int h
, int camx
, int camy
) {
1195 R_gl_setclip(x
, y
, w
, h
);
1196 glTranslatef(x
, y
, 0);
1197 if (w_horiz
&& horiz
.n
!= NULL
) {
1198 R_gl_draw_image_ext(&horiz
, 0, 0, w
, h
);
1199 if (sky_type
== 2 && lt_time
< 0) {
1200 image
*tanderbolt
= <n
[lt_type
][lt_time
< -5 ? 0 : 1];
1202 R_gl_draw_image(tanderbolt
, 0, lt_ypos
, 0);
1204 R_gl_draw_image(tanderbolt
, w
- 1, lt_ypos
, 1);
1208 glDisable(GL_BLEND
);
1209 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1210 glDisable(GL_TEXTURE_2D
);
1211 R_gl_set_color(DEFAULT_SKY_COLOR
);
1212 R_gl_draw_quad(0, 0, w
, h
);
1214 int maxx
= min((camx
+ w
) / CELW
+ 1, FLDW
);
1215 int maxy
= min((camy
+ h
) / CELH
+ 1, FLDH
);
1216 int minx
= max((camx
- max_wall_width
) / CELW
, 0);
1217 int miny
= max((camy
- max_wall_height
) / CELH
, 0);
1218 glTranslatef(-camx
, -camy
, 0);
1219 R_draw_fld((byte
*)fldb
, minx
, miny
, maxx
, maxy
, 0);
1222 R_draw_player(&pl1
);
1224 R_draw_player(&pl2
);
1230 R_draw_fld((byte
*)fldf
, minx
, miny
, maxx
, maxy
, 1);
1231 glTranslatef(camx
, camy
, 0);
1232 if (sky_type
== 2 && (lt_time
== -4 || lt_time
== -2)) {
1233 glColor4ub(255, 255, 255, 255);
1235 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
1236 glDisable(GL_TEXTURE_2D
);
1237 R_gl_draw_quad(0, 0, w
, h
);
1242 static void R_draw_player_view (player_t
*p
, int x
, int y
, int w
, int h
) {
1243 p
->looky
= min(max(p
->looky
, -SCRH
/ 4), SCRH
/ 4); // TODO remove writeback
1246 int cx
= min(max(p
->o
.x
, cw
/ 2), FLDW
* CELW
- cw
/ 2);
1247 int cy
= min(max(p
->o
.y
- 12 + p
->looky
, h
/ 2), FLDH
* CELH
- h
/ 2);
1248 int camx
= max(cx
- cw
/ 2, 0);
1249 int camy
= max(cy
- h
/ 2, 0);
1251 R_draw_view(x
, y
+ 1, cw
, h
- 2, camx
, camy
);
1252 glTranslatef(x
, y
, 0);
1254 if (get_pu_st(p
->invl
)) {
1256 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
);
1257 glDisable(GL_TEXTURE_2D
);
1258 glColor4ub(191, 191, 191, 255);
1259 R_gl_draw_quad(0, 0, cw
, h
);
1262 if (p
->suit
&& get_pu_st(p
->suit
)) {
1264 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1265 glDisable(GL_TEXTURE_2D
);
1266 glColor4ub(0, 255, 0, 192);
1267 R_gl_draw_quad(0, 0, cw
, h
);
1269 int f
= min(max(p
->pain
* 3, 0), 255);
1272 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1273 glDisable(GL_TEXTURE_2D
);
1274 glColor4ub(255, 0, 0, f
);
1275 R_gl_draw_quad(0, 0, cw
, h
);
1278 R_gl_setclip(x
, y
, w
, h
);
1279 glTranslatef(-x
+ cw
, 0, 0);
1280 R_gl_draw_image(&stone
, 0, 0, 0);
1283 R_gl_draw_image(&stone2
, 0, i
, 0);
1286 if (p
->drawst
& PL_DRAWAIR
) {
1287 if (p
->air
< PL_AIR
) {
1288 int a
= min(max(p
->air
, 0), MAXAIR
) * 100 / MAXAIR
;
1289 glDisable(GL_BLEND
);
1290 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1291 glDisable(GL_TEXTURE_2D
);
1292 R_gl_set_color(0xC8);
1293 R_gl_draw_quad(10, 49, a
, 2);
1296 if (p
->drawst
& PL_DRAWLIFE
) {
1298 Z_printhf("%3d%%", p
->life
);
1300 if (p
->drawst
& PL_DRAWARMOR
) {
1301 Z_gotoxy(10, 7 + 19);
1302 Z_printhf("%3d%%", p
->armor
);
1304 if (p
->drawst
& PL_DRAWWPN
) {
1331 R_gl_draw_image(&sth
[12 + p
->wpn
], st
- 88, 58 + 19, 0);
1335 Z_gotoxy(st
- 10 - 5 * 14, 58 + 2);
1336 Z_printhf("%5d", i
);
1339 if (p
->drawst
& PL_DRAWFRAG
&& g_dm
) {
1340 Z_gotoxy(st
- 5 - 5 * 14, 77 + 5);
1341 Z_printhf("%5d", p
->frag
);
1343 if (p
->drawst
& PL_DRAWKEYS
) {
1345 for (k
= p
->keys
>> 4, n
= 0, x
= st
- 75; n
< 3; n
++, k
>>= 1, x
+= 9) {
1347 R_gl_draw_image(&keys
[n
], x
, 91, 0);
1351 if (p
->drawst
& PL_DRAWLIVES
&& !_2pl
) {
1352 Z_gotoxy(st
- 35, 17);
1353 Z_printhf("%d", p
->lives
);
1360 static void pl_info (player_t
*p
, int x
, int y
) {
1361 dword t
= p
->kills
* 10920 / g_time
;
1362 Z_gotoxy(x
+ 25, y
); Z_printbf("KILLS");
1363 Z_gotoxy(x
+ 25, y
+ 15); Z_printbf("KPM");
1364 Z_gotoxy(x
+ 25, y
+ 30); Z_printbf("SECRETS %u / %u", p
->secrets
, sw_secrets
);
1365 Z_gotoxy(x
+ 255, y
); Z_printbf("%u", p
->kills
);
1366 Z_gotoxy(x
+ 255, y
+ 15); Z_printbf("%u.%u", t
/ 10, t
% 10);
1369 static void R_draw_intermission (void) {
1372 Z_gotoxy(cx
- 14*12/2, 20);
1373 Z_printbf("LEVEL COMPLETE");
1374 Z_calc_time(g_time
, &hr
, &mn
, &sc
);
1375 Z_gotoxy(cx
- 12*12/2, 40);
1376 Z_printbf("TIME %u:%02u:%02u", hr
, mn
, sc
);
1379 Z_gotoxy(cx
- 10*12/2, h
);
1380 Z_printbf("PLAYER ONE");
1383 pl_info(&pl1
, cx
- 160, h
);
1385 h
+= 30 + SCRH
/ 10;
1386 Z_gotoxy(cx
- 10*12/2, h
);
1387 Z_printbf("PLAYER TWO");
1389 pl_info(&pl2
, cx
- 160, h
);
1393 static void W_act (void) {
1395 if (g_time
% 3 == 0) {
1396 for (i
= 1; i
< max_textures
; i
++) {
1400 if (anip
[a
][anic
[a
]].res
== -1) {
1403 walp
[i
] = anip
[a
][anic
[a
]];
1409 void R_draw (void) {
1411 glClearColor(0, 0, 0, 1);
1412 glClear(GL_COLOR_BUFFER_BIT
);
1413 glEnable(GL_SCISSOR_TEST
);
1424 R_gl_draw_image_ext(&scrnh
[0], 0, 0, SCRW
, SCRH
);
1427 R_gl_draw_image_ext(&scrnh
[1], 0, 0, SCRW
, SCRH
);
1428 R_draw_intermission();
1431 R_gl_draw_image_ext(&scrnh
[2], 0, 0, SCRW
, SCRH
);
1435 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
/ 2);
1436 R_draw_player_view(&pl2
, 0, SCRH
/ 2, SCRW
, SCRH
/ 2);
1438 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
);
1440 R_gl_setclip(0, 0, SCRW
, SCRH
);
1447 void R_alloc (void) {
1450 logo("R_alloc: load graphics\n");
1452 scrnh
[0] = R_gl_loadimage("TITLEPIC");
1454 scrnh
[1] = R_gl_loadimage("INTERPIC");
1455 scrnh
[2] = R_gl_loadimage("ENDPIC");
1456 for (i
= 0; i
< 2; i
++) {
1457 sprintf(s
, "LTN%c", '1' + i
);
1458 for (j
= 0; j
< 2; j
++) {
1459 ltn
[i
][j
] = Z_getspr(s
, j
, 0, NULL
);
1463 for (i
= 0; i
< SMSN
; i
++) {
1464 smk_spr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_smoke_spr
);
1466 for (i
= 0; i
< FLSN
; i
++) {
1467 smk_fspr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_flame_spr
);
1470 for (i
= 0; i
< 10; i
++) {
1471 fx_spr
[i
] = Z_getspr("TFOG", i
, 0, fx_sprd
+ i
);
1473 for (; i
< 15; i
++) {
1474 fx_spr
[i
] = Z_getspr("IFOG", i
- 10, 0, fx_sprd
+ i
);
1477 for (i
= 0; i
< 4; i
++) {
1478 wp_spr
[i
* 2] = Z_getspr("MISL", i
, 1, wp_sprd
+ i
* 2);
1479 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
, 2, wp_sprd
+ i
* 2 + 1);
1481 for (; i
< 6; i
++) {
1482 wp_spr
[i
* 2] = Z_getspr("PLSS", i
- 4, 1, wp_sprd
+ i
* 2);
1483 wp_spr
[i
* 2 + 1] = Z_getspr("PLSS", i
- 4, 2, wp_sprd
+ i
* 2 + 1);
1485 for (; i
< 11; i
++) {
1486 wp_spr
[i
* 2] = Z_getspr("PLSE", i
- 6, 1, wp_sprd
+ i
* 2);
1487 wp_spr
[i
* 2 + 1] = Z_getspr("PLSE", i
- 6, 2, wp_sprd
+ i
* 2 + 1);
1489 for (; i
< 13; i
++) {
1490 wp_spr
[i
* 2] = Z_getspr("APLS", i
- 11, 1, wp_sprd
+ i
* 2);
1491 wp_spr
[i
* 2 + 1] = Z_getspr("APLS", i
- 11, 2, wp_sprd
+ i
* 2 + 1);
1493 for (; i
< 18; i
++) {
1494 wp_spr
[i
* 2] = Z_getspr("APBX", i
- 13, 1, wp_sprd
+ i
* 2);
1495 wp_spr
[i
* 2 + 1] = Z_getspr("APBX", i
- 13, 2, wp_sprd
+ i
* 2 + 1);
1497 for(; i
< 20; i
++) {
1498 wp_spr
[i
* 2] = Z_getspr("BFS1", i
- 18, 1, wp_sprd
+ i
* 2);
1499 wp_spr
[i
* 2 + 1] = Z_getspr("BFS1", i
- 18, 2, wp_sprd
+ i
* 2 + 1);
1501 for (; i
< 26; i
++) {
1502 wp_spr
[i
* 2] = Z_getspr("BFE1", i
- 20, 1, wp_sprd
+ i
* 2);
1503 wp_spr
[i
* 2 + 1] = Z_getspr("BFE1", i
- 20, 2, wp_sprd
+ i
* 2 + 1);
1505 for (; i
< 30; i
++) {
1506 wp_spr
[i
* 2] = Z_getspr("BFE2", i
- 26, 1, wp_sprd
+ i
* 2);
1507 wp_spr
[i
* 2 + 1] = Z_getspr("BFE2", i
- 26, 2, wp_sprd
+ i
* 2 + 1);
1509 for (; i
< 32; i
++) {
1510 wp_spr
[i
* 2] = Z_getspr("MISL", i
- 30 + 4, 1, wp_sprd
+ i
* 2);
1511 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
- 30 + 4, 2, wp_sprd
+ i
* 2 + 1);
1513 for (; i
< 37; i
++) {
1514 wp_spr
[i
* 2] = Z_getspr("BAL1", i
- 32, 1, wp_sprd
+ i
* 2);
1515 wp_spr
[i
* 2 + 1] = Z_getspr("BAL1", i
- 32, 2, wp_sprd
+ i
* 2 + 1);
1517 for (; i
< 42; i
++) {
1518 wp_spr
[i
* 2] = Z_getspr("BAL7", i
- 37, 1, wp_sprd
+ i
* 2);
1519 wp_spr
[i
* 2 + 1] = Z_getspr("BAL7", i
- 37, 2, wp_sprd
+ i
* 2 + 1);
1521 for (; i
< 47; i
++) {
1522 wp_spr
[i
* 2] = Z_getspr("BAL2", i
- 42, 1, wp_sprd
+ i
* 2);
1523 wp_spr
[i
* 2 + 1] = Z_getspr("BAL2", i
- 42, 2, wp_sprd
+ i
* 2 + 1);
1525 for (; i
< 49; i
++) {
1526 wp_spr
[i
* 2] = Z_getspr("MANF", i
- 47, 1, wp_sprd
+ i
* 2);
1527 wp_spr
[i
* 2 + 1] = Z_getspr("MANF", i
- 47, 2, wp_sprd
+ i
* 2 + 1);
1530 static const char snm
[18][4] = {
1531 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1532 "STIM", "MEDI", "BPAK",
1533 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1535 static const char n4
[4][4] = {
1536 "SOUL", "SMRT", "SMGT", "SMBT"
1538 static const char n3
[2][4] = {
1541 for (i
= 0; i
< 18; i
++) {
1542 item_spr
[i
] = Z_getspr(snm
[i
], 0, 0, item_sprd
+ i
);
1544 for (; i
< 20; i
++) {
1545 item_spr
[i
] = Z_getspr("ARM1", i
- 18, 0, item_sprd
+ i
);
1546 item_spr
[i
+ 2] = Z_getspr("ARM2", i
- 18, 0, item_sprd
+ i
);
1549 for (; i
< 26; i
++) {
1550 item_spr
[i
] = Z_getspr("MEGA", i
- 22, 0, item_sprd
+ i
);
1552 for (; i
< 30; i
++) {
1553 item_spr
[i
] = Z_getspr("PINV", i
- 26, 0, item_sprd
+ i
);
1555 item_spr
[30] = Z_getspr("AQUA", 0, 0, item_sprd
+ 30);
1556 item_spr
[31] = Z_getspr("KEYR", 0, 0, item_sprd
+ 31);
1557 item_spr
[32] = Z_getspr("KEYG", 0, 0, item_sprd
+ 32);
1558 item_spr
[33] = Z_getspr("KEYB", 0, 0, item_sprd
+ 33);
1559 item_spr
[34] = Z_getspr("SUIT", 0, 0, item_sprd
+ 34);
1560 for (n
= 35, j
= 0; j
< 4; j
++) {
1561 for (i
= 0; i
< 4; i
++, n
++) {
1562 item_spr
[n
] = Z_getspr(n4
[j
], i
, 0, item_sprd
+ n
);
1565 for (j
= 0; j
< 2; j
++) {
1566 for (i
= 0; i
< 3; i
++, n
++) {
1567 item_spr
[n
] = Z_getspr(n3
[j
], i
, 0, item_sprd
+ n
);
1570 item_spr
[57] = Z_getspr("GUN2", 0, 0, item_sprd
+ 57);
1572 for (i
= 0; i
< 27; i
++) {
1573 plr_spr
[i
* 2] = Z_getspr("PLAY", i
, 1, plr_sprd
+ i
* 2);
1574 plr_msk
[i
* 2] = R_gl_get_special_spr("PLAY", i
, 1, &R_extract_mask_spr
);
1575 plr_spr
[i
* 2 + 1] = Z_getspr("PLAY", i
, 2, plr_sprd
+ i
* 2 + 1);
1576 plr_msk
[i
* 2 + 1] = R_gl_get_special_spr("PLAY", i
, 2, &R_extract_mask_spr
);
1578 strncpy(s
, "PWPx", 4);
1579 for (i
= 1; i
< 11; i
++) {
1580 s
[3] = (i
< 10 ? '0' : 'A' - 10) + i
;
1581 for (j
= 0; j
< 6; j
++) {
1582 plr_wpn
[i
][j
] = Z_getspr(s
, j
, 1, NULL
);
1586 static const char msn
[MN_TN
][4] = {
1587 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1588 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1590 static const int mms
[MN_TN
] = {
1591 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1592 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1594 mn_sgun
[0] = Z_getspr("PWP4", 0, 1, NULL
);
1595 mn_sgun
[1] = Z_getspr("PWP4", 1, 1, NULL
);
1596 for (j
= 0; j
< MN_TN
; j
++) {
1597 for (i
= 0; i
< mms
[j
]; i
++) {
1598 mn_spr
[j
][i
] = Z_getspr(msn
[j
], i
/ 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1599 if (j
== MN_MAN
- 1) {
1600 mn_man_msk
[i
] = R_gl_get_special_spr(msn
[j
], i
/ 2, (i
& 1) + 1, &R_extract_mask_spr
);
1603 if (j
== MN_BARREL
- 1) {
1604 for (i
= 4; i
< 14; i
++) {
1605 mn_spr
[j
][i
] = Z_getspr("BEXP", i
/ 2 - 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1609 for (i
= 0; i
< 8; i
++) {
1610 mn_fspr
[i
] = Z_getspr("FIRE", i
, 0, NULL
);
1612 pl_spr
[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL
);
1613 pl_msk
[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr
);
1614 pl_spr
[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL
);
1615 pl_msk
[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr
);
1617 static const char mnm
[22][8]={
1618 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1619 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1620 "STTMINUS", "STTPRCNT",
1621 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1622 "PLASA0", "BFUGA0", "GUN2A0"
1624 stone
= R_gl_loadimage("STONE");
1625 stone2
= R_gl_loadimage("STONE2");
1626 keys
[0] = R_gl_loadimage("KEYRA0");
1627 keys
[1] = R_gl_loadimage("KEYGA0");
1628 keys
[2] = R_gl_loadimage("KEYBA0");
1629 for (i
= 0; i
< 22; i
++) {
1630 sth
[i
] = R_gl_loadimage(mnm
[i
]);
1632 strcpy(s
, "STBF_*");
1633 for (i
= '!'; i
< 160; i
++) {
1635 bfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1637 for (i
= '!'; i
< 160; i
++) {
1638 sprintf(s
, "STCFN%03d", i
);
1639 sfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1641 strcpy(s
, "WINUM*");
1642 for (i
= '0'; i
<= '9'; i
++) {
1644 bfh
[i
- '!'] = R_gl_loadimage(s
);
1646 bfh
[':' - '!'] = R_gl_loadimage("WICOLON");
1648 msklh
[0] = R_gl_loadimage("M_SKULL1");
1649 msklh
[1] = R_gl_loadimage("M_SKULL2");
1650 mbarl
= R_gl_loadimage("M_THERML");
1651 mbarm
= R_gl_loadimage("M_THERMM");
1652 mbarr
= R_gl_loadimage("M_THERMR");
1653 mbaro
= R_gl_loadimage("M_THERMO");
1654 mslotl
= R_gl_loadimage("M_LSLEFT");
1655 mslotm
= R_gl_loadimage("M_LSCNTR");
1656 mslotr
= R_gl_loadimage("M_LSRGHT");
1658 for (i
= 1; i
< ANIT
; i
++) {
1659 for (j
= 0; anm
[i
- 1][j
]; j
++) {
1660 anip
[i
][j
] = R_gl_loadimage(anm
[i
- 1][j
]);
1663 anip
[i
][j
] = (image
) {
1673 void R_init (void) {
1675 int flags
= SYSTEM_USE_OPENGL
;
1677 flags
|= SYSTEM_USE_FULLSCREEN
;
1679 logo("R_init: intialize opengl render\n");
1680 int was
= Y_videomode_setted();
1681 if (SCRW
<= 0 || SCRH
<= 0) {
1682 ERR_failinit("Invalid screen size %ix%i\n", SCRW
, SCRH
);
1685 R_init_playpal(); // only onece
1687 res
= Y_set_videomode(SCRW
, SCRH
, flags
);
1689 ERR_failinit("Unable to set video mode\n");
1691 root
= R_cache_new();
1696 void R_done (void) {
1697 R_cache_free(root
, 1);
1698 Y_unset_videomode();
1701 void R_setgamma (int g
) {
1702 gamma
= g
< 0 ? 0 : (g
> 4 ? 4 : g
);
1705 int R_getgamma (void) {
1709 void R_toggle_fullscreen (void) {
1710 Y_set_fullscreen(!Y_get_fullscreen());
1711 fullscreen
= Y_get_fullscreen();
1715 void R_get_name (int n
, char s
[8]) {
1716 assert(n
>= 0 && n
< 256);
1717 if (walp
[n
].res
== -1) {
1719 } else if (walp
[n
].res
== -2) {
1720 memcpy(s
, "_WATER_", 8);
1721 s
[7] = '0' + (intptr_t)walp
[n
].n
- 1;
1722 } else if (walani
[n
] > 0) {
1723 memcpy(s
, anm
[walani
[n
] - 1][0], 8);
1725 F_getresname(s
, walp
[n
].res
& 0x7FFF);
1729 static short getani (char n
[8]) {
1731 while (i
< ANIT
- 1 && strncasecmp(n
, anm
[i
][0], 8) != 0) {
1734 return i
< ANIT
- 1 ? i
+ 1 : 0;
1737 int R_get_special_id (int n
) {
1738 assert(n
>= 0 && n
<= 256);
1739 return walp
[n
].res
== -2 ? (intptr_t)walp
[n
].n
: -1;
1742 void R_begin_load (void) {
1744 for (i
= 0; i
< 256; i
++) {
1745 if (walp
[i
].n
!= NULL
&& walp
[i
].res
>= 0 && walani
[i
] == 0) {
1746 R_gl_free_image(&walp
[i
]);
1748 memset(&walp
[i
], 0, sizeof(image
));
1753 memset(anic
, 0, sizeof(anic
));
1755 max_wall_height
= 0;
1759 void R_load (char s
[8], int f
) {
1760 assert(max_textures
< 256);
1762 walp
[max_textures
] = (image
) {
1770 } else if (strncasecmp(s
, "_WATER_", 7) == 0) {
1771 walp
[max_textures
] = (image
) {
1772 .n
= (void*)((intptr_t)s
[7] - '0' + 1),
1780 walp
[max_textures
] = R_gl_loadimage(s
);
1782 walp
[max_textures
].res
|= 0x8000;
1784 if (s
[0] == 'S' && s
[1] == 'W' && s
[4] == '_') {
1785 walswp
[max_textures
] = 0;
1787 walani
[max_textures
] = getani(s
);
1789 max_wall_width
= max(max_wall_width
, walp
[max_textures
].w
);
1790 max_wall_height
= max(max_wall_height
, walp
[max_textures
].h
);
1794 void R_end_load (void) {
1798 for (i
= 1; i
< 256 && j
< 256; i
++) {
1799 if (walswp
[i
] == 0) {
1802 g
= F_getresid(s
) | (walp
[i
].res
& 0x8000);
1804 while (k
< 256 && walp
[k
].res
!= g
) {
1810 walp
[k
] = R_gl_getimage(g
);
1811 walf
[k
] = g
& 0x8000 ? 1 : 0;
1819 void R_loadsky (int sky
) {
1823 R_gl_free_image(&horiz
);
1824 horiz
= R_gl_loadimage(s
);