91707ef5d32d2e7af2209a0a61d8c34d44672bb9
13 #include "sound.h" // snd_vol
14 #include "music.h" // mus_vol
22 #include "switch.h" // sw_secrets
25 # include <OpenGL/gl.h>
29 #include <stdlib.h> // malloc free abs
30 #include <assert.h> // assert
33 #define VGA_TRANSPARENT_COLOR 0
34 #define DEFAULT_SKY_COLOR 0x97
36 #define PLAYER_COLOR_OFFSET 7
42 typedef struct vgaimg
{
59 struct node
*left
, *right
;
65 typedef struct cache
{
71 typedef struct image
{
79 int SCRW
= 320; // public
80 int SCRH
= 200; // public
82 static int fullscreen
;
83 static SDL_Surface
*surf
;
84 static rgb playpal
[256];
85 static byte bright
[256];
86 static GLuint lastTexture
;
90 static image scrnh
[3]; // TITLEPIC INTERPIC ENDPIC
91 static image ltn
[2][2];
94 static image smk_spr
[SMSN
];
95 static image smk_fspr
[FLSN
];
98 static image fx_spr
[15];
99 static char fx_sprd
[15];
102 static image wp_spr
[49*2];
103 static char wp_sprd
[49*2];
106 static image item_spr
[58];
107 static char item_sprd
[58];
110 static image plr_spr
[27*2];
111 static image plr_msk
[27*2];
112 static char plr_sprd
[27*2];
113 static image plr_wpn
[11][6];
116 static image pl_spr
[2];
117 static image pl_msk
[2];
118 static image mn_spr
[MN_TN
][29*2];
119 static image mn_man_msk
[29*2];
120 static char mn_sprd
[MN_TN
][29*2];
121 static image mn_fspr
[8];
122 static image mn_sgun
[2];
125 static image sth
[22];
126 static image bfh
[160 - '!'];
127 static image sfh
[160 - '!'];
130 static image keys
[3];
136 static image msklh
[2];
146 static const char *anm
[ANIT
- 1][5] = {
147 {"WALL22_1", "WALL23_1", "WALL23_2", NULL
, NULL
},
148 {"WALL58_1", "WALL58_2", "WALL58_3", NULL
, NULL
},
149 {"W73A_1", "W73A_2", NULL
, NULL
, NULL
},
150 {"RP2_1", "RP2_2", "RP2_3", "RP2_4", NULL
}
152 static int max_wall_width
;
153 static int max_wall_height
;
154 static int max_textures
;
155 static image walp
[256];
156 static byte walani
[256];
157 static image anip
[ANIT
][5];
158 static byte anic
[ANIT
];
163 // https://blackpawn.com/texts/lightmaps/
164 static node
*R_node_alloc (node
*p
, int w
, int h
) {
170 node
*n
= R_node_alloc(p
->left
, w
, h
);
171 return n
? n
: R_node_alloc(p
->right
, w
, h
);
173 int pw
= p
->r
- p
->l
+ 1;
174 int ph
= p
->b
- p
->t
+ 1;
175 if (p
->leaf
|| pw
< w
|| ph
< h
) {
177 } else if (pw
== w
&& ph
== h
) {
181 p
->left
= malloc(sizeof(node
));
182 p
->right
= malloc(sizeof(node
));
183 if (pw
- w
> ph
- h
) {
214 return R_node_alloc(p
->left
, w
, h
);
219 static int R_node_have_leaf (node
*n
) {
220 return n
&& (n
->leaf
|| R_node_have_leaf(n
->left
) || R_node_have_leaf(n
->right
));
223 static void R_node_free_recursive (node
*n
) {
225 R_node_free_recursive(n
->left
);
226 R_node_free_recursive(n
->right
);
231 static void R_node_free (node
*n
) {
233 //logo("free node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
235 assert(n
->left
== NULL
);
236 assert(n
->right
== NULL
);
241 assert(p
->leaf
== 0);
244 if (R_node_have_leaf(p
) == 0) {
245 R_node_free_recursive(p
->left
);
247 R_node_free_recursive(p
->right
);
257 static void R_cache_get_max_texture_size (int *w
, int *h
) {
259 glGetIntegerv(GL_MAX_TEXTURE_SIZE
, &size
);
260 size
= min(max(size
, 0), 512); // more can be buggy on older hardware
265 static void R_gl_bind_texture (GLuint id
) {
266 if (id
!= lastTexture
) {
267 glBindTexture(GL_TEXTURE_2D
, id
);
271 static cache
*R_cache_new (void) {
275 R_cache_get_max_texture_size(&w
, &h
);
277 glGenTextures(1, &id
);
279 R_gl_bind_texture(id
);
280 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
281 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
282 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, w
, h
, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
283 c
= malloc(sizeof(cache
));
291 glDeleteTextures(1, &id
);
295 //logo("new cache %p\n", c);
299 static void R_cache_free (cache
*root
, int freetexture
) {
304 R_node_free_recursive(c
->root
.left
);
305 R_node_free_recursive(c
->root
.right
);
306 if (freetexture
&& c
->id
!= 0) {
307 glDeleteTextures(1, &c
->id
);
314 static node
*R_cache_alloc (cache
*root
, int w
, int h
) {
316 assert(w
> 0 && h
> 0);
321 R_cache_get_max_texture_size(&maxw
, &maxh
);
322 if (w
<= maxw
&& h
<= maxh
) {
324 n
= R_node_alloc(&c
->root
, w
, h
);
336 n
= R_node_alloc(&c
->root
, w
, h
);
345 //logo("new node %p {%i:%i:%i:%i}\n", n, n->l, n->t, n->r, n->b);
347 logo("new node failed\n");
352 static void R_cache_update (node
*n
, const void *data
, int x
, int y
, int w
, int h
) {
359 assert(n
->l
+ x
+ w
- 1 <= n
->r
);
360 assert(n
->t
+ y
+ h
- 1 <= n
->b
);
361 R_gl_bind_texture(n
->base
->id
);
362 glTexSubImage2D(GL_TEXTURE_2D
, 0, n
->l
+ x
, n
->t
+ y
, w
, h
, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
365 /* Generic helpers */
367 static void R_init_playpal (void) {
369 byte
*vgapal
= M_lock(F_getresid("PLAYPAL"));
370 for (i
= 0; i
< 256; i
++) {
372 .r
= vgapal
[i
* 3 + 0] * 255 / 63,
373 .g
= vgapal
[i
* 3 + 1] * 255 / 63,
374 .b
= vgapal
[i
* 3 + 2] * 255 / 63,
376 bright
[i
] = ((int)vgapal
[i
* 3 + 0] + vgapal
[i
* 3 + 1] + vgapal
[i
* 3 + 2]) * 8 / (63 * 3);
381 static vgaimg
*R_getvga (int id
) {
382 int loaded
= M_was_locked(id
);
383 vgaimg
*v
= M_lock(id
);
384 if (v
!= NULL
&& !loaded
) {
385 v
->w
= short2host(v
->w
);
386 v
->h
= short2host(v
->h
);
387 v
->x
= short2host(v
->x
);
388 v
->y
= short2host(v
->y
);
393 static rgba
*R_extract_flame_spr (vgaimg
*v
) {
394 static const byte flametab
[16] = {
395 0xBC, 0xBA, 0xB8, 0xB6, 0xB4, 0xB2, 0xB0, 0xD5,
396 0xD6, 0xD7, 0xA1, 0xA0, 0xE3, 0xE2, 0xE1, 0xE0
399 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
401 for (j
= 0; j
< v
->h
; j
++) {
402 for (i
= 0; i
< v
->w
; i
++) {
403 int k
= j
* v
->w
+ i
;
404 byte c
= v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
];
406 .r
= playpal
[flametab
[c
]].r
,
407 .g
= playpal
[flametab
[c
]].g
,
408 .b
= playpal
[flametab
[c
]].b
,
409 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
417 static rgba
*R_extract_smoke_spr (vgaimg
*v
) {
419 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
421 for (j
= 0; j
< v
->h
; j
++) {
422 for (i
= 0; i
< v
->w
; i
++) {
423 int k
= j
* v
->w
+ i
;
424 byte c
= ((v
->data
[k
] + bright
[DEFAULT_SKY_COLOR
]) + 0x60) ^ 0x0F;
425 byte a
= 0xFF - ((int)playpal
[c
].r
+ playpal
[c
].g
+ playpal
[c
].b
) / 3;
430 .a
= v
->data
[k
] == VGA_TRANSPARENT_COLOR
? 0x00 : a
,
438 static rgba
*R_extract_mask_spr (vgaimg
*v
) {
440 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
442 for (j
= 0; j
< v
->h
; j
++) {
443 for (i
= 0; i
< v
->w
; i
++) {
444 int k
= j
* v
->w
+ i
;
446 if (c
>= 0x70 && c
<= 0x7F) {
447 byte mask
= c
- 0x70;
448 mask
= 0xFF - ((mask
<< 4) | mask
);
469 static rgba
*R_extract_rgba_spr (vgaimg
*v
) {
471 rgba
*s
= malloc(v
->w
* v
->h
* sizeof(rgba
));
473 for (j
= 0; j
< v
->h
; j
++) {
474 for (i
= 0; i
< v
->w
; i
++) {
475 int k
= j
* v
->w
+ i
;
481 .a
= c
== VGA_TRANSPARENT_COLOR
? 0x00 : 0xFF,
491 static image
R_gl_create_image (const rgba
*buf
, int w
, int h
) {
492 node
*n
= R_cache_alloc(root
, w
, h
);
494 R_cache_update(n
, buf
, 0, 0, w
, h
);
504 static image
R_gl_get_special_image (int id
, rgba
*(*fn
)(vgaimg
*)) {
506 vgaimg
*v
= R_getvga(id
);
508 rgba
*buf
= (*fn
)(v
);
509 img
= R_gl_create_image(buf
, v
->w
, v
->h
);
523 static image
R_gl_getimage (int id
) {
524 return R_gl_get_special_image(id
, &R_extract_rgba_spr
);
527 static image
R_gl_loadimage (const char name
[8]) {
528 return R_gl_getimage(F_getresid(name
));
531 static image
R_gl_get_special_spr (const char n
[4], int s
, int d
, rgba
*(*fn
)(vgaimg
*)) {
532 return R_gl_get_special_image(F_getsprid(n
, s
, d
), fn
);
535 static void R_gl_free_image (image
*img
) {
536 if (img
->n
!= NULL
&& img
->res
>= 0) {
543 static void R_gl_draw_quad (int x
, int y
, int w
, int h
) {
545 glVertex2i(x
+ w
, y
);
547 glVertex2i(x
, y
+ h
);
548 glVertex2i(x
+ w
, y
+ h
);
552 static void R_gl_draw_textured (image
*img
, int x
, int y
, int w
, int h
, int flip
) {
554 GLfloat nw
= img
->n
->base
->root
.r
+ 1;
555 GLfloat nh
= img
->n
->base
->root
.b
+ 1;
556 GLfloat ax
= (flip
? img
->n
->l
: img
->n
->r
+ 1) / nw
;
557 GLfloat bx
= (flip
? img
->n
->r
+ 1 : img
->n
->l
) / nh
;
558 GLfloat ay
= (img
->n
->t
) / nw
;
559 GLfloat by
= (img
->n
->b
+ 1) / nh
;
560 R_gl_bind_texture(img
->n
->base
->id
);
561 glEnable(GL_TEXTURE_2D
);
563 glTexCoord2f(ax
, ay
); glVertex2i(x
+ w
, y
);
564 glTexCoord2f(bx
, ay
); glVertex2i(x
, y
);
565 glTexCoord2f(bx
, by
); glVertex2i(x
, y
+ h
);
566 glTexCoord2f(ax
, by
); glVertex2i(x
+ w
, y
+ h
);
569 glColor3ub(255, 0, 0);
571 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
572 glDisable(GL_TEXTURE_2D
);
573 R_gl_draw_quad(x
, y
, w
, h
);
577 /* fit image into rectangle without applying offset and transparency */
578 static void R_gl_draw_image_ext (image
*img
, int x
, int y
, int w
, int h
) {
580 glColor3ub(255, 255, 255);
581 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
582 R_gl_draw_textured(img
, x
, y
, w
, h
, 0);
585 /* draw sprite with offset and coloring */
586 static void R_gl_draw_image_color (image
*img
, int x
, int y
, int flip
) {
587 int xx
= flip
? x
- img
->w
+ img
->x
: x
- img
->x
;
589 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
590 R_gl_draw_textured(img
, xx
, y
- img
->y
, img
->w
, img
->h
, flip
);
593 /* draw sprite with offset */
594 static void R_gl_draw_image (image
*img
, int x
, int y
, int flip
) {
595 glColor3ub(255, 255, 255);
596 R_gl_draw_image_color(img
, x
, y
, flip
);
599 static void R_gl_set_color (byte c
) {
600 glColor3ub(playpal
[c
].r
, playpal
[c
].g
, playpal
[c
].b
);
603 static void R_gl_setclip (int x
, int y
, int w
, int h
) {
604 glScissor(x
, SCRH
- h
- y
, w
, h
);
607 static void R_gl_setmatrix (void) {
608 glScissor(0, 0, SCRW
, SCRH
);
609 glViewport(0, 0, SCRW
, SCRH
);
610 glMatrixMode(GL_PROJECTION
);
612 glOrtho(0, SCRW
, SCRH
, 0, 0, 1);
613 glMatrixMode(GL_MODELVIEW
);
619 static image
Z_getspr (const char n
[4], int s
, int d
, char *dir
) {
620 int h
= F_getsprid(n
, s
, d
);
622 *dir
= (h
& 0x8000) ? 1 : 0;
624 return R_gl_getimage(h
);
627 static void Z_putch_generic (image img
[], int off
, int ch
) {
629 if (ch
> 32 && ch
< 160) {
633 R_gl_draw_image(p
, prx
, pry
, 0);
640 static void Z_printf_generic (image img
[], int off
, const char *fmt
, va_list ap
) {
643 vsprintf(buf
, fmt
, ap
);
644 for (i
= 0; buf
[i
]; ++i
) {
652 Z_putch_generic(img
, off
, (byte
)buf
[i
]);
657 static void Z_gotoxy (int x
, int y
) {
662 static void Z_printbf (const char *fmt
, ...) {
665 Z_printf_generic(bfh
, 12, fmt
, a
);
669 static void Z_printsf (const char *fmt
, ...) {
672 Z_printf_generic(sfh
, 7, fmt
, a
);
676 static void Z_printhf (const char *fmt
, ...) {
681 vsprintf(buf
, fmt
, a
);
683 for (i
= 0; buf
[i
]; ++i
) {
714 R_gl_draw_image(&sth
[c
], prx
, pry
, 0);
722 static image
*PL_getspr (int s
, int d
, int msk
) {
723 int i
= (s
- 'A') * 2 + d
;
724 return msk
? &plr_msk
[i
] : &plr_spr
[i
];
727 static void GM_draw (void) {
728 enum {MENU
, MSG
}; // copypasted from menu.c!
730 CANCEL
, NEWGAME
, LOADGAME
, SAVEGAME
, OPTIONS
, QUITGAME
, QUIT
, ENDGAME
, ENDGM
,
731 PLR1
, PLR2
, COOP
, DM
, VOLUME
, GAMMA
, LOAD
, SAVE
, PLCOLOR
, PLCEND
, MUSIC
, INTERP
,
732 SVOLM
, SVOLP
, MVOLM
, MVOLP
, GAMMAM
, GAMMAP
, PL1CM
, PL1CP
, PL2CM
, PL2CP
733 }; // copypasted from menu.c!
734 int i
, j
, k
, x
, y
, cx
, cy
;
740 if (mnu
->type
== MENU
) {
741 y
= cy
- (mnu
->n
* 16 - 20) / 2;
742 Z_gotoxy(cx
- mnu
->x
, y
- 10); Z_printbf("%s", mnu
->ttl
);
743 for (i
= 0; i
< mnu
->n
; i
++) {
744 if (mnu
->t
[i
] == LOAD
|| mnu
->t
[i
] == SAVE
) {
746 R_gl_draw_image(&mslotl
, cx
- mnu
->x
, j
, 0);
747 for (k
= 8; k
< 184; k
+= 8) {
748 R_gl_draw_image(&mslotm
, cx
- mnu
->x
+ k
, j
, 0);
750 R_gl_draw_image(&mslotr
, cx
- mnu
->x
+ 184, j
, 0);
751 Z_gotoxy(cx
- mnu
->x
+ 4, j
- 8);
752 if (input
&& i
== save_mnu
.cur
) {
753 Z_printsf("%s_", ibuf
);
755 Z_printsf("%s", savname
[i
]);
758 x
= mnu
->t
[i
] >= SVOLM
? (mnu
->t
[i
] >= PL1CM
? 50 : 152) : 0;
759 Z_gotoxy(cx
- mnu
->x
+ x
, y
+ i
* 16 + 20);
760 Z_printbf("%s", mnu
->m
[i
]);
763 Z_printbf(" '%s'", g_music
);
766 Z_printbf("%s", fullscreen
? "ON" : "OFF");
772 img
= PL_getspr(*panimp
, 0, 0);
773 R_gl_draw_image(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
774 img
= PL_getspr(*panimp
, 0, 1);
775 R_gl_set_color(pcolortab
[(mnu
->t
[i
] == PL1CM
) ? p1color
: p2color
] + PLAYER_COLOR_OFFSET
);
776 R_gl_draw_image_color(img
, cx
- mnu
->x
+ (mnu
->t
[i
] == PL1CM
? 15 : 35), y
+ i
* 16 + 20 + 14, 0);
785 R_gl_draw_image(&mbarl
, cx
- mnu
->x
, j
, 0);
786 for (k
= 8; k
< 144; k
+= 8) {
787 R_gl_draw_image(&mbarm
, cx
- mnu
->x
+ k
, j
, 0);
789 R_gl_draw_image(&mbarr
, cx
- mnu
->x
+ 144, j
, 0);
804 R_gl_draw_image(&mbaro
, cx
- mnu
->x
+ 8 + k
, j
, 0);
809 R_gl_draw_image(&msklh
[(gm_tm
/ 6) & 1], cx
- mnu
->x
- 25, y
+ mnu
->cur
* 16 + 20 - 8, 0);
810 } else if (mnu
->type
== MSG
) {
811 Z_gotoxy(cx
- strlen(mnu
->ttl
) * 7 / 2, cy
- 10); Z_printsf(mnu
->ttl
);
812 Z_gotoxy(cx
- 24, SCRH
/ 2); Z_printsf("(Y/N)");
814 ERR_fatal("Unknown menu type %i\n", mnu
->type
);
821 static void R_draw_fld (byte
*fld
, int minx
, int miny
, int maxx
, int maxy
, int fg
) {
823 assert(minx
>= 0 && minx
<= FLDW
);
824 assert(miny
>= 0 && miny
<= FLDH
);
825 assert(maxx
>= 0 && maxx
<= FLDW
);
826 assert(maxy
>= 0 && maxy
<= FLDH
);
827 for (j
= miny
; j
< maxy
; j
++) {
828 for (i
= minx
; i
< maxx
; i
++) {
829 byte id
= fld
[j
* FLDW
+ i
];
831 if (walp
[id
].res
< 0) {
833 switch (R_get_special_id(id
)) {
835 glColor4ub(0, 0, 255, 127);
838 glColor4ub(0, 127, 0, 127);
841 glColor4ub(127, 0, 0, 127);
844 glColor4ub(0, 0, 0, 127);
848 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
849 glDisable(GL_TEXTURE_2D
);
850 R_gl_draw_quad(i
* CELW
, j
* CELW
, CELW
, CELH
);
853 R_gl_draw_image(&walp
[id
], i
* CELW
, j
* CELH
, 0);
860 static void R_draw_dots (void) {
863 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
864 glDisable(GL_TEXTURE_2D
);
866 for (i
= 0; i
< MAXDOT
; i
++) {
868 R_gl_set_color(dot
[i
].c
);
869 glVertex2i(dot
[i
].o
.x
, dot
[i
].o
.y
+ 1);
875 static void R_draw_items (void) {
877 for (i
= 0; i
< MAXITEM
; ++i
) {
879 if (it
[i
].t
&& it
[i
].s
>= 0) {
880 switch (it
[i
].t
& 0x7FFF) {
882 s
= it
[i
].s
/ 9 + 18;
885 s
= it
[i
].s
/ 9 + 20;
888 s
= it
[i
].s
/ 2 + 22;
891 s
= it
[i
].s
/ 2 + 26;
897 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_SUPER
) * 4 + 35;
899 case I_GOR1
: case I_FCAN
:
900 s
= it
[i
].s
/ 2 + (it
[i
].t
- I_GOR1
) * 3 + 51;
911 s
= (it
[i
].t
& 0x7FFF) - I_KEYR
+ 31;
917 s
= (it
[i
].t
& 0x7FFF) - 1;
921 R_gl_draw_image(&item_spr
[s
], it
[i
].o
.x
, it
[i
].o
.y
, item_sprd
[s
]);
926 static int standspr (player_t
*p
) {
929 } else if (p
->f
& PLF_DOWN
) {
936 static int wpnspr (player_t
*p
) {
939 } else if(p
->f
& PLF_DOWN
) {
946 static void R_draw_player (player_t
*p
) {
947 enum {STAND
, GO
, DIE
, SLOP
, DEAD
, MESS
, OUT
, FALL
}; // copypasted from player.c!
948 static const int wytab
[] = {-1, -2, -1, 0};
955 if (p
->f
& PLF_FIRE
) {
958 } else if (p
->pain
) {
981 s
= plr_goanim
[p
->s
/ 8];
982 w
= (p
->f
& PLF_FIRE
) ? 'B' : 'A';
984 wy
= 1 + wytab
[s
- 'A'];
988 s
= plr_dieanim
[p
->s
];
991 s
= plr_slopanim
[p
->s
];
1001 R_gl_draw_image(&plr_wpn
[(int)p
->wpn
][w
-'A'], p
->o
.x
+ wx
, p
->o
.y
+ wy
, p
->d
);
1004 R_gl_draw_image(&plr_spr
[(s
- 'A') * 2 + p
->d
], p
->o
.x
, p
->o
.y
, plr_sprd
[(s
- 'A') * 2 + p
->d
]);
1005 R_gl_set_color(p
->color
+ PLAYER_COLOR_OFFSET
);
1006 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
]);
1010 static void R_draw_monsters (void) {
1011 enum {SLEEP
, GO
, RUN
, CLIMB
, DIE
, DEAD
, ATTACK
, SHOOT
, PAIN
, WAIT
, REVIVE
, RUNOUT
}; // copypasted from monster.c!
1013 for (i
= 0; i
< MAXMN
; i
++) {
1014 if (mn
[i
].t
!= MN_NONE
) {
1017 if (mn
[i
].t
< MN__LAST
) {
1018 if ((mn
[i
].t
!= MN_SOUL
&& mn
[i
].t
!= MN_PAIN
) || mn
[i
].st
!= DEAD
) {
1019 int ap
= mn
[i
].ap
[mn
[i
].ac
];
1020 int d
= (ap
- 'A') * 2 + mn
[i
].d
;
1021 int dir
= mn_sprd
[mn
[i
].t
- 1][d
];
1022 if (mn
[i
].t
== MN_MAN
&& (ap
== 'E' || ap
== 'F')) {
1023 R_gl_draw_image(&mn_sgun
[ap
- 'E'], x
, y
, mn
[i
].d
);
1025 R_gl_draw_image(&mn_spr
[mn
[i
].t
- 1][d
], x
, y
, dir
);
1026 if (mn
[i
].t
== MN_MAN
) {
1027 R_gl_set_color(MANCOLOR
+ PLAYER_COLOR_OFFSET
);
1028 R_gl_draw_image_color(&mn_man_msk
[d
], x
, y
, dir
);
1031 if (mn
[i
].t
== MN_VILE
&& mn
[i
].st
== SHOOT
) {
1032 R_gl_draw_image(&mn_fspr
[mn
[i
].ac
/ 3], mn
[i
].tx
, mn
[i
].ty
, 0);
1034 } else if (mn
[i
].t
== MN_PL_DEAD
|| mn
[i
].t
== MN_PL_MESS
) {
1035 int type
= mn
[i
].t
- MN_PL_DEAD
;
1036 R_gl_draw_image(&pl_spr
[type
], x
, y
, 0);
1037 R_gl_set_color(mn
[i
].d
);
1038 R_gl_draw_image_color(&pl_msk
[type
], x
, y
, 0);
1044 static void R_draw_weapons (void) {
1045 enum {NONE
, ROCKET
, PLASMA
, APLASMA
, BALL1
, BALL2
, BALL7
, BFGBALL
, BFGHIT
, MANF
, REVF
, FIRE
}; // copypasted from weapons.c!
1047 for (i
= 0; i
< MAXWPN
; ++i
) {
1055 d
= wp
[i
].o
.xv
> 0 ? 1 : 0;
1056 x
= abs(wp
[i
].o
.xv
);
1069 s
= (d
- 2) / 2 + 1;
1103 d
= wp
[i
].o
.xv
>= 0 ? 1 : 0;
1107 d
= wp
[i
].o
.xv
>=0 ? 1 : 0;
1119 s
= wp
[i
].s
/ 2 + 26;
1123 R_gl_draw_image(&wp_spr
[s
* 2 + d
], wp
[i
].o
.x
, wp
[i
].o
.y
, wp_sprd
[s
* 2 + d
]);
1128 static void R_draw_smoke (void) {
1130 for (i
= 0; i
< MAXSMOK
; ++i
) {
1135 if (s
>= (SMSN
- 1) * 3) {
1138 s
= SMSN
- 1 - s
/ 3;
1140 R_gl_draw_image(&smk_spr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1144 if (s
>= FLSN
- 1) {
1149 R_gl_draw_image(&smk_fspr
[s
], sm
[i
].x
>> 8, (sm
[i
].y
>> 8) + 1, 0);
1156 static void R_draw_effects (void) {
1157 enum {NONE
, TFOG
, IFOG
, BUBL
}; // copypasted from fx.c
1159 for (i
= 0; i
< MAXFX
; ++i
) {
1163 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1166 s
= fx
[i
].s
/ 2 + 10;
1167 R_gl_draw_image(&fx_spr
[s
], fx
[i
].x
, fx
[i
].y
, fx_sprd
[s
]);
1170 glDisable(GL_BLEND
);
1171 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1172 glDisable(GL_TEXTURE_2D
);
1174 R_gl_set_color(0xC0 + fx
[i
].s
);
1175 glVertex2i(fx
[i
].x
>> 8, (fx
[i
].y
>> 8) + 1);
1182 static int get_pu_st (int t
) {
1183 if (t
>= PL_FLASH
) {
1185 } else if((t
/ 9) & 1) {
1192 static void R_draw_view (int x
, int y
, int w
, int h
, int camx
, int camy
) {
1194 R_gl_setclip(x
, y
, w
, h
);
1195 glTranslatef(x
, y
, 0);
1196 if (w_horiz
&& horiz
.n
!= NULL
) {
1197 R_gl_draw_image_ext(&horiz
, 0, 0, w
, h
);
1198 if (sky_type
== 2 && lt_time
< 0) {
1199 image
*tanderbolt
= <n
[lt_type
][lt_time
< -5 ? 0 : 1];
1201 R_gl_draw_image(tanderbolt
, 0, lt_ypos
, 0);
1203 R_gl_draw_image(tanderbolt
, w
- 1, lt_ypos
, 1);
1207 glDisable(GL_BLEND
);
1208 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1209 glDisable(GL_TEXTURE_2D
);
1210 R_gl_set_color(DEFAULT_SKY_COLOR
);
1211 R_gl_draw_quad(0, 0, w
, h
);
1213 int maxx
= min((camx
+ w
) / CELW
+ 1, FLDW
);
1214 int maxy
= min((camy
+ h
) / CELH
+ 1, FLDH
);
1215 int minx
= max((camx
- max_wall_width
) / CELW
, 0);
1216 int miny
= max((camy
- max_wall_height
) / CELH
, 0);
1217 glTranslatef(-camx
, -camy
, 0);
1218 R_draw_fld((byte
*)fldb
, minx
, miny
, maxx
, maxy
, 0);
1221 R_draw_player(&pl1
);
1223 R_draw_player(&pl2
);
1229 R_draw_fld((byte
*)fldf
, minx
, miny
, maxx
, maxy
, 1);
1230 glTranslatef(camx
, camy
, 0);
1231 if (sky_type
== 2 && (lt_time
== -4 || lt_time
== -2)) {
1232 glColor4ub(255, 255, 255, 255);
1234 glBlendFunc(GL_DST_COLOR
, GL_SRC_COLOR
);
1235 glDisable(GL_TEXTURE_2D
);
1236 R_gl_draw_quad(0, 0, w
, h
);
1241 static void R_draw_player_view (player_t
*p
, int x
, int y
, int w
, int h
) {
1242 p
->looky
= min(max(p
->looky
, -SCRH
/ 4), SCRH
/ 4); // TODO remove writeback
1245 int cx
= min(max(p
->o
.x
, cw
/ 2), FLDW
* CELW
- cw
/ 2);
1246 int cy
= min(max(p
->o
.y
- 12 + p
->looky
, h
/ 2), FLDH
* CELH
- h
/ 2);
1247 int camx
= max(cx
- cw
/ 2, 0);
1248 int camy
= max(cy
- h
/ 2, 0);
1250 R_draw_view(x
, y
+ 1, cw
, h
- 2, camx
, camy
);
1251 glTranslatef(x
, y
, 0);
1253 if (get_pu_st(p
->invl
)) {
1255 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
);
1256 glDisable(GL_TEXTURE_2D
);
1257 glColor4ub(191, 191, 191, 255);
1258 R_gl_draw_quad(0, 0, cw
, h
);
1261 if (p
->suit
&& get_pu_st(p
->suit
)) {
1263 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1264 glDisable(GL_TEXTURE_2D
);
1265 glColor4ub(0, 255, 0, 192);
1266 R_gl_draw_quad(0, 0, cw
, h
);
1268 int f
= min(max(p
->pain
* 3, 0), 255);
1271 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1272 glDisable(GL_TEXTURE_2D
);
1273 glColor4ub(255, 0, 0, f
);
1274 R_gl_draw_quad(0, 0, cw
, h
);
1277 R_gl_setclip(x
, y
, w
, h
);
1278 glTranslatef(-x
+ cw
, 0, 0);
1279 R_gl_draw_image(&stone
, 0, 0, 0);
1282 R_gl_draw_image(&stone2
, 0, i
, 0);
1285 if (p
->drawst
& PL_DRAWAIR
) {
1286 if (p
->air
< PL_AIR
) {
1287 int a
= min(max(p
->air
, 0), MAXAIR
) * 100 / MAXAIR
;
1288 glDisable(GL_BLEND
);
1289 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1290 glDisable(GL_TEXTURE_2D
);
1291 R_gl_set_color(0xC8);
1292 R_gl_draw_quad(10, 49, a
, 2);
1295 if (p
->drawst
& PL_DRAWLIFE
) {
1297 Z_printhf("%3d%%", p
->life
);
1299 if (p
->drawst
& PL_DRAWARMOR
) {
1300 Z_gotoxy(10, 7 + 19);
1301 Z_printhf("%3d%%", p
->armor
);
1303 if (p
->drawst
& PL_DRAWWPN
) {
1330 R_gl_draw_image(&sth
[12 + p
->wpn
], st
- 88, 58 + 19, 0);
1334 Z_gotoxy(st
- 10 - 5 * 14, 58 + 2);
1335 Z_printhf("%5d", i
);
1338 if (p
->drawst
& PL_DRAWFRAG
&& g_dm
) {
1339 Z_gotoxy(st
- 5 - 5 * 14, 77 + 5);
1340 Z_printhf("%5d", p
->frag
);
1342 if (p
->drawst
& PL_DRAWKEYS
) {
1344 for (k
= p
->keys
>> 4, n
= 0, x
= st
- 75; n
< 3; n
++, k
>>= 1, x
+= 9) {
1346 R_gl_draw_image(&keys
[n
], x
, 91, 0);
1350 if (p
->drawst
& PL_DRAWLIVES
&& !_2pl
) {
1351 Z_gotoxy(st
- 35, 17);
1352 Z_printhf("%d", p
->lives
);
1359 static void pl_info (player_t
*p
, int x
, int y
) {
1360 dword t
= p
->kills
* 10920 / g_time
;
1361 Z_gotoxy(x
+ 25, y
); Z_printbf("KILLS");
1362 Z_gotoxy(x
+ 25, y
+ 15); Z_printbf("KPM");
1363 Z_gotoxy(x
+ 25, y
+ 30); Z_printbf("SECRETS %u / %u", p
->secrets
, sw_secrets
);
1364 Z_gotoxy(x
+ 255, y
); Z_printbf("%u", p
->kills
);
1365 Z_gotoxy(x
+ 255, y
+ 15); Z_printbf("%u.%u", t
/ 10, t
% 10);
1368 static void R_draw_intermission (void) {
1371 Z_gotoxy(cx
- 14*12/2, 20);
1372 Z_printbf("LEVEL COMPLETE");
1373 Z_calc_time(g_time
, &hr
, &mn
, &sc
);
1374 Z_gotoxy(cx
- 12*12/2, 40);
1375 Z_printbf("TIME %u:%02u:%02u", hr
, mn
, sc
);
1378 Z_gotoxy(cx
- 10*12/2, h
);
1379 Z_printbf("PLAYER ONE");
1382 pl_info(&pl1
, cx
- 160, h
);
1384 h
+= 30 + SCRH
/ 10;
1385 Z_gotoxy(cx
- 10*12/2, h
);
1386 Z_printbf("PLAYER TWO");
1388 pl_info(&pl2
, cx
- 160, h
);
1392 static void W_act (void) {
1394 if (g_time
% 3 == 0) {
1395 for (i
= 1; i
< max_textures
; i
++) {
1399 if (anip
[a
][anic
[a
]].res
== -1) {
1402 walp
[i
] = anip
[a
][anic
[a
]];
1408 void R_draw (void) {
1410 glClearColor(0, 0, 0, 1);
1411 glClear(GL_COLOR_BUFFER_BIT
);
1412 glEnable(GL_SCISSOR_TEST
);
1423 R_gl_draw_image_ext(&scrnh
[0], 0, 0, SCRW
, SCRH
);
1426 R_gl_draw_image_ext(&scrnh
[1], 0, 0, SCRW
, SCRH
);
1427 R_draw_intermission();
1430 R_gl_draw_image_ext(&scrnh
[2], 0, 0, SCRW
, SCRH
);
1434 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
/ 2);
1435 R_draw_player_view(&pl2
, 0, SCRH
/ 2, SCRW
, SCRH
/ 2);
1437 R_draw_player_view(&pl1
, 0, 0, SCRW
, SCRH
);
1439 R_gl_setclip(0, 0, SCRW
, SCRH
);
1443 SDL_GL_SwapBuffers();
1446 void R_alloc (void) {
1449 logo("R_alloc: load graphics\n");
1451 scrnh
[0] = R_gl_loadimage("TITLEPIC");
1453 scrnh
[1] = R_gl_loadimage("INTERPIC");
1454 scrnh
[2] = R_gl_loadimage("ENDPIC");
1455 for (i
= 0; i
< 2; i
++) {
1456 sprintf(s
, "LTN%c", '1' + i
);
1457 for (j
= 0; j
< 2; j
++) {
1458 ltn
[i
][j
] = Z_getspr(s
, j
, 0, NULL
);
1462 for (i
= 0; i
< SMSN
; i
++) {
1463 smk_spr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_smoke_spr
);
1465 for (i
= 0; i
< FLSN
; i
++) {
1466 smk_fspr
[i
] = R_gl_get_special_spr("SMOK", i
, 0, &R_extract_flame_spr
);
1469 for (i
= 0; i
< 10; i
++) {
1470 fx_spr
[i
] = Z_getspr("TFOG", i
, 0, fx_sprd
+ i
);
1472 for (; i
< 15; i
++) {
1473 fx_spr
[i
] = Z_getspr("IFOG", i
- 10, 0, fx_sprd
+ i
);
1476 for (i
= 0; i
< 4; i
++) {
1477 wp_spr
[i
* 2] = Z_getspr("MISL", i
, 1, wp_sprd
+ i
* 2);
1478 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
, 2, wp_sprd
+ i
* 2 + 1);
1480 for (; i
< 6; i
++) {
1481 wp_spr
[i
* 2] = Z_getspr("PLSS", i
- 4, 1, wp_sprd
+ i
* 2);
1482 wp_spr
[i
* 2 + 1] = Z_getspr("PLSS", i
- 4, 2, wp_sprd
+ i
* 2 + 1);
1484 for (; i
< 11; i
++) {
1485 wp_spr
[i
* 2] = Z_getspr("PLSE", i
- 6, 1, wp_sprd
+ i
* 2);
1486 wp_spr
[i
* 2 + 1] = Z_getspr("PLSE", i
- 6, 2, wp_sprd
+ i
* 2 + 1);
1488 for (; i
< 13; i
++) {
1489 wp_spr
[i
* 2] = Z_getspr("APLS", i
- 11, 1, wp_sprd
+ i
* 2);
1490 wp_spr
[i
* 2 + 1] = Z_getspr("APLS", i
- 11, 2, wp_sprd
+ i
* 2 + 1);
1492 for (; i
< 18; i
++) {
1493 wp_spr
[i
* 2] = Z_getspr("APBX", i
- 13, 1, wp_sprd
+ i
* 2);
1494 wp_spr
[i
* 2 + 1] = Z_getspr("APBX", i
- 13, 2, wp_sprd
+ i
* 2 + 1);
1496 for(; i
< 20; i
++) {
1497 wp_spr
[i
* 2] = Z_getspr("BFS1", i
- 18, 1, wp_sprd
+ i
* 2);
1498 wp_spr
[i
* 2 + 1] = Z_getspr("BFS1", i
- 18, 2, wp_sprd
+ i
* 2 + 1);
1500 for (; i
< 26; i
++) {
1501 wp_spr
[i
* 2] = Z_getspr("BFE1", i
- 20, 1, wp_sprd
+ i
* 2);
1502 wp_spr
[i
* 2 + 1] = Z_getspr("BFE1", i
- 20, 2, wp_sprd
+ i
* 2 + 1);
1504 for (; i
< 30; i
++) {
1505 wp_spr
[i
* 2] = Z_getspr("BFE2", i
- 26, 1, wp_sprd
+ i
* 2);
1506 wp_spr
[i
* 2 + 1] = Z_getspr("BFE2", i
- 26, 2, wp_sprd
+ i
* 2 + 1);
1508 for (; i
< 32; i
++) {
1509 wp_spr
[i
* 2] = Z_getspr("MISL", i
- 30 + 4, 1, wp_sprd
+ i
* 2);
1510 wp_spr
[i
* 2 + 1] = Z_getspr("MISL", i
- 30 + 4, 2, wp_sprd
+ i
* 2 + 1);
1512 for (; i
< 37; i
++) {
1513 wp_spr
[i
* 2] = Z_getspr("BAL1", i
- 32, 1, wp_sprd
+ i
* 2);
1514 wp_spr
[i
* 2 + 1] = Z_getspr("BAL1", i
- 32, 2, wp_sprd
+ i
* 2 + 1);
1516 for (; i
< 42; i
++) {
1517 wp_spr
[i
* 2] = Z_getspr("BAL7", i
- 37, 1, wp_sprd
+ i
* 2);
1518 wp_spr
[i
* 2 + 1] = Z_getspr("BAL7", i
- 37, 2, wp_sprd
+ i
* 2 + 1);
1520 for (; i
< 47; i
++) {
1521 wp_spr
[i
* 2] = Z_getspr("BAL2", i
- 42, 1, wp_sprd
+ i
* 2);
1522 wp_spr
[i
* 2 + 1] = Z_getspr("BAL2", i
- 42, 2, wp_sprd
+ i
* 2 + 1);
1524 for (; i
< 49; i
++) {
1525 wp_spr
[i
* 2] = Z_getspr("MANF", i
- 47, 1, wp_sprd
+ i
* 2);
1526 wp_spr
[i
* 2 + 1] = Z_getspr("MANF", i
- 47, 2, wp_sprd
+ i
* 2 + 1);
1529 static const char snm
[18][4] = {
1530 "CLIP", "SHEL", "ROCK", "CELL", "AMMO", "SBOX", "BROK", "CELP",
1531 "STIM", "MEDI", "BPAK",
1532 "CSAW", "SHOT", "SGN2", "MGUN", "LAUN", "PLAS", "BFUG"
1534 static const char n4
[4][4] = {
1535 "SOUL", "SMRT", "SMGT", "SMBT"
1537 static const char n3
[2][4] = {
1540 for (i
= 0; i
< 18; i
++) {
1541 item_spr
[i
] = Z_getspr(snm
[i
], 0, 0, item_sprd
+ i
);
1543 for (; i
< 20; i
++) {
1544 item_spr
[i
] = Z_getspr("ARM1", i
- 18, 0, item_sprd
+ i
);
1545 item_spr
[i
+ 2] = Z_getspr("ARM2", i
- 18, 0, item_sprd
+ i
);
1548 for (; i
< 26; i
++) {
1549 item_spr
[i
] = Z_getspr("MEGA", i
- 22, 0, item_sprd
+ i
);
1551 for (; i
< 30; i
++) {
1552 item_spr
[i
] = Z_getspr("PINV", i
- 26, 0, item_sprd
+ i
);
1554 item_spr
[30] = Z_getspr("AQUA", 0, 0, item_sprd
+ 30);
1555 item_spr
[31] = Z_getspr("KEYR", 0, 0, item_sprd
+ 31);
1556 item_spr
[32] = Z_getspr("KEYG", 0, 0, item_sprd
+ 32);
1557 item_spr
[33] = Z_getspr("KEYB", 0, 0, item_sprd
+ 33);
1558 item_spr
[34] = Z_getspr("SUIT", 0, 0, item_sprd
+ 34);
1559 for (n
= 35, j
= 0; j
< 4; j
++) {
1560 for (i
= 0; i
< 4; i
++, n
++) {
1561 item_spr
[n
] = Z_getspr(n4
[j
], i
, 0, item_sprd
+ n
);
1564 for (j
= 0; j
< 2; j
++) {
1565 for (i
= 0; i
< 3; i
++, n
++) {
1566 item_spr
[n
] = Z_getspr(n3
[j
], i
, 0, item_sprd
+ n
);
1569 item_spr
[57] = Z_getspr("GUN2", 0, 0, item_sprd
+ 57);
1571 for (i
= 0; i
< 27; i
++) {
1572 plr_spr
[i
* 2] = Z_getspr("PLAY", i
, 1, plr_sprd
+ i
* 2);
1573 plr_msk
[i
* 2] = R_gl_get_special_spr("PLAY", i
, 1, &R_extract_mask_spr
);
1574 plr_spr
[i
* 2 + 1] = Z_getspr("PLAY", i
, 2, plr_sprd
+ i
* 2 + 1);
1575 plr_msk
[i
* 2 + 1] = R_gl_get_special_spr("PLAY", i
, 2, &R_extract_mask_spr
);
1577 strncpy(s
, "PWPx", 4);
1578 for (i
= 1; i
< 11; i
++) {
1579 s
[3] = (i
< 10 ? '0' : 'A' - 10) + i
;
1580 for (j
= 0; j
< 6; j
++) {
1581 plr_wpn
[i
][j
] = Z_getspr(s
, j
, 1, NULL
);
1585 static const char msn
[MN_TN
][4] = {
1586 "SARG", "TROO", "POSS", "SPOS", "CYBR", "CPOS", "BOSS", "BOS2", "HEAD", "SKUL",
1587 "PAIN", "SPID", "BSPI", "FATT", "SKEL", "VILE", "FISH", "BAR1", "ROBO", "PLAY"
1589 static const int mms
[MN_TN
] = {
1590 14*2, 21*2, 21*2, 21*2, 16*2, 20*2, 15*2, 15*2, 12*2, 11*2,
1591 13*2, 19*2, 16*2, 20*2, 17*2, 29*2, 6*2, 2*2, 17*2, 23*2
1593 mn_sgun
[0] = Z_getspr("PWP4", 0, 1, NULL
);
1594 mn_sgun
[1] = Z_getspr("PWP4", 1, 1, NULL
);
1595 for (j
= 0; j
< MN_TN
; j
++) {
1596 for (i
= 0; i
< mms
[j
]; i
++) {
1597 mn_spr
[j
][i
] = Z_getspr(msn
[j
], i
/ 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1598 if (j
== MN_MAN
- 1) {
1599 mn_man_msk
[i
] = R_gl_get_special_spr(msn
[j
], i
/ 2, (i
& 1) + 1, &R_extract_mask_spr
);
1602 if (j
== MN_BARREL
- 1) {
1603 for (i
= 4; i
< 14; i
++) {
1604 mn_spr
[j
][i
] = Z_getspr("BEXP", i
/ 2 - 2, (i
& 1) + 1, &mn_sprd
[j
][i
]);
1608 for (i
= 0; i
< 8; i
++) {
1609 mn_fspr
[i
] = Z_getspr("FIRE", i
, 0, NULL
);
1611 pl_spr
[0] = Z_getspr("PLAY", 'N' - 'A', 0, NULL
);
1612 pl_msk
[0] = R_gl_get_special_spr("PLAY", 'N' - 'A', 0, &R_extract_mask_spr
);
1613 pl_spr
[1] = Z_getspr("PLAY", 'W' - 'A', 0, NULL
);
1614 pl_msk
[1] = R_gl_get_special_spr("PLAY", 'W' - 'A', 0, &R_extract_mask_spr
);
1616 static const char mnm
[22][8]={
1617 "STTNUM0", "STTNUM1", "STTNUM2", "STTNUM3", "STTNUM4",
1618 "STTNUM5", "STTNUM6", "STTNUM7", "STTNUM8", "STTNUM9",
1619 "STTMINUS", "STTPRCNT",
1620 "FISTA0", "CSAWA0", "PISTA0", "SHOTA0", "SGN2A0", "MGUNA0", "LAUNA0",
1621 "PLASA0", "BFUGA0", "GUN2A0"
1623 stone
= R_gl_loadimage("STONE");
1624 stone2
= R_gl_loadimage("STONE2");
1625 keys
[0] = R_gl_loadimage("KEYRA0");
1626 keys
[1] = R_gl_loadimage("KEYGA0");
1627 keys
[2] = R_gl_loadimage("KEYBA0");
1628 for (i
= 0; i
< 22; i
++) {
1629 sth
[i
] = R_gl_loadimage(mnm
[i
]);
1631 strcpy(s
, "STBF_*");
1632 for (i
= '!'; i
< 160; i
++) {
1634 bfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1636 for (i
= '!'; i
< 160; i
++) {
1637 sprintf(s
, "STCFN%03d", i
);
1638 sfh
[i
- '!'] = R_gl_getimage(F_findres(s
));
1640 strcpy(s
, "WINUM*");
1641 for (i
= '0'; i
<= '9'; i
++) {
1643 bfh
[i
- '!'] = R_gl_loadimage(s
);
1645 bfh
[':' - '!'] = R_gl_loadimage("WICOLON");
1647 msklh
[0] = R_gl_loadimage("M_SKULL1");
1648 msklh
[1] = R_gl_loadimage("M_SKULL2");
1649 mbarl
= R_gl_loadimage("M_THERML");
1650 mbarm
= R_gl_loadimage("M_THERMM");
1651 mbarr
= R_gl_loadimage("M_THERMR");
1652 mbaro
= R_gl_loadimage("M_THERMO");
1653 mslotl
= R_gl_loadimage("M_LSLEFT");
1654 mslotm
= R_gl_loadimage("M_LSCNTR");
1655 mslotr
= R_gl_loadimage("M_LSRGHT");
1657 for (i
= 1; i
< ANIT
; i
++) {
1658 for (j
= 0; anm
[i
- 1][j
]; j
++) {
1659 anip
[i
][j
] = R_gl_loadimage(anm
[i
- 1][j
]);
1662 anip
[i
][j
] = (image
) {
1672 void R_init (void) {
1673 Uint32 flags
= SDL_OPENGL
;
1675 flags
= flags
| SDL_FULLSCREEN
;
1677 if (SCRW
<= 0 || SCRH
<= 0) {
1678 ERR_failinit("Invalid screen size %ix%i\n", SCRW
, SCRH
);
1681 R_init_playpal(); // only onece
1683 surf
= SDL_SetVideoMode(SCRW
, SCRH
, 0, flags
);
1685 ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
1687 root
= R_cache_new();
1692 void R_done (void) {
1693 R_cache_free(root
, 1);
1696 void R_setgamma (int g
) {
1697 gamma
= g
< 0 ? 0 : (g
> 4 ? 4 : g
);
1700 int R_getgamma (void) {
1704 void R_toggle_fullscreen (void) {
1705 fullscreen
= !fullscreen
;
1707 R_init(); // recreate window
1711 void R_get_name (int n
, char s
[8]) {
1712 assert(n
>= 0 && n
< 256);
1713 if (walp
[n
].res
== -1) {
1715 } else if (walp
[n
].res
== -2) {
1716 memcpy(s
, "_WATER_", 8);
1717 s
[7] = '0' + (intptr_t)walp
[n
].n
- 1;
1718 } else if (walani
[n
] > 0) {
1719 memcpy(s
, anm
[walani
[n
] - 1][0], 8);
1721 F_getresname(s
, walp
[n
].res
& 0x7FFF);
1725 static short getani (char n
[8]) {
1727 while (i
< ANIT
- 1 && strncasecmp(n
, anm
[i
][0], 8) != 0) {
1730 return i
< ANIT
- 1 ? i
+ 1 : 0;
1733 int R_get_special_id (int n
) {
1734 assert(n
>= 0 && n
<= 256);
1735 return walp
[n
].res
== -2 ? (intptr_t)walp
[n
].n
: -1;
1738 void R_begin_load (void) {
1740 for (i
= 0; i
< 256; i
++) {
1741 if (walp
[i
].n
!= NULL
&& walp
[i
].res
>= 0 && walani
[i
] == 0) {
1742 R_gl_free_image(&walp
[i
]);
1744 memset(&walp
[i
], 0, sizeof(image
));
1749 memset(anic
, 0, sizeof(anic
));
1751 max_wall_height
= 0;
1755 void R_load (char s
[8], int f
) {
1756 assert(max_textures
< 256);
1758 walp
[max_textures
] = (image
) {
1766 } else if (strncasecmp(s
, "_WATER_", 7) == 0) {
1767 walp
[max_textures
] = (image
) {
1768 .n
= (void*)((intptr_t)s
[7] - '0' + 1),
1776 walp
[max_textures
] = R_gl_loadimage(s
);
1778 walp
[max_textures
].res
|= 0x8000;
1780 if (s
[0] == 'S' && s
[1] == 'W' && s
[4] == '_') {
1781 walswp
[max_textures
] = 0;
1783 walani
[max_textures
] = getani(s
);
1785 max_wall_width
= max(max_wall_width
, walp
[max_textures
].w
);
1786 max_wall_height
= max(max_wall_height
, walp
[max_textures
].h
);
1790 void R_end_load (void) {
1794 for (i
= 1; i
< 256 && j
< 256; i
++) {
1795 if (walswp
[i
] == 0) {
1798 g
= F_getresid(s
) | (walp
[i
].res
& 0x8000);
1800 while (k
< 256 && walp
[k
].res
!= g
) {
1806 walp
[k
] = R_gl_getimage(g
);
1807 walf
[k
] = g
& 0x8000 ? 1 : 0;
1815 void R_loadsky (int sky
) {
1819 R_gl_free_image(&horiz
);
1820 horiz
= R_gl_loadimage(s
);