2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Definitions for graphics lib.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-01-12 00:26:03 +00:00
|
|
|
#pragma once
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-07-19 17:58:36 +00:00
|
|
|
#include <cstdint>
|
2014-07-20 03:48:27 +00:00
|
|
|
#include <memory>
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "pstypes.h"
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2013-01-06 21:03:57 +00:00
|
|
|
#include "palette.h"
|
2013-06-27 02:35:22 +00:00
|
|
|
#include "dxxsconf.h"
|
2013-12-08 23:37:40 +00:00
|
|
|
#include "fmtcheck.h"
|
2014-06-21 23:55:24 +00:00
|
|
|
#include "pack.h"
|
2014-07-17 03:05:21 +00:00
|
|
|
#include "compiler-array.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#ifdef DXX_BUILD_DESCENT_I
|
|
|
|
extern int HiresGFXAvailable;
|
|
|
|
#endif
|
|
|
|
|
2011-02-23 16:46:39 +00:00
|
|
|
// some defines for transparency and blending
|
|
|
|
#define TRANSPARENCY_COLOR 255 // palette entry of transparency color -- 255 on the PC
|
|
|
|
#define GR_FADE_LEVELS 34
|
|
|
|
#define GR_FADE_OFF GR_FADE_LEVELS // yes, max means OFF - don't screw that up
|
|
|
|
#define GR_BLEND_NORMAL 0 // normal blending
|
|
|
|
#define GR_BLEND_ADDITIVE_A 1 // additive alpha blending
|
|
|
|
#define GR_BLEND_ADDITIVE_C 2 // additive color blending
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#define GWIDTH grd_curcanv->cv_bitmap.bm_w
|
|
|
|
#define GHEIGHT grd_curcanv->cv_bitmap.bm_h
|
2015-03-22 18:49:21 +00:00
|
|
|
#define SWIDTH (grd_curscreen->get_screen_width())
|
|
|
|
#define SHEIGHT (grd_curscreen->get_screen_height())
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
#define HIRESMODE HiresGFXAvailable // descent.pig either contains hires or lowres graphics, not both
|
|
|
|
#endif
|
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2013-11-10 16:38:06 +00:00
|
|
|
#define HIRESMODE (SWIDTH >= 640 && SHEIGHT >= 480 && !GameArg.GfxSkipHiresGFX)
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
#define MAX_BMP_SIZE(width, height) (4 + ((width) + 2) * (height))
|
2009-11-17 14:27:39 +00:00
|
|
|
|
|
|
|
#define SCRNS_DIR "screenshots/"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
struct grs_point
|
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
fix x,y;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//these are control characters that have special meaning in the font code
|
|
|
|
|
|
|
|
#define CC_COLOR 1 //next char is new foreground color
|
|
|
|
#define CC_LSPACING 2 //next char specifies line spacing
|
|
|
|
#define CC_UNDERLINE 3 //next char is underlined
|
|
|
|
|
|
|
|
//now have string versions of these control characters (can concat inside a string)
|
|
|
|
|
|
|
|
#define CC_COLOR_S "\x1" //next char is new foreground color
|
|
|
|
#define CC_LSPACING_S "\x2" //next char specifies line spacing
|
|
|
|
#define CC_UNDERLINE_S "\x3" //next char is underlined
|
|
|
|
|
|
|
|
#define BM_LINEAR 0
|
|
|
|
#define BM_MODEX 1
|
|
|
|
#define BM_SVGA 2
|
|
|
|
#define BM_RGB15 3 //5 bits each r,g,b stored at 16 bits
|
|
|
|
#define BM_SVGA15 4
|
|
|
|
#ifdef OGL
|
|
|
|
#define BM_OGL 5
|
|
|
|
#endif /* def OGL */
|
|
|
|
|
|
|
|
#define SM(w,h) ((((u_int32_t)w)<<16)+(((u_int32_t)h)&0xFFFF))
|
|
|
|
#define SM_W(m) (m>>16)
|
|
|
|
#define SM_H(m) (m&0xFFFF)
|
2009-11-17 14:27:39 +00:00
|
|
|
#define SM_ORIGINAL 0
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#define BM_FLAG_TRANSPARENT 1
|
|
|
|
#define BM_FLAG_SUPER_TRANSPARENT 2
|
|
|
|
#define BM_FLAG_NO_LIGHTING 4
|
|
|
|
#define BM_FLAG_RLE 8 // A run-length encoded bitmap.
|
|
|
|
#define BM_FLAG_PAGED_OUT 16 // This bitmap's data is paged out.
|
|
|
|
#define BM_FLAG_RLE_BIG 32 // for bitmaps that RLE to > 255 per row (i.e. cockpits)
|
|
|
|
|
2014-07-14 02:40:42 +00:00
|
|
|
struct grs_bitmap : prohibit_void_ptr<grs_bitmap>
|
2013-12-22 22:03:07 +00:00
|
|
|
{
|
2014-12-05 03:31:07 +00:00
|
|
|
uint16_t bm_x,bm_y; // Offset from parent's origin
|
2014-09-20 23:47:27 +00:00
|
|
|
uint16_t bm_w,bm_h; // width,height
|
2006-03-20 17:12:09 +00:00
|
|
|
sbyte bm_type; // 0=Linear, 1=ModeX, 2=SVGA
|
|
|
|
sbyte bm_flags; // bit 0 on means it has transparency.
|
|
|
|
// bit 1 on means it has supertransparency
|
|
|
|
// bit 2 on means it doesn't get passed through lighting.
|
|
|
|
short bm_rowsize; // unsigned char offset to next row
|
2014-12-02 03:24:38 +00:00
|
|
|
union {
|
|
|
|
const uint8_t *bm_data; // ptr to pixel data...
|
2006-03-20 17:12:09 +00:00
|
|
|
// Linear = *parent+(rowsize*y+x)
|
|
|
|
// ModeX = *parent+(rowsize*y+x/4)
|
|
|
|
// SVGA = *parent+(rowsize*y+x)
|
2014-12-02 03:24:38 +00:00
|
|
|
uint8_t *bm_mdata;
|
|
|
|
};
|
|
|
|
const uint8_t *get_bitmap_data() const { return bm_data; }
|
|
|
|
uint8_t *get_bitmap_data() { return bm_mdata; }
|
2006-03-20 17:12:09 +00:00
|
|
|
unsigned short bm_handle; //for application. initialized to 0
|
|
|
|
ubyte avg_color; // Average color of all pixels in texture map.
|
2014-07-19 03:08:19 +00:00
|
|
|
array<fix, 3> avg_color_rgb; // same as above but real rgb value to be used to textured objects that should emit light
|
2013-10-26 03:40:42 +00:00
|
|
|
struct grs_bitmap *bm_parent;
|
2006-03-20 17:12:09 +00:00
|
|
|
#ifdef OGL
|
2013-12-22 22:03:07 +00:00
|
|
|
struct ogl_texture *gltexture;
|
2006-03-20 17:12:09 +00:00
|
|
|
#endif /* def OGL */
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//font structure
|
2014-06-21 23:55:24 +00:00
|
|
|
struct grs_font : public prohibit_void_ptr<grs_font>
|
2013-12-22 22:03:07 +00:00
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
short ft_w; // Width in pixels
|
|
|
|
short ft_h; // Height in pixels
|
|
|
|
short ft_flags; // Proportional?
|
|
|
|
short ft_baseline; //
|
|
|
|
ubyte ft_minchar; // First char defined by this font
|
|
|
|
ubyte ft_maxchar; // Last char defined by this font
|
|
|
|
short ft_bytewidth; // Width in unsigned chars
|
|
|
|
ubyte * ft_data; // Ptr to raw data.
|
2014-08-07 03:05:48 +00:00
|
|
|
std::unique_ptr<ubyte *[]> ft_chars; // Ptrs to data for each char (required for prop font)
|
2006-03-20 17:12:09 +00:00
|
|
|
short * ft_widths; // Array of widths (required for prop font)
|
|
|
|
ubyte * ft_kerndata; // Array of kerning triplet data
|
|
|
|
#ifdef OGL
|
|
|
|
// These fields do not participate in disk i/o!
|
2014-08-07 03:09:28 +00:00
|
|
|
std::unique_ptr<grs_bitmap[]> ft_bitmaps;
|
2006-03-20 17:12:09 +00:00
|
|
|
grs_bitmap ft_parent_bitmap;
|
|
|
|
#endif /* def OGL */
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#define GRS_FONT_SIZE 28 // how much space it takes up on disk
|
|
|
|
|
2014-11-30 22:09:19 +00:00
|
|
|
struct grs_canvas : prohibit_void_ptr<grs_canvas>
|
2013-12-22 22:03:07 +00:00
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
grs_bitmap cv_bitmap; // the bitmap for this canvas
|
2014-07-20 03:48:27 +00:00
|
|
|
const grs_font * cv_font; // the currently selected font
|
2014-11-15 03:31:41 +00:00
|
|
|
uint8_t cv_color; // current color
|
2006-03-20 17:12:09 +00:00
|
|
|
short cv_drawmode; // fill,XOR,etc.
|
|
|
|
short cv_font_fg_color; // current font foreground color (-1==Invisible)
|
|
|
|
short cv_font_bg_color; // current font background color (-1==Invisible)
|
2014-07-14 01:56:12 +00:00
|
|
|
int cv_fade_level; // transparency level
|
|
|
|
ubyte cv_blend_func; // blending function to use
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// System functions:
|
|
|
|
// setup and set mode. this creates a grs_screen structure and sets
|
|
|
|
// grd_curscreen to point to it. grs_curcanv points to this screen's
|
|
|
|
// canvas. Saves the current VGA state and screen mode.
|
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2015-03-22 18:49:21 +00:00
|
|
|
class grs_screen : prohibit_void_ptr<grs_screen>
|
|
|
|
{ // This is a video screen
|
|
|
|
unsigned short sc_w, sc_h; // Actual Width and Height
|
|
|
|
public:
|
|
|
|
grs_canvas sc_canvas; // Represents the entire screen
|
|
|
|
u_int32_t sc_mode; // Video mode number
|
|
|
|
fix sc_aspect; //aspect ratio (w/h) for this screen
|
|
|
|
uint_fast32_t get_screen_width() const
|
|
|
|
{
|
|
|
|
return sc_w;
|
|
|
|
}
|
|
|
|
uint_fast32_t get_screen_height() const
|
|
|
|
{
|
|
|
|
return sc_h;
|
|
|
|
}
|
|
|
|
void set_screen_width_height(uint16_t w, uint16_t h)
|
|
|
|
{
|
|
|
|
sc_w = w;
|
|
|
|
sc_h = h;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-02-09 12:38:21 +00:00
|
|
|
int gr_init(int mode);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-07-17 03:05:21 +00:00
|
|
|
int gr_list_modes( array<uint32_t, 50> &gsmodes );
|
2006-03-20 17:12:09 +00:00
|
|
|
int gr_set_mode(u_int32_t mode);
|
2008-04-22 08:29:29 +00:00
|
|
|
void gr_set_attributes(void);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//shut down the 2d. Restore the screen mode.
|
|
|
|
void gr_close(void);
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Canvas functions:
|
|
|
|
|
|
|
|
// Makes a new canvas. allocates memory for the canvas and its bitmap,
|
|
|
|
// including the raw pixel buffer.
|
|
|
|
|
2014-09-17 02:45:12 +00:00
|
|
|
struct grs_main_canvas : grs_canvas
|
|
|
|
{
|
|
|
|
~grs_main_canvas();
|
|
|
|
};
|
|
|
|
typedef std::unique_ptr<grs_main_canvas> grs_canvas_ptr;
|
|
|
|
|
2014-11-15 03:31:41 +00:00
|
|
|
grs_canvas_ptr gr_create_canvas(uint16_t w, uint16_t h);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Creates a canvas that is part of another canvas. this can be used to make
|
|
|
|
// a window on the screen. the canvas structure is malloc'd; the address of
|
|
|
|
// the raw pixel data is inherited from the parent canvas.
|
|
|
|
|
2014-09-06 23:55:43 +00:00
|
|
|
struct grs_subcanvas : grs_canvas {};
|
|
|
|
typedef std::unique_ptr<grs_subcanvas> grs_subcanvas_ptr;
|
|
|
|
|
2015-01-17 18:31:40 +00:00
|
|
|
grs_subcanvas_ptr gr_create_sub_canvas(grs_canvas &canv,uint16_t x,uint16_t y,uint16_t w, uint16_t h);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Initialize the specified canvas. the raw pixel data buffer is passed as
|
|
|
|
// a parameter. no memory allocation is performed.
|
|
|
|
|
2015-01-17 18:31:40 +00:00
|
|
|
void gr_init_canvas(grs_canvas &canv,unsigned char *pixdata, uint8_t pixtype, uint16_t w, uint16_t h);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Initialize the specified sub canvas. no memory allocation is performed.
|
|
|
|
|
2015-01-17 18:31:40 +00:00
|
|
|
void gr_init_sub_canvas(grs_canvas &n, grs_canvas &src, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Clear the current canvas to the specified color
|
2014-08-08 02:07:47 +00:00
|
|
|
void gr_clear_canvas(color_t color);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Bitmap functions:
|
|
|
|
|
2008-11-09 14:31:30 +00:00
|
|
|
// these are the two workhorses, the others just use these
|
2014-11-30 22:09:20 +00:00
|
|
|
void gr_init_bitmap(grs_bitmap &bm, uint8_t mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline, unsigned char * data);
|
2014-11-30 22:09:21 +00:00
|
|
|
void gr_init_sub_bitmap (grs_bitmap &bm, grs_bitmap &bmParent, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
2008-11-09 14:31:30 +00:00
|
|
|
|
2014-11-30 22:09:21 +00:00
|
|
|
void gr_init_bitmap_alloc(grs_bitmap &bm, uint8_t mode, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t bytesperline);
|
2015-01-17 18:31:40 +00:00
|
|
|
void gr_free_bitmap_data(grs_bitmap &bm);
|
2008-11-09 14:31:30 +00:00
|
|
|
|
2014-07-22 02:14:56 +00:00
|
|
|
// Free the bitmap and its pixel data
|
2015-01-17 18:31:40 +00:00
|
|
|
class grs_main_bitmap : public grs_bitmap
|
2014-07-22 02:14:56 +00:00
|
|
|
{
|
2015-01-17 18:31:40 +00:00
|
|
|
public:
|
|
|
|
grs_main_bitmap() = default;
|
|
|
|
grs_main_bitmap(const grs_main_bitmap &) = delete;
|
|
|
|
grs_main_bitmap &operator=(const grs_main_bitmap &) = delete;
|
|
|
|
~grs_main_bitmap()
|
2014-07-22 02:14:56 +00:00
|
|
|
{
|
2015-01-17 18:31:40 +00:00
|
|
|
gr_free_bitmap_data(*this);
|
2014-07-22 02:14:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-17 18:31:40 +00:00
|
|
|
typedef std::unique_ptr<grs_main_bitmap> grs_bitmap_ptr;
|
2014-07-22 02:14:56 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// Allocate a bitmap and its pixel data buffer.
|
2014-11-15 03:31:41 +00:00
|
|
|
grs_bitmap_ptr gr_create_bitmap(uint16_t w,uint16_t h);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-07-22 02:50:01 +00:00
|
|
|
// Free the bitmap, but not the pixel data buffer
|
2015-01-17 18:31:40 +00:00
|
|
|
class grs_subbitmap : public grs_bitmap
|
2014-07-22 02:50:01 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2015-01-17 18:31:40 +00:00
|
|
|
typedef std::unique_ptr<grs_subbitmap> grs_subbitmap_ptr;
|
2014-07-22 02:50:01 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// Creates a bitmap which is part of another bitmap
|
2014-11-30 22:09:21 +00:00
|
|
|
grs_subbitmap_ptr gr_create_sub_bitmap(grs_bitmap &bm, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Free the bitmap's data
|
2014-11-30 22:09:20 +00:00
|
|
|
void gr_init_bitmap_data (grs_bitmap &bm);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-11-30 22:09:22 +00:00
|
|
|
void gr_bm_pixel(grs_bitmap &bm, uint_fast32_t x, uint_fast32_t y, uint8_t color );
|
2014-12-02 03:35:01 +00:00
|
|
|
void gr_bm_ubitblt(unsigned w, unsigned h, int dx, int dy, int sx, int sy, const grs_bitmap &src, grs_bitmap &dest);
|
2014-12-02 03:35:01 +00:00
|
|
|
void gr_bm_ubitbltm(unsigned w, unsigned h, unsigned dx, unsigned dy, unsigned sx, unsigned sy, const grs_bitmap &src, grs_bitmap &dest);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-11-30 22:09:21 +00:00
|
|
|
static inline void gr_set_bitmap_flags(grs_bitmap &bm, uint8_t flags)
|
|
|
|
{
|
|
|
|
bm.bm_flags = flags;
|
|
|
|
}
|
|
|
|
|
2014-11-30 22:09:21 +00:00
|
|
|
static inline void gr_set_transparent(grs_bitmap &bm, bool bTransparent)
|
|
|
|
{
|
|
|
|
auto bm_flags = bm.bm_flags;
|
|
|
|
gr_set_bitmap_flags(bm, bTransparent ? bm_flags | BM_FLAG_TRANSPARENT : bm_flags & ~BM_FLAG_TRANSPARENT);
|
|
|
|
}
|
|
|
|
|
2014-11-30 22:09:20 +00:00
|
|
|
void gr_set_bitmap_data(grs_bitmap &bm, unsigned char *data);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Color functions:
|
|
|
|
|
|
|
|
// When this function is called, the guns are set to gr_palette, and
|
|
|
|
// the palette stays the same until gr_close is called
|
|
|
|
|
2013-06-08 22:24:17 +00:00
|
|
|
void gr_use_palette_table(const char * filename );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Drawing functions:
|
|
|
|
|
2011-02-23 16:46:39 +00:00
|
|
|
// Sets the color in the current canvas.
|
2014-08-08 02:07:47 +00:00
|
|
|
void gr_setcolor(color_t color);
|
2011-02-23 16:46:39 +00:00
|
|
|
// Sets transparency and blending function
|
|
|
|
void gr_settransblend(int fade_level, ubyte blend_func);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Draws a point into the current canvas in the current color and drawmode.
|
|
|
|
void gr_pixel(int x,int y);
|
|
|
|
void gr_upixel(int x,int y);
|
|
|
|
|
|
|
|
// Gets a pixel;
|
2014-11-30 22:09:18 +00:00
|
|
|
unsigned char gr_gpixel(const grs_bitmap &bitmap, int x, int y );
|
|
|
|
unsigned char gr_ugpixel(const grs_bitmap &bitmap, int x, int y );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Draws a line into the current canvas in the current color and drawmode.
|
|
|
|
int gr_line(fix x0,fix y0,fix x1,fix y1);
|
|
|
|
int gr_uline(fix x0,fix y0,fix x1,fix y1);
|
|
|
|
|
|
|
|
// Draw the bitmap into the current canvas at the specified location.
|
2014-12-02 03:35:01 +00:00
|
|
|
void gr_bitmap(unsigned x,unsigned y,grs_bitmap &bm);
|
2014-11-30 22:09:19 +00:00
|
|
|
void gr_ubitmap(grs_bitmap &bm);
|
2014-12-02 03:35:01 +00:00
|
|
|
void show_fullscr(grs_bitmap &bm);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2010-06-18 07:31:06 +00:00
|
|
|
// Find transparent area in bitmap
|
2014-12-02 03:35:01 +00:00
|
|
|
void gr_bitblt_find_transparent_area(const grs_bitmap &bm, unsigned &minx, unsigned &miny, unsigned &maxx, unsigned &maxy);
|
2010-06-18 07:31:06 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// bitmap function with transparency
|
2014-12-02 03:35:01 +00:00
|
|
|
void gr_bitmapm(unsigned x, unsigned y, const grs_bitmap &bm);
|
2014-12-02 03:35:01 +00:00
|
|
|
void gr_ubitmapm(unsigned x, unsigned y, grs_bitmap &bm);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Draw a rectangle into the current canvas.
|
|
|
|
void gr_rect(int left,int top,int right,int bot);
|
|
|
|
void gr_urect(int left,int top,int right,int bot);
|
|
|
|
|
|
|
|
// Draw a filled circle
|
|
|
|
int gr_disk(fix x,fix y,fix r);
|
|
|
|
|
|
|
|
// Draw an outline circle
|
|
|
|
int gr_circle(fix x,fix y,fix r);
|
|
|
|
int gr_ucircle(fix x,fix y,fix r);
|
|
|
|
|
|
|
|
// Draw an unfilled rectangle into the current canvas
|
2015-02-14 22:48:30 +00:00
|
|
|
void gr_box(uint_fast32_t left,uint_fast32_t top,uint_fast32_t right,uint_fast32_t bot);
|
2006-03-20 17:12:09 +00:00
|
|
|
void gr_ubox(int left,int top,int right,int bot);
|
|
|
|
|
|
|
|
void gr_scanline( int x1, int x2, int y );
|
|
|
|
void gr_uscanline( int x1, int x2, int y );
|
|
|
|
|
2014-07-20 03:48:27 +00:00
|
|
|
void gr_close_font(std::unique_ptr<grs_font> font);
|
|
|
|
|
|
|
|
struct font_delete
|
|
|
|
{
|
|
|
|
void operator()(grs_font *p) const
|
|
|
|
{
|
|
|
|
gr_close_font(std::unique_ptr<grs_font>(p));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::unique_ptr<grs_font, font_delete> grs_font_ptr;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Reads in a font file... current font set to this one.
|
2014-07-20 03:48:27 +00:00
|
|
|
grs_font_ptr gr_init_font( const char * fontfile );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
#define DXX_SDL_WINDOW_CAPTION "Descent"
|
|
|
|
#define DXX_SDL_WINDOW_ICON_BITMAP "d1x-rebirth.bmp"
|
|
|
|
|
|
|
|
static inline void gr_remap_color_fonts() {}
|
|
|
|
static inline void gr_remap_mono_fonts() {}
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
|
|
|
#define DXX_SDL_WINDOW_CAPTION "Descent II"
|
|
|
|
#define DXX_SDL_WINDOW_ICON_BITMAP "d2x-rebirth.bmp"
|
2013-01-06 21:03:57 +00:00
|
|
|
void gr_copy_palette(palette_array_t &gr_palette, const palette_array_t &pal);
|
2013-03-03 01:03:33 +00:00
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//remap (by re-reading) all the color fonts
|
|
|
|
void gr_remap_color_fonts();
|
|
|
|
void gr_remap_mono_fonts();
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Writes a string using current font. Returns the next column after last char.
|
2014-07-20 03:48:27 +00:00
|
|
|
void gr_set_curfont(const grs_font *);
|
|
|
|
static inline void gr_set_curfont(const grs_font_ptr &p)
|
|
|
|
{
|
|
|
|
gr_set_curfont(p.get());
|
|
|
|
}
|
2008-02-24 14:41:27 +00:00
|
|
|
void gr_set_fontcolor( int fg_color, int bg_color );
|
2013-12-01 19:13:39 +00:00
|
|
|
void gr_string(int x, int y, const char *s );
|
|
|
|
void gr_ustring(int x, int y, const char *s );
|
|
|
|
void gr_printf( int x, int y, const char * format, ... ) __attribute_format_printf(3, 4);
|
2013-12-08 23:37:40 +00:00
|
|
|
#define gr_printf(A1,A2,F,...) dxx_call_printf_checked(gr_printf,gr_string,(A1,A2),(F),##__VA_ARGS__)
|
2013-12-01 19:13:39 +00:00
|
|
|
void gr_uprintf( int x, int y, const char * format, ... ) __attribute_format_printf(3, 4);
|
2013-12-08 23:37:40 +00:00
|
|
|
#define gr_uprintf(A1,A2,F,...) dxx_call_printf_checked(gr_uprintf,gr_ustring,(A1,A2),(F),##__VA_ARGS__)
|
2012-07-22 23:17:54 +00:00
|
|
|
void gr_get_string_size(const char *s, int *string_width, int *string_height, int *average_width );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
// From scale.c
|
2014-11-30 22:09:17 +00:00
|
|
|
void scale_bitmap(const grs_bitmap &bp, const array<grs_point, 3> &vertbuf, int orientation );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
// Global variables
|
|
|
|
extern grs_canvas *grd_curcanv; //active canvas
|
2014-11-30 22:09:19 +00:00
|
|
|
extern std::unique_ptr<grs_screen> grd_curscreen; //active screen
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-01-12 00:26:03 +00:00
|
|
|
void gr_set_default_canvas();
|
|
|
|
void gr_set_current_canvas(grs_canvas &);
|
|
|
|
void _gr_set_current_canvas(grs_canvas *);
|
|
|
|
|
|
|
|
static inline void _gr_set_current_canvas_inline(grs_canvas *canv)
|
|
|
|
{
|
|
|
|
if (canv)
|
|
|
|
gr_set_current_canvas(*canv);
|
|
|
|
else
|
|
|
|
gr_set_default_canvas();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gr_set_current_canvas(grs_canvas *canv)
|
|
|
|
{
|
|
|
|
#ifdef DXX_HAVE_BUILTIN_CONSTANT_P
|
|
|
|
if (__builtin_constant_p(!canv))
|
|
|
|
_gr_set_current_canvas_inline(canv);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
_gr_set_current_canvas(canv);
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-09-17 02:45:12 +00:00
|
|
|
static inline void gr_set_current_canvas(grs_canvas_ptr &canv)
|
|
|
|
{
|
|
|
|
gr_set_current_canvas(canv.get());
|
|
|
|
}
|
|
|
|
|
2014-09-06 23:55:43 +00:00
|
|
|
static inline void gr_set_current_canvas(grs_subcanvas_ptr &canv)
|
|
|
|
{
|
|
|
|
gr_set_current_canvas(canv.get());
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//flags for fonts
|
|
|
|
#define FT_COLOR 1
|
|
|
|
#define FT_PROPORTIONAL 2
|
|
|
|
#define FT_KERNED 4
|
|
|
|
|
2013-01-06 21:03:57 +00:00
|
|
|
extern palette_array_t gr_palette;
|
2014-08-08 02:44:27 +00:00
|
|
|
typedef array<color_t, 256> gft_array0;
|
|
|
|
typedef array<gft_array0, GR_FADE_LEVELS> gft_array1;
|
|
|
|
extern gft_array1 gr_fade_table;
|
2006-03-20 17:12:09 +00:00
|
|
|
extern ubyte gr_inverse_table[32*32*32];
|
|
|
|
|
|
|
|
extern ushort gr_palette_selector;
|
|
|
|
extern ushort gr_inverse_table_selector;
|
|
|
|
extern ushort gr_fade_table_selector;
|
|
|
|
|
|
|
|
// Remaps a bitmap into the current palette. If transparent_color is
|
|
|
|
// between 0 and 255 then all occurances of that color are mapped to
|
|
|
|
// whatever color the 2d uses for transparency. This is normally used
|
|
|
|
// right after a call to iff_read_bitmap like this:
|
|
|
|
// iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal);
|
|
|
|
// if (iff_error != IFF_NO_ERROR) Error("Can't load IFF file <%s>, error=%d",filename,iff_error);
|
|
|
|
// if ( iff_has_transparency )
|
|
|
|
// gr_remap_bitmap( new, newpal, iff_transparent_color );
|
|
|
|
// else
|
|
|
|
// gr_remap_bitmap( new, newpal, -1 );
|
2013-01-06 21:03:57 +00:00
|
|
|
void gr_remap_bitmap( grs_bitmap * bmp, palette_array_t &palette, int transparent_color, int super_transparent_color );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Same as above, but searches using gr_find_closest_color which uses
|
|
|
|
// 18-bit accurracy instead of 15bit when translating colors.
|
2015-01-25 05:32:45 +00:00
|
|
|
void gr_remap_bitmap_good(grs_bitmap &bmp, palette_array_t &palette, uint_fast32_t transparent_color, uint_fast32_t super_transparent_color);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-01-06 21:03:57 +00:00
|
|
|
void gr_palette_step_up( int r, int g, int b );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
extern void gr_bitmap_check_transparency( grs_bitmap * bmp );
|
|
|
|
|
|
|
|
#define BM_RGB(r,g,b) ( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )
|
|
|
|
#define BM_XRGB(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 )
|
|
|
|
|
|
|
|
// Given: r,g,b, each in range of 0-63, return the color index that
|
|
|
|
// best matches the input.
|
2014-08-08 02:07:47 +00:00
|
|
|
color_t gr_find_closest_color( int r, int g, int b );
|
2006-03-20 17:12:09 +00:00
|
|
|
int gr_find_closest_color_15bpp( int rgb );
|
|
|
|
|
2007-03-21 11:32:33 +00:00
|
|
|
extern void gr_flip(void);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* must return 0 if windowed, 1 if fullscreen
|
|
|
|
*/
|
|
|
|
int gr_check_fullscreen(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns state after toggling (ie, same as if you had called
|
|
|
|
* check_fullscreen immediatly after)
|
|
|
|
*/
|
2015-03-22 18:49:21 +00:00
|
|
|
void gr_toggle_fullscreen();
|
2012-11-02 16:51:24 +00:00
|
|
|
void ogl_do_palfx(void);
|
2013-08-13 23:11:49 +00:00
|
|
|
void ogl_init_pixel_buffers(unsigned w, unsigned h);
|
2012-11-02 16:51:24 +00:00
|
|
|
void ogl_close_pixel_buffers(void);
|
2012-11-11 22:12:51 +00:00
|
|
|
void ogl_cache_polymodel_textures(int model_num);;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|