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 {%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 void Z_putch_generic (image img
[], int off
, int ch
) {
633 if (ch
> 32 && ch
< 160) {
637 R_gl_draw_image(p
, prx
, pry
, 0);
644 static void Z_printf_generic (image img
[], int off
, const char *fmt
, va_list ap
) {
647 vsprintf(buf
, fmt
, ap
);
648 for (i
= 0; buf
[i
]; ++i
) {
656 Z_putch_generic(img
, off
, (byte
)buf
[i
]);
661 static void Z_gotoxy (int x
, int y
) {
666 static void Z_printbf (const char *fmt
, ...) {
669 Z_printf_generic(bfh
, 12, fmt
, a
);
673 static void Z_printsf (const char *fmt
, ...) {
676 Z_printf_generic(sfh
, 7, fmt
, a
);
680 static void Z_printhf (const char *fmt
, ...) {
685 vsprintf(buf
, fmt
, a
);
687 for (i
= 0; buf
[i
]; ++i
) {
718 R_gl_draw_image(&sth
[c
], prx
, pry
, 0);
726 static image
*PL_getspr (int s
, int d
, int msk
) {
727 int i
= (s
- 'A') * 2 + d
;
728 return msk
? &plr_msk
[i
] : &plr_spr
[i
];
731 static void GM_draw (void) {
732 enum {MENU
, MSG
}; // copypasted from menu.c!
734 CANCEL
, NEWGAME
, LOADGAME
, SAVEGAME
, OPTIONS
, QUITGAME
, QUIT
, ENDGAME
, ENDGM
,
735 PLR1
, PLR2
, COOP
, DM
, VOLUME
, GAMMA
, LOAD
, SAVE
, PLCOLOR
, PLCEND
, MUSIC
, INTERP
,
736 SVOLM
, SVOLP
, MVOLM
, MVOLP
, GAMMAM
, GAMMAP
, PL1CM
, PL1CP
, PL2CM
, PL2CP
737 }; // copypasted from menu.c!
738 int i
, j
, k
, x
, y
, cx
, cy
;
744 if (mnu
->type
== MENU
) {
745 y
= cy
- (mnu
->n
* 16 - 20) / 2;
746 Z_gotoxy(cx
- mnu
->x
, y
- 10); Z_printbf("%s", mnu
->ttl
);
747 for (i
= 0; i
< mnu
->n
; i
++) {
748 if (mnu
->t
[i
] == LOAD
|| mnu
->t
[i
] == SAVE
) {
750 R_gl_draw_image(&mslotl
, cx
- mnu
->x
, j
, 0);
751 for (k
= 8; k
< 184; k
+= 8) {
752 R_gl_draw_image(&mslotm
, cx
- mnu
->x
+ k
, j
, 0);
754 R_gl_draw_image(&mslotr
, cx
- mnu
->x
+ 184, j
, 0);
755 Z_gotoxy(cx
- mnu
->x
+ 4, j
- 8);
756 if (input
&& i
== save_mnu
.cur
) {
757 Z_printsf("%s_", ibuf
);
759 Z_printsf("%s", savname
[i
]);
762 x
= mnu
->t
[i
] >= SVOLM
? (mnu
->t
[i
] >= PL1CM
? 50 : 152) : 0;
763 Z_gotoxy(cx
- mnu
->x
+ x
, y
+ i
* 16 + 20);
764 Z_printbf("%s", mnu
->m
[i
]);
767 Z_printbf(" '%s'", g_music
);
770 Z_printbf("%s", fullscreen
? "ON" : "OFF");
776 img
= PL_getspr(*panimp
, 0, 0);
777 R_gl_draw_image(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
778 img
= PL_getspr(*panimp
, 0, 1);
779 R_gl_set_color(pcolortab
[(mnu
->t
[i
] == PL1CM
) ? p1color
: p2color
] + PLAYER_COLOR_OFFSET
);
780 R_gl_draw_image_color(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
789 R_gl_draw_image(&mbarl
, cx
- mnu
->x
, j
, 0);
790 for (k
= 8; k
< 144; k
+= 8) {
791 R_gl_draw_image(&mbarm
, cx
- mnu
->x
+ k
, j
, 0);
793 R_gl_draw_image(&mbarr
, cx
- mnu
->x
+ 144, j
, 0);
808 R_gl_draw_image(&mbaro
, cx
- mnu
->x
+ 8 + k
, j
, 0);
813 R_gl_draw_image(&msklh
[(gm_tm
/ 6) & 1], cx
- mnu
->x
- 25, y
+ mnu
->cur
* 16 + 20 - 8, 0);
814 } else if (mnu
->type
== MSG
) {
815 Z_gotoxy(cx
- strlen(mnu
->ttl
) * 7 / 2, cy
- 10); Z_printsf(mnu
->ttl
);
816 Z_gotoxy(cx
- 24, SCRH
/ 2); Z_printsf("(Y/N)");
818 ERR_fatal("Unknown menu type %i\n", mnu
->type
);
825 static void R_draw_fld (byte
*fld
, int minx
, int miny
, int maxx
, int maxy
, int fg
) {
827 assert(minx
>= 0 && minx
<= FLDW
);
828 assert(miny
>= 0 && miny
<= FLDH
);
829 assert(maxx
>= 0 && maxx
<= FLDW
);
830 assert(maxy
>= 0 && maxy
<= FLDH
);
831 for (j
= miny
; j
< maxy
; j
++) {
832 for (i
= minx
; i
< maxx
; i
++) {
833 byte id
= fld
[j
* FLDW
+ i
];
835 if (walp
[id
].res
< 0) {
837 switch (R_get_special_id(id
)) {
839 glColor4ub(0, 0, 255, 127);
842 glColor4ub(0, 127, 0, 127);
845 glColor4ub(127, 0, 0, 127);
848 glColor4ub(0, 0, 0, 127);
852 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
853 glDisable(GL_TEXTURE_2D
);
854 R_gl_draw_quad(i
* CELW
, j
* CELW
, CELW
, CELH
);
857 R_gl_draw_image(&walp
[id
], i
* CELW
, j
* CELH
, 0);
864 static void R_draw_dots (void) {
867 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
868 glDisable(GL_TEXTURE_2D
);
870 for (i
= 0; i
< MAXDOT
; i
++) {
872 R_gl_set_color(dot
[i
].c
);
873 glVertex2i(dot
[i
].o
.x
, dot
[i
].o
.y
+ 1);
879 static void R_draw_items (void) {
881 for (i
= 0; i
< MAXITEM
; ++i
) {
883 if (it
[i
].t
&& it
[i
].s
>= 0) {
884 switch (it
[i
].t
& 0x7FFF) {
886 s
= it
[i
].s
/ 9 + 18;
889 s
= it
[i
].s
/ 9 + 20;
892 s
= it
[i
].s
/ 2 + 22;
895 s
= it
[i
].s
/ 2 + 26;
901 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_SUPER
) * 4 + 35;
903 case I_GOR1
: case I_FCAN
:
904 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_GOR1
) * 3 + 51;
915 s
= (it
[i
].t
& 0x7FFF) - I_KEYR
+ 31;
921 s
= (it
[i
].t
& 0x7FFF) - 1;
925 R_gl_draw_image(&item_spr
[s
], it
[i
].o
.x
, it
[i
].o
.y
, item_sprd
[s
]);
930 static int standspr (player_t
*p
) {
933 } else if (p
->f
& PLF_DOWN
) {
940 static int wpnspr (player_t
*p
) {
943 } else if(p
->f
& PLF_DOWN
) {
950 static void R_draw_player (player_t
*p
) {
951 enum {STAND
, GO
, DIE
, SLOP
, DEAD
, MESS
, OUT
, FALL
}; // copypasted from player.c!
952 static const int wytab
[] = {-1, -2, -1, 0};
959 if (p
->f
& PLF_FIRE
) {
962 } else if (p
->pain
) {
985 s
= plr_goanim
[p
->s
/ 8];
986 w
= (p
->f
& PLF_FIRE
) ? 'B' : 'A';
988 wy
= 1 + wytab
[s
- 'A'];
992 s
= plr_dieanim
[p
->s
];
995 s
= plr_slopanim
[p
->s
];
1005 R_gl_draw_image(&plr_wpn
[(int)p
->wpn
][w
-'A'], p
->o
.x
+ wx
, p
->o
.y
+ wy
, p
->d
);
1008 R_gl_draw_image(&plr_spr
[(s
- 'A') * 2 + p
->d
], p
->o
.x
, p
->o
.y
, plr_sprd
[(s
- 'A') * 2 + p
->d
]);
1009 R_gl_set_color(p
->color
+ PLAYER_COLOR_OFFSET
);
1010 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
]);
1014 static void R_draw_monsters (void) {
1015 enum {SLEEP
, GO
, RUN
, CLIMB
, DIE
, DEAD
, ATTACK
, SHOOT
, PAIN
, WAIT
, REVIVE
, RUNOUT
}; // copypasted from monster.c!
1017 for (i
= 0; i
< MAXMN
; i
++) {
1018 if (mn
[i
].t
!= MN_NONE
) {
1021 if (mn
[i
].t
< MN__LAST
) {
1022 if ((mn
[i
].t
!= MN_SOUL
&& mn
[i
].t
!= MN_PAIN
) || mn
[i
].st
!= DEAD
) {
1023 int ap
= mn
[i
].ap
[mn
[i
].ac
];
1024 int d
= (ap
- 'A') * 2 + mn
[i
].d
;
1025 int dir
= mn_sprd
[mn
[i
].t
- 1][d
];
1026 if (mn
[i
].t
== MN_MAN
&& (ap
== 'E' || ap
== 'F')) {
1027 R_gl_draw_image(&mn_sgun
[ap
- 'E'], x
, y
, mn
[i
].d
);
1029 R_gl_draw_image(&mn_spr
[mn
[i
].t
- 1][d
], x
, y
, dir
);
1030 if (mn
[i
].t
== MN_MAN
) {
1031 R_gl_set_color(MANCOLOR
+ PLAYER_COLOR_OFFSET
);
1032 R_gl_draw_image_color(&mn_man_msk
[d
], x
, y
, dir
);
1035 if (mn
[i
].t
== MN_VILE
&& mn
[i
].st
== SHOOT
) {
1036 R_gl_draw_image(&mn_fspr
[mn
[i
].ac
/ 3], mn
[i
].tx
, mn
[i
].ty
, 0);
1038 } else if (mn
[i
].t
== MN_PL_DEAD
|| mn
[i
].t
== MN_PL_MESS
) {
1039 int type
= mn
[i
].t
- MN_PL_DEAD
;
1040 R_gl_draw_image(&pl_spr
[type
], x
, y
, 0);
1041 R_gl_set_color(mn
[i
].d
);
1042 R_gl_draw_image_color(&pl_msk
[type
], x
, y
, 0);
1048 static void R_draw_weapons (void) {
1049 enum {NONE
, ROCKET
, PLASMA
, APLASMA
, BALL1
, BALL2
, BALL7
, BFGBALL
, BFGHIT
, MANF
, REVF
, FIRE
}; // copypasted from weapons.c!
1051 for (i
= 0; i
< MAXWPN
; ++i
) {
1059 d
= wp
[i
].o
.xv
> 0 ? 1 : 0;
1060 x
= abs(wp
[i
].o
.xv
);
1073 s
= (d
- 2) / 2 + 1;
1107 d
= wp
[i
].o
.xv
>= 0 ? 1 : 0;
1111 d
= wp
[i
].o
.xv
>=0 ? 1 : 0;
1123 s
= wp
[i
].s
/ 2 + 26;
1127 R_gl_draw_image(&wp_spr
[s
* 2 + d
], wp
[i
].o
.x
, wp
[i
].o
.y
, wp_sprd
[s
* 2 + d
]);
1132 static void R_draw_smoke (void) {
1134 for (i
= 0; i
< MAXSMOK
; ++i
) {
1139 if (s
>= (SMSN
- 1) * 3) {
1142 s
= SMSN
- 1 - s
/ 3;
1144 R_gl_draw_image(&smk_spr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1148 if (s
>= FLSN
- 1) {
1153 R_gl_draw_image(&smk_fspr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1160 static void R_draw_effects (void) {
1161 enum {NONE
, TFOG
, IFOG
, BUBL
}; // copypasted from fx.c
1163 for (i
= 0; i
< MAXFX
; ++i
) {
1167 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1170 s
= fx
[i
].s
/ 2 + 10;
1171 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1174 glDisable(GL_BLEND
);
1175 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1176 glDisable(GL_TEXTURE_2D
);
1178 R_gl_set_color(0xC0 + fx
[i
].s
);
1179 glVertex2i(fx
[i
].x
>> 8, (fx
[i
].y
>> 8) + 1);
1186 static int get_pu_st (int t
) {
1187 if (t
>= PL_FLASH
) {
1189 } else if((t
/ 9) & 1) {
1196 static void R_draw_view (int x
, int y
, int w
, int h
, int camx
, int camy
) {
1198 R_gl_setclip(x
, y
, w
, h
);
1199 glTranslatef(x
, y
, 0);
1200 if (w_horiz
&& horiz
.n
!= NULL
) {
1201 R_gl_draw_image_ext(&horiz
, 0, 0, w
, h
);
1202 if (sky_type
== 2 && lt_time
< 0) {
1203 image
*tanderbolt
= <n
[lt_type
][lt_time
< -5 ? 0 : 1];
1205 R_gl_draw_image(tanderbolt
, 0, lt_ypos
, 0);
1207 R_gl_draw_image(tanderbolt
, w
- 1, lt_ypos
, 1);
1211 glDisable(GL_BLEND
);
1212 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1213 glDisable(GL_TEXTURE_2D
);
1214 R_gl_set_color(DEFAULT_SKY_COLOR
);
1215 R_gl_draw_quad(0, 0, w
, h
);
1217 int maxx
= min((camx
+ w
) / CELW
+ 1, FLDW
);
1218 int maxy
= min((camy
+ h
) / CELH
+ 1, FLDH
);
1219 int minx
= max((camx
- max_wall_width
) / CELW
, 0);
1220 int miny
= max((camy
- max_wall_height
) / CELH
, 0);
1221 glTranslatef(-camx
, -camy
, 0);
1222 R_draw_fld((byte
*)fldb
, minx
, miny
, maxx
, maxy
, 0);
1225 R_draw_player(&pl1
);
1227 R_draw_player(&pl2
);
1233 R_draw_fld((byte
*)fldf
, minx
, miny
, maxx
, maxy
, 1);
1234 glTranslatef(camx
, camy
, 0);
1235 if (sky_type
== 2 && (lt_time
== -4 || lt_time
== -2)) {
1236 glColor4ub(255, 255, 255, 255);
1238 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
1239 glDisable(GL_TEXTURE_2D
);
1240 R_gl_draw_quad(0, 0, w
, h
);
1245 static void R_draw_player_view (player_t
*p
, int x
, int y
, int w
, int h
) {
1246 p
->looky
= min(max(p
->looky
, -SCRH
/ 4), SCRH
/ 4); // TODO remove writeback
1249 int cx
= min(max(p
->o
.x
, cw
/ 2), FLDW
* CELW
- cw
/ 2);
1250 int cy
= min(max(p
->o
.y
- 12 + p
->looky
, h
/ 2), FLDH
* CELH
- h
/ 2);
1251 int camx
= max(cx
- cw
/ 2, 0);
1252 int camy
= max(cy
- h
/ 2, 0);
1254 R_draw_view(x
, y
+ 1, cw
, h
- 2, camx
, camy
);
1255 glTranslatef(x
, y
, 0);
1257 if (get_pu_st(p
->invl
)) {
1259 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
);
1260 glDisable(GL_TEXTURE_2D
);
1261 glColor4ub(191, 191, 191, 255);
1262 R_gl_draw_quad(0, 0, cw
, h
);
1265 if (p
->suit
&& get_pu_st(p
->suit
)) {
1267 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1268 glDisable(GL_TEXTURE_2D
);
1269 glColor4ub(0, 255, 0, 192);
1270 R_gl_draw_quad(0, 0, cw
, h
);
1272 int f
= min(max(p
->pain
* 3, 0), 255);
1275 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1276 glDisable(GL_TEXTURE_2D
);
1277 glColor4ub(255, 0, 0, f
);
1278 R_gl_draw_quad(0, 0, cw
, h
);
1281 R_gl_setclip(x
, y
, w
, h
);
1282 glTranslatef(-x
+ cw
, 0, 0);
1283 R_gl_draw_image(&stone
, 0, 0, 0);
1286 R_gl_draw_image(&stone2
, 0, i
, 0);
1289 if (p
->drawst
& PL_DRAWAIR
) {
1290 if (p
->air
< PL_AIR
) {
1291 int a
= min(max(p
->air
, 0), MAXAIR
) * 100 / MAXAIR
;
1292 glDisable(GL_BLEND
);
1293 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1294 glDisable(GL_TEXTURE_2D
);
1295 R_gl_set_color(0xC8);
1296 R_gl_draw_quad(10, 49, a
, 2);
1299 if (p
->drawst
& PL_DRAWLIFE
) {
1301 Z_printhf("%3d%%", p
->life
);
1303 if (p
->drawst
& PL_DRAWARMOR
) {
1304 Z_gotoxy(10, 7 + 19);
1305 Z_printhf("%3d%%", p
->armor
);
1307 if (p
->drawst
& PL_DRAWWPN
) {
1334 R_gl_draw_image(&sth
[12 + p
->wpn
], st
- 88, 58 + 19, 0);
1338 Z_gotoxy(st
- 10 - 5 * 14, 58 + 2);
1339 Z_printhf("%5d", i
);
1342 if (p
->drawst
& PL_DRAWFRAG
&& g_dm
) {
1343 Z_gotoxy(st
- 5 - 5 * 14, 77 + 5);
1344 Z_printhf("%5d", p
->frag
);
1346 if (p
->drawst
& PL_DRAWKEYS
) {
1348 for (k
= p
->keys
>> 4, n
= 0, x
= st
- 75; n
< 3; n
++, k
>>= 1, x
+= 9) {
1350 R_gl_draw_image(&keys
[n
], x
, 91, 0);
1354 if (p
->drawst
& PL_DRAWLIVES
&& !_2pl
) {
1355 Z_gotoxy(st
- 35, 17);
1356 Z_printhf("%d", p
->lives
);
1363 static void pl_info (player_t
*p
, int x
, int y
) {
1364 dword t
= p
->kills
* 10920 / g_time
;
1365 Z_gotoxy(x
+ 25, y
); Z_printbf("KILLS");
1366 Z_gotoxy(x
+ 25, y
+ 15); Z_printbf("KPM");
1367 Z_gotoxy(x
+ 25, y
+ 30); Z_printbf("SECRETS %u / %u", p
->secrets
, sw_secrets
);
1368 Z_gotoxy(x
+ 255, y
); Z_printbf("%u", p
->kills
);
1369 Z_gotoxy(x
+ 255, y
+ 15); Z_printbf("%u.%u", t
/ 10, t
% 10);
1372 static void R_draw_intermission (void) {
1375 Z_gotoxy(cx
- 14*12/2, 20);
1376 Z_printbf("LEVEL COMPLETE");
1377 Z_calc_time(g_time
, &hr
, &mn
, &sc
);
1378 Z_gotoxy(cx
- 12*12/2, 40);
1379 Z_printbf("TIME %u:%02u:%02u", hr
, mn
, sc
);
1382 Z_gotoxy(cx
- 10*12/2, h
);
1383 Z_printbf("PLAYER ONE");
1386 pl_info(&pl1
, cx
- 160, h
);
1388 h
+= 30 + SCRH
/ 10;
1389 Z_gotoxy(cx
- 10*12/2, h
);
1390 Z_printbf("PLAYER TWO");
1392 pl_info(&pl2
, cx
- 160, h
);
1396 static void W_act (void) {
1398 if (g_time
% 3 == 0) {
1399 for (i
= 1; i
< max_textures
; i
++) {
1403 if (anip
[a
][anic
[a
]].res
== -1) {
1406 walp
[i
] = anip
[a
][anic
[a
]];
1412 void R_draw (void) {
1414 glClearColor(0, 0, 0, 1);
1415 glClear(GL_COLOR_BUFFER_BIT
);
1416 glEnable(GL_SCISSOR_TEST
);
1427 R_gl_draw_image_ext(&scrnh
[0], 0, 0, SCRW
, SCRH
);
1430 R_gl_draw_image_ext(&scrnh
[1], 0, 0, SCRW
, SCRH
);
1431 R_draw_intermission();
1434 R_gl_draw_image_ext(&scrnh
[2], 0, 0, SCRW
, SCRH
);
1438 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
/ 2);
1439 R_draw_player_view(&pl2
, 0, SCRH
/ 2, SCRW
, SCRH
/ 2);
1441 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
);
1443 R_gl_setclip(0, 0, SCRW
, SCRH
);
1450 void R_alloc (void) {
1453 logo("R_alloc: load graphics\n");
1455 scrnh
[0] = R_gl_loadimage("TITLEPIC");
1456 scrnh
[1] = R_gl_loadimage("INTERPIC");
1457 scrnh
[2] = R_gl_loadimage("ENDPIC");
1458 for (i
= 0; i
< 2; i
++) {
1459 sprintf(s
, "LTN%c", '1' + i
);
1460 for (j
= 0; j
< 2; j
++) {
1461 ltn
[i
][j
] = Z_getspr(s
, j
, 0, NULL
);
1465 for (i
= 0; i
< SMSN
; i
++) {
1466 smk_spr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_smoke_spr
);
1468 for (i
= 0; i
< FLSN
; i
++) {
1469 smk_fspr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_flame_spr
);
1472 for (i
= 0; i
< 10; i
++) {
1473 fx_spr
[i
] = Z_getspr("TFOG", i
, 0, fx_sprd
+ i
);
1475 for (; i
< 15; i
++) {
1476 fx_spr
[i
] = Z_getspr("IFOG", i
- 10, 0, fx_sprd
+ i
);
1479 for (i
= 0; i
< 4; i
++) {
1480 wp_spr
[i
* 2] = Z_getspr("MISL", i
, 1, wp_sprd
+ i
* 2);
1481 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
, 2, wp_sprd
+ i
* 2 + 1);
1483 for (; i
< 6; i
++) {
1484 wp_spr
[i
* 2] = Z_getspr("PLSS", i
- 4, 1, wp_sprd
+ i
* 2);
1485 wp_spr
[i
* 2 + 1] = Z_getspr("PLSS", i
- 4, 2, wp_sprd
+ i
* 2 + 1);
1487 for (; i
< 11; i
++) {
1488 wp_spr
[i
* 2] = Z_getspr("PLSE", i
- 6, 1, wp_sprd
+ i
* 2);
1489 wp_spr
[i
* 2 + 1] = Z_getspr("PLSE", i
- 6, 2, wp_sprd
+ i
* 2 + 1);
1491 for (; i
< 13; i
++) {
1492 wp_spr
[i
* 2] = Z_getspr("APLS", i
- 11, 1, wp_sprd
+ i
* 2);
1493 wp_spr
[i
* 2 + 1] = Z_getspr("APLS", i
- 11, 2, wp_sprd
+ i
* 2 + 1);
1495 for (; i
< 18; i
++) {
1496 wp_spr
[i
* 2] = Z_getspr("APBX", i
- 13, 1, wp_sprd
+ i
* 2);
1497 wp_spr
[i
* 2 + 1] = Z_getspr("APBX", i
- 13, 2, wp_sprd
+ i
* 2 + 1);
1499 for(; i
< 20; i
++) {
1500 wp_spr
[i
* 2] = Z_getspr("BFS1", i
- 18, 1, wp_sprd
+ i
* 2);
1501 wp_spr
[i
* 2 + 1] = Z_getspr("BFS1", i
- 18, 2, wp_sprd
+ i
* 2 + 1);
1503 for (; i
< 26; i
++) {
1504 wp_spr
[i
* 2] = Z_getspr("BFE1", i
- 20, 1, wp_sprd
+ i
* 2);
1505 wp_spr
[i
* 2 + 1] = Z_getspr("BFE1", i
- 20, 2, wp_sprd
+ i
* 2 + 1);
1507 for (; i
< 30; i
++) {
1508 wp_spr
[i
* 2] = Z_getspr("BFE2", i
- 26, 1, wp_sprd
+ i
* 2);
1509 wp_spr
[i
* 2 + 1] = Z_getspr("BFE2", i
- 26, 2, wp_sprd
+ i
* 2 + 1);
1511 for (; i
< 32; i
++) {
1512 wp_spr
[i
* 2] = Z_getspr("MISL", i
- 30 + 4, 1, wp_sprd
+ i
* 2);
1513 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
- 30 + 4, 2, wp_sprd
+ i
* 2 + 1);
1515 for (; i
< 37; i
++) {
1516 wp_spr
[i
* 2] = Z_getspr("BAL1", i
- 32, 1, wp_sprd
+ i
* 2);
1517 wp_spr
[i
* 2 + 1] = Z_getspr("BAL1", i
- 32, 2, wp_sprd
+ i
* 2 + 1);
1519 for (; i
< 42; i
++) {
1520 wp_spr
[i
* 2] = Z_getspr("BAL7", i
- 37, 1, wp_sprd
+ i
* 2);
1521 wp_spr
[i
* 2 + 1] = Z_getspr("BAL7", i
- 37, 2, wp_sprd
+ i
* 2 + 1);
1523 for (; i
< 47; i
++) {
1524 wp_spr
[i
* 2] = Z_getspr("BAL2", i
- 42, 1, wp_sprd
+ i
* 2);
1525 wp_spr
[i
* 2 + 1] = Z_getspr("BAL2", i
- 42, 2, wp_sprd
+ i
* 2 + 1);
1527 for (; i
< 49; i
++) {
1528 wp_spr
[i
* 2] = Z_getspr("MANF", i
- 47, 1, wp_sprd
+ i
* 2);
1529 wp_spr
[i
* 2 + 1] = Z_getspr("MANF", i
- 47, 2, wp_sprd
+ i
* 2 + 1);
1532 static const char snm
[18][4] = {
1533 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1534 "STIM", "MEDI", "BPAK",
1535 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1537 static const char n4
[4][4] = {
1538 "SOUL", "SMRT", "SMGT", "SMBT"
1540 static const char n3
[2][4] = {
1543 for (i
= 0; i
< 18; i
++) {
1544 item_spr
[i
] = Z_getspr(snm
[i
], 0, 0, item_sprd
+ i
);
1546 for (; i
< 20; i
++) {
1547 item_spr
[i
] = Z_getspr("ARM1", i
- 18, 0, item_sprd
+ i
);
1548 item_spr
[i
+ 2] = Z_getspr("ARM2", i
- 18, 0, item_sprd
+ i
);
1551 for (; i
< 26; i
++) {
1552 item_spr
[i
] = Z_getspr("MEGA", i
- 22, 0, item_sprd
+ i
);
1554 for (; i
< 30; i
++) {
1555 item_spr
[i
] = Z_getspr("PINV", i
- 26, 0, item_sprd
+ i
);
1557 item_spr
[30] = Z_getspr("AQUA", 0, 0, item_sprd
+ 30);
1558 item_spr
[31] = Z_getspr("KEYR", 0, 0, item_sprd
+ 31);
1559 item_spr
[32] = Z_getspr("KEYG", 0, 0, item_sprd
+ 32);
1560 item_spr
[33] = Z_getspr("KEYB", 0, 0, item_sprd
+ 33);
1561 item_spr
[34] = Z_getspr("SUIT", 0, 0, item_sprd
+ 34);
1562 for (n
= 35, j
= 0; j
< 4; j
++) {
1563 for (i
= 0; i
< 4; i
++, n
++) {
1564 item_spr
[n
] = Z_getspr(n4
[j
], i
, 0, item_sprd
+ n
);
1567 for (j
= 0; j
< 2; j
++) {
1568 for (i
= 0; i
< 3; i
++, n
++) {
1569 item_spr
[n
] = Z_getspr(n3
[j
], i
, 0, item_sprd
+ n
);
1572 item_spr
[57] = Z_getspr("GUN2", 0, 0, item_sprd
+ 57);
1574 for (i
= 0; i
< 27; i
++) {
1575 plr_spr
[i
* 2] = Z_getspr("PLAY", i
, 1, plr_sprd
+ i
* 2);
1576 plr_msk
[i
* 2] = R_gl_get_special_spr("PLAY", i
, 1, &R_extract_mask_spr
);
1577 plr_spr
[i
* 2 + 1] = Z_getspr("PLAY", i
, 2, plr_sprd
+ i
* 2 + 1);
1578 plr_msk
[i
* 2 + 1] = R_gl_get_special_spr("PLAY", i
, 2, &R_extract_mask_spr
);
1580 strncpy(s
, "PWPx", 4);
1581 for (i
= 1; i
< 11; i
++) {
1582 s
[3] = (i
< 10 ? '0' : 'A' - 10) + i
;
1583 for (j
= 0; j
< 6; j
++) {
1584 plr_wpn
[i
][j
] = Z_getspr(s
, j
, 1, NULL
);
1588 static const char msn
[MN_TN
][4] = {
1589 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1590 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1592 static const int mms
[MN_TN
] = {
1593 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1594 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1596 mn_sgun
[0] = Z_getspr("PWP4", 0, 1, NULL
);
1597 mn_sgun
[1] = Z_getspr("PWP4", 1, 1, NULL
);
1598 for (j
= 0; j
< MN_TN
; j
++) {
1599 for (i
= 0; i
< mms
[j
]; i
++) {
1600 mn_spr
[j
][i
] = Z_getspr(msn
[j
], i
/ 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1601 if (j
== MN_MAN
- 1) {
1602 mn_man_msk
[i
] = R_gl_get_special_spr(msn
[j
], i
/ 2, (i
& 1) + 1, &R_extract_mask_spr
);
1605 if (j
== MN_BARREL
- 1) {
1606 for (i
= 4; i
< 14; i
++) {
1607 mn_spr
[j
][i
] = Z_getspr("BEXP", i
/ 2 - 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1611 for (i
= 0; i
< 8; i
++) {
1612 mn_fspr
[i
] = Z_getspr("FIRE", i
, 0, NULL
);
1614 pl_spr
[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL
);
1615 pl_msk
[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr
);
1616 pl_spr
[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL
);
1617 pl_msk
[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr
);
1619 static const char mnm
[22][8]={
1620 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1621 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1622 "STTMINUS", "STTPRCNT",
1623 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1624 "PLASA0", "BFUGA0", "GUN2A0"
1626 stone
= R_gl_loadimage("STONE");
1627 stone2
= R_gl_loadimage("STONE2");
1628 keys
[0] = R_gl_loadimage("KEYRA0");
1629 keys
[1] = R_gl_loadimage("KEYGA0");
1630 keys
[2] = R_gl_loadimage("KEYBA0");
1631 for (i
= 0; i
< 22; i
++) {
1632 sth
[i
] = R_gl_loadimage(mnm
[i
]);
1634 strcpy(s
, "STBF_*");
1635 for (i
= '!'; i
< 160; i
++) {
1637 bfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1639 for (i
= '!'; i
< 160; i
++) {
1640 sprintf(s
, "STCFN%03d", i
);
1641 sfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1643 strcpy(s
, "WINUM*");
1644 for (i
= '0'; i
<= '9'; i
++) {
1646 bfh
[i
- '!'] = R_gl_loadimage(s
);
1648 bfh
[':' - '!'] = R_gl_loadimage("WICOLON");
1650 msklh
[0] = R_gl_loadimage("M_SKULL1");
1651 msklh
[1] = R_gl_loadimage("M_SKULL2");
1652 mbarl
= R_gl_loadimage("M_THERML");
1653 mbarm
= R_gl_loadimage("M_THERMM");
1654 mbarr
= R_gl_loadimage("M_THERMR");
1655 mbaro
= R_gl_loadimage("M_THERMO");
1656 mslotl
= R_gl_loadimage("M_LSLEFT");
1657 mslotm
= R_gl_loadimage("M_LSCNTR");
1658 mslotr
= R_gl_loadimage("M_LSRGHT");
1660 for (i
= 1; i
< ANIT
; i
++) {
1661 for (j
= 0; j
< 5 && anm
[i
- 1][j
]; j
++) {
1662 anip
[i
][j
] = R_gl_loadimage(anm
[i
- 1][j
]);
1665 anip
[i
][j
] = (image
) {
1675 static void R_reload_textures (void);
1677 void R_set_videomode (int w
, int h
, int fullscreen
) {
1680 int was
= Y_videomode_setted();
1682 R_cache_free(root
, 0);
1685 int res
= Y_set_videomode_opengl(w
, h
, fullscreen
);
1688 ERR_failinit("Unable to set video mode\n");
1691 Y_get_videomode(&SCRW
, &SCRH
);
1692 root
= R_cache_new();
1695 R_reload_textures();
1699 void R_toggle_fullscreen (void) {
1700 R_cache_free(root
, 0);
1701 Y_set_fullscreen(!Y_get_fullscreen());
1702 fullscreen
= Y_get_fullscreen();
1703 Y_get_videomode(&SCRW
, &SCRH
);
1704 root
= R_cache_new();
1707 R_reload_textures();
1710 void R_init (void) {
1711 logo("R_init: intialize opengl render\n");
1713 R_set_videomode(SCRW
, SCRH
, fullscreen
);
1716 void R_done (void) {
1717 R_cache_free(root
, 1);
1718 Y_unset_videomode();
1722 void R_setgamma (int g
) {
1723 gamma
= g
< 0 ? 0 : (g
> 4 ? 4 : g
);
1726 int R_getgamma (void) {
1730 void R_get_name (int n
, char s
[8]) {
1731 assert(n
>= 0 && n
< 256);
1732 if (walp
[n
].res
== -1) {
1734 } else if (walp
[n
].res
== -2) {
1735 memcpy(s
, "_WATER_", 8);
1736 s
[7] = '0' + (intptr_t)walp
[n
].n
- 1;
1737 } else if (walani
[n
] > 0) {
1738 memcpy(s
, anm
[walani
[n
] - 1][0], 8);
1740 F_getresname(s
, walp
[n
].res
& 0x7FFF);
1744 static short getani (char n
[8]) {
1746 while (i
< ANIT
- 1 && strncasecmp(n
, anm
[i
][0], 8) != 0) {
1749 return i
< ANIT
- 1 ? i
+ 1 : 0;
1752 int R_get_special_id (int n
) {
1753 assert(n
>= 0 && n
<= 256);
1754 return walp
[n
].res
== -2 ? (intptr_t)walp
[n
].n
: -1;
1757 static void R_reload_textures (void) {
1760 for (i
= 0; i
< max_textures
; i
++) {
1762 if (walp
[i
].res
>= 0) {
1763 walp
[i
] = R_gl_getimage(walp
[i
].res
);
1767 horiz
= R_gl_getimage(horiz
.res
);
1771 void R_begin_load (void) {
1773 for (i
= 0; i
< 256; i
++) {
1774 if (walp
[i
].n
!= NULL
&& walp
[i
].res
>= 0 && walani
[i
] == 0) {
1775 R_gl_free_image(&walp
[i
]);
1777 memset(&walp
[i
], 0, sizeof(image
));
1782 memset(anic
, 0, sizeof(anic
));
1784 max_wall_height
= 0;
1788 void R_load (char s
[8], int f
) {
1789 assert(max_textures
< 256);
1791 walp
[max_textures
] = (image
) {
1799 } else if (strncasecmp(s
, "_WATER_", 7) == 0) {
1800 walp
[max_textures
] = (image
) {
1801 .n
= (void*)((intptr_t)s
[7] - '0' + 1),
1809 walp
[max_textures
] = R_gl_loadimage(s
);
1811 walp
[max_textures
].res
|= 0x8000;
1813 if (s
[0] == 'S' && s
[1] == 'W' && s
[4] == '_') {
1814 walswp
[max_textures
] = 0;
1816 walani
[max_textures
] = getani(s
);
1818 max_wall_width
= max(max_wall_width
, walp
[max_textures
].w
);
1819 max_wall_height
= max(max_wall_height
, walp
[max_textures
].h
);
1823 void R_end_load (void) {
1827 for (i
= 1; i
< 256 && j
< 256; i
++) {
1828 if (walswp
[i
] == 0) {
1831 g
= F_getresid(s
) | (walp
[i
].res
& 0x8000);
1833 while (k
< 256 && walp
[k
].res
!= g
) {
1840 walp
[k
] = R_gl_getimage(g
);
1841 walf
[k
] = g
& 0x8000 ? 1 : 0;
1849 void R_loadsky (int sky
) {
1853 R_gl_free_image(&horiz
);
1854 horiz
= R_gl_loadimage(s
);