1 /* $Id: gr.h,v 1.19 2003/03/19 22:44:15 btb Exp $ */ 2 /* 3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX 4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO 5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A 6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS 7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS 8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE 9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE 10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS 11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. 12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. 13 */ 14 15 #ifndef _GR_H 16 #define _GR_H 17 18 #include "pstypes.h" 19 #include "fix.h" 20 21 #if defined(MACINTOSH) || defined(MACDATA) 22 #error foo 23 #define SWAP_0_255 // swap black and white 24 #define TRANSPARENCY_COLOR 0 // palette entry of transparency color -- 0 on the mac 25 #define TRANSPARENCY_COLOR_STR "0" 26 #else 27 /* #undef SWAP_0_255 */ // no swapping for PC people 28 #define TRANSPARENCY_COLOR 255 // palette entry of transparency color -- 255 on the PC 29 #define TRANSPARENCY_COLOR_STR "255" 30 #endif 31 32 #define GR_FADE_LEVELS 34 33 #define GR_ACTUAL_FADE_LEVELS 32 34 35 #define GWIDTH grd_curcanv->cv_bitmap.bm_w 36 #define GHEIGHT grd_curcanv->cv_bitmap.bm_h 37 #define SWIDTH (grd_curscreen->sc_w) 38 #define SHEIGHT (grd_curscreen->sc_h) 39 40 41 extern int Gr_scanline_darkening_level; 42 43 typedef struct _grs_point { 44 fix x,y; 45 } grs_point; 46 47 //these are control characters that have special meaning in the font code 48 49 #define CC_COLOR 1 //next char is new foreground color 50 #define CC_LSPACING 2 //next char specifies line spacing 51 #define CC_UNDERLINE 3 //next char is underlined 52 53 //now have string versions of these control characters (can concat inside a string) 54 55 #define CC_COLOR_S "\x1" //next char is new foreground color 56 #define CC_LSPACING_S "\x2" //next char specifies line spacing 57 #define CC_UNDERLINE_S "\x3" //next char is underlined 58 59 #define BM_LINEAR 0 60 #define BM_MODEX 1 61 #define BM_SVGA 2 62 #define BM_RGB15 3 //5 bits each r,g,b stored at 16 bits 63 #define BM_SVGA15 4 64 #ifdef OGL 65 #define BM_OGL 5 66 #endif 67 68 //@@// Define these modes for Gameplay too, since the game was developed under 69 //@@// DOS, we will adapt these modes to other systems thru rendering. 70 //@@#define SM_ORIGINAL -1 71 //@@#define SM_320x200C 0 72 //@@#define SM_320x200U 1 73 //@@#define SM_320x240U 2 74 //@@#define SM_360x200U 3 75 //@@#define SM_360x240U 4 76 //@@#define SM_376x282U 5 77 //@@#define SM_320x400U 6 78 //@@#define SM_320x480U 7 79 //@@#define SM_360x400U 8 80 //@@#define SM_360x480U 9 81 //@@#define SM_360x360U 10 82 //@@#define SM_376x308U 11 83 //@@#define SM_376x564U 12 84 //@@#define SM_640x400V 13 85 //@@#define SM_640x480V 14 86 //@@#define SM_800x600V 15 87 //@@#define SM_1024x768V 16 88 //@@#define SM_640x480V15 17 89 //@@#define SM_800x600V15 18 90 91 #define SM(w,h) ((((u_int32_t)w)<<16)+(((u_int32_t)h)&0xFFFF)) 92 #define SM_W(m) (m>>16) 93 #define SM_H(m) (m&0xFFFF) 94 95 96 #define BM_FLAG_TRANSPARENT 1 97 #define BM_FLAG_SUPER_TRANSPARENT 2 98 #define BM_FLAG_NO_LIGHTING 4 99 #define BM_FLAG_RLE 8 // A run-length encoded bitmap. 100 #define BM_FLAG_PAGED_OUT 16 // This bitmap's data is paged out. 101 #define BM_FLAG_RLE_BIG 32 // for bitmaps that RLE to > 255 per row (i.e. cockpits) 102 103 typedef struct _grs_bitmap { 104 short bm_x,bm_y; // Offset from parent's origin 105 short bm_w,bm_h; // width,height 106 byte bm_type; // 0=Linear, 1=ModeX, 2=SVGA 107 byte bm_flags; // bit 0 on means it has transparency. 108 // bit 1 on means it has supertransparency 109 // bit 2 on means it doesn't get passed through lighting. 110 short bm_rowsize; // unsigned char offset to next row 111 unsigned char * bm_data; // ptr to pixel data... 112 // Linear = *parent+(rowsize*y+x) 113 // ModeX = *parent+(rowsize*y+x/4) 114 // SVGA = *parent+(rowsize*y+x) 115 unsigned short bm_handle; //for application. initialized to 0 116 ubyte avg_color; // Average color of all pixels in texture map. 117 byte unused; // to 4-byte align. 118 #ifdef OGL 119 struct _ogl_texture *gltexture; 120 struct _grs_bitmap *bm_parent; 121 #endif 122 } grs_bitmap; 123 124 //font structure 125 typedef struct _grs_font { 126 short ft_w; // Width in pixels 127 short ft_h; // Height in pixels 128 short ft_flags; // Proportional? 129 short ft_baseline; // 130 ubyte ft_minchar; // First char defined by this font 131 ubyte ft_maxchar; // Last char defined by this font 132 short ft_bytewidth; // Width in unsigned chars 133 ubyte * ft_data; // Ptr to raw data. 134 ubyte ** ft_chars; // Ptrs to data for each char (required for prop font) 135 short * ft_widths; // Array of widths (required for prop font) 136 ubyte * ft_kerndata; // Array of kerning triplet data 137 #ifdef OGL 138 // These fields do not participate in disk i/o! 139 grs_bitmap *ft_bitmaps; 140 grs_bitmap ft_parent_bitmap; 141 #endif 142 } __pack__ grs_font; 143 144 #define GRS_FONT_SIZE 28 // how much space it takes up on disk 145 146 typedef struct _grs_canvas { 147 grs_bitmap cv_bitmap; // the bitmap for this canvas 148 short cv_color; // current color 149 short cv_drawmode; // fill,XOR,etc. 150 grs_font * cv_font; // the currently selected font 151 short cv_font_fg_color; // current font foreground color (-1==Invisible) 152 short cv_font_bg_color; // current font background color (-1==Invisible) 153 } grs_canvas; 154 155 //shortcuts 156 #define cv_w cv_bitmap.bm_w 157 #define cv_h cv_bitmap.bm_h 158 159 typedef struct _grs_screen { // This is a video screen 160 grs_canvas sc_canvas; // Represents the entire screen 161 int sc_mode; // Video mode number 162 short sc_w, sc_h; // Actual Width and Height 163 fix sc_aspect; //aspect ratio (w/h) for this screen 164 } grs_screen; 165 166 167 //========================================================================= 168 // System functions: 169 // setup and set mode. this creates a grs_screen structure and sets 170 // grd_curscreen to point to it. grs_curcanv points to this screen's 171 // canvas. Saves the current VGA state and screen mode. 172 173 int gr_init(void); 174 175 // This function sets up the main screen. It should be called whenever 176 // the video mode changes. 177 int gr_init_screen(int mode, int w, int h, int x, int y, int rowsize, ubyte *data); 178 179 int gr_check_mode(u_int32_t mode); 180 int gr_set_mode(u_int32_t mode); 181 182 183 // These 4 functions actuall change screen colors. 184 185 extern void gr_pal_fade_out(unsigned char * pal); 186 extern void gr_pal_fade_in(unsigned char * pal); 187 extern void gr_pal_clear(void); 188 extern void gr_pal_setblock( int start, int number, unsigned char * pal ); 189 extern void gr_pal_getblock( int start, int number, unsigned char * pal ); 190 191 192 extern unsigned char *gr_video_memory; 193 // All graphic modules will define this value. 194 195 //shut down the 2d. Restore the screen mode. 196 void gr_close(void); 197 198 //========================================================================= 199 // Canvas functions: 200 201 // Makes a new canvas. allocates memory for the canvas and its bitmap, 202 // including the raw pixel buffer. 203 204 grs_canvas *gr_create_canvas(int w, int h); 205 #if defined(POLY_ACC) 206 grs_canvas *gr_create_canvas2(int w, int h, int type); 207 #endif 208 209 // Creates a canvas that is part of another canvas. this can be used to make 210 // a window on the screen. the canvas structure is malloc'd; the address of 211 // the raw pixel data is inherited from the parent canvas. 212 213 grs_canvas *gr_create_sub_canvas(grs_canvas *canv,int x,int y,int w, int h); 214 215 // Initialize the specified canvas. the raw pixel data buffer is passed as 216 // a parameter. no memory allocation is performed. 217 218 void gr_init_canvas(grs_canvas *canv,unsigned char *pixdata,int pixtype, int w,int h); 219 220 // Initialize the specified sub canvas. no memory allocation is performed. 221 222 void gr_init_sub_canvas(grs_canvas *new,grs_canvas *src,int x,int y,int w, int h); 223 224 // Free up the canvas and its pixel data. 225 226 void gr_free_canvas(grs_canvas *canv); 227 228 // Free up the canvas. do not free the pixel data, which belongs to the 229 // parent canvas. 230 231 void gr_free_sub_canvas(grs_canvas *canv); 232 233 // Clear the current canvas to the specified color 234 void gr_clear_canvas(int color); 235 236 //========================================================================= 237 // Bitmap functions: 238 239 // Allocate a bitmap and its pixel data buffer. 240 grs_bitmap *gr_create_bitmap(int w,int h); 241 242 // Allocated a bitmap and makes its data be raw_data that is already somewhere. 243 grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data ); 244 245 #if defined(POLY_ACC) 246 // Allocates a bitmap of a specific type. data is either NULL or raw data. 247 grs_bitmap *gr_create_bitmap2(int w, int h, int type, void *data ); 248 #endif 249 250 // Creates a bitmap which is part of another bitmap 251 grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm,int x,int y,int w, int h); 252 253 // Free the bitmap and its pixel data 254 void gr_free_bitmap(grs_bitmap *bm); 255 256 // Free the bitmap's data 257 void gr_free_bitmap_data (grs_bitmap *bm); 258 void gr_init_bitmap_data (grs_bitmap *bm); 259 260 // Free the bitmap, but not the pixel data buffer 261 void gr_free_sub_bitmap(grs_bitmap *bm); 262 263 void gr_bm_pixel( grs_bitmap * bm, int x, int y, unsigned char color ); 264 void gr_bm_upixel( grs_bitmap * bm, int x, int y, unsigned char color ); 265 void gr_bm_ubitblt( int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); 266 void gr_bm_ubitbltm(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); 267 268 #ifndef __MSDOS__ 269 void gr_bm_ubitblt_double(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *src, grs_bitmap *dest); 270 void gr_linear_movsd_double(ubyte *src, ubyte *dest, int num_pixels); 271 #endif 272 273 void gr_update_buffer( void * sbuf1, void * sbuf2, void * dbuf, int size ); 274 275 //========================================================================= 276 // Color functions: 277 278 // When this function is called, the guns are set to gr_palette, and 279 // the palette stays the same until gr_close is called 280 281 void gr_use_palette_table(char * filename ); 282 void gr_copy_palette(ubyte *gr_palette, ubyte *pal, int size); 283 284 //========================================================================= 285 // Drawing functions: 286 287 // For solid, XOR, or other fill modes. 288 int gr_set_drawmode(int mode); 289 290 // Sets the color in the current canvas. should be a macro 291 // Use: gr_setcolor(int color); 292 void gr_setcolor(int color); 293 294 // Draw a polygon into the current canvas in the current color and drawmode. 295 // verts points to an ordered list of x,y pairs. the polygon should be 296 // convex; a concave polygon will be handled in some reasonable manner, 297 // but not necessarily shaded as a concave polygon. It shouldn't hang. 298 // probably good solution is to shade from minx to maxx on each scan line. 299 // int should really be fix 300 int gr_poly(int nverts,int *verts); 301 int gr_upoly(int nverts,int *verts); 302 303 304 // Draws a point into the current canvas in the current color and drawmode. 305 void gr_pixel(int x,int y); 306 void gr_upixel(int x,int y); 307 308 // Gets a pixel; 309 unsigned char gr_gpixel( grs_bitmap * bitmap, int x, int y ); 310 unsigned char gr_ugpixel( grs_bitmap * bitmap, int x, int y ); 311 312 // Draws a line into the current canvas in the current color and drawmode. 313 int gr_line(fix x0,fix y0,fix x1,fix y1); 314 int gr_uline(fix x0,fix y0,fix x1,fix y1); 315 316 // Draws an anti-aliased line into the current canvas in the current color and drawmode. 317 int gr_aaline(fix x0,fix y0,fix x1,fix y1); 318 int gr_uaaline(fix x0,fix y0,fix x1,fix y1); 319 320 // Draw the bitmap into the current canvas at the specified location. 321 void gr_bitmap(int x,int y,grs_bitmap *bm); 322 void gr_ubitmap(int x,int y,grs_bitmap *bm); 323 void gr_bitmap_scale_to(grs_bitmap *src, grs_bitmap *dst); 324 void show_fullscr(grs_bitmap *bm); 325 326 // bitmap function with transparency 327 void gr_bitmapm( int x, int y, grs_bitmap *bm ); 328 void gr_ubitmapm( int x, int y, grs_bitmap *bm ); 329 330 // Draw a rectangle into the current canvas. 331 void gr_rect(int left,int top,int right,int bot); 332 void gr_urect(int left,int top,int right,int bot); 333 334 // Draw a filled circle 335 int gr_disk(fix x,fix y,fix r); 336 int gr_udisk(fix x,fix y,fix r); 337 338 // Draw an outline circle 339 int gr_circle(fix x,fix y,fix r); 340 int gr_ucircle(fix x,fix y,fix r); 341 342 // Draw an unfilled rectangle into the current canvas 343 void gr_box(int left,int top,int right,int bot); 344 void gr_ubox(int left,int top,int right,int bot); 345 346 void gr_scanline( int x1, int x2, int y ); 347 void gr_uscanline( int x1, int x2, int y ); 348 349 350 // Reads in a font file... current font set to this one. 351 grs_font * gr_init_font( char * fontfile ); 352 void gr_close_font( grs_font * font ); 353 354 //remap a font, re-reading its data & palette 355 void gr_remap_font( grs_font *font, char * fontname, char *font_data ); 356 357 //remap (by re-reading) all the color fonts 358 void gr_remap_color_fonts(); 359 360 // Writes a string using current font. Returns the next column after last char. 361 void gr_set_fontcolor( int fg, int bg ); 362 void gr_set_curfont( grs_font * new ); 363 int gr_string(int x, int y, char *s ); 364 int gr_ustring(int x, int y, char *s ); 365 int gr_printf( int x, int y, char * format, ... ); 366 int gr_uprintf( int x, int y, char * format, ... ); 367 void gr_get_string_size(char *s, int *string_width, int *string_height, int *average_width ); 368 369 370 // From roller.c 371 void rotate_bitmap(grs_bitmap *bp, grs_point *vertbuf, int light_value); 372 373 // From scale.c 374 void scale_bitmap(grs_bitmap *bp, grs_point *vertbuf, int orientation ); 375 376 //=========================================================================== 377 // Global variables 378 extern grs_canvas *grd_curcanv; //active canvas 379 extern grs_screen *grd_curscreen; //active screen 380 extern unsigned char Test_bitmap_data[64*64]; 381 382 //shortcut to look at current font 383 #define grd_curfont grd_curcanv->cv_font 384 385 extern unsigned int FixDivide( unsigned int x, unsigned int y ); 386 387 extern void gr_show_canvas( grs_canvas *canv ); 388 extern void gr_set_current_canvas( grs_canvas *canv ); 389 390 //flags for fonts 391 #define FT_COLOR 1 392 #define FT_PROPORTIONAL 2 393 #define FT_KERNED 4 394 395 extern void gr_vesa_update( grs_bitmap * source1, grs_bitmap * dest, grs_bitmap * source2 ); 396 397 // Special effects 398 extern void gr_snow_out(int num_dots); 399 400 extern void test_rotate_bitmap(void); 401 extern void rotate_bitmap(grs_bitmap *bp, grs_point *vertbuf, int light_value); 402 403 extern ubyte gr_palette[256*3]; 404 extern ubyte gr_fade_table[256*GR_FADE_LEVELS]; 405 extern ubyte gr_inverse_table[32*32*32]; 406 407 extern ushort gr_palette_selector; 408 extern ushort gr_inverse_table_selector; 409 extern ushort gr_fade_table_selector; 410 411 // Remaps a bitmap into the current palette. If transparent_color is 412 // between 0 and 255 then all occurances of that color are mapped to 413 // whatever color the 2d uses for transparency. This is normally used 414 // right after a call to iff_read_bitmap like this: 415 // iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal); 416 // if (iff_error != IFF_NO_ERROR) Error("Can't load IFF file <%s>, error=%d",filename,iff_error); 417 // if ( iff_has_transparency ) 418 // gr_remap_bitmap( new, newpal, iff_transparent_color ); 419 // else 420 // gr_remap_bitmap( new, newpal, -1 ); 421 extern void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color ); 422 423 // Same as above, but searches using gr_find_closest_color which uses 424 // 18-bit accurracy instead of 15bit when translating colors. 425 extern void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color ); 426 427 extern void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq ); 428 429 extern void gr_palette_step_up( int r, int g, int b ); 430 431 extern void gr_bitmap_check_transparency( grs_bitmap * bmp ); 432 433 // Allocates a selector that has a base address at 'address' and length 'size'. 434 // Returns 0 if successful... BE SURE TO CHECK the return value since there 435 // is a limited number of selectors available!!! 436 extern int get_selector( void * address, int size, unsigned int * selector ); 437 438 // Assigns a selector to a bitmap. Returns 0 if successful. BE SURE TO CHECK 439 // this return value since there is a limited number of selectors!!!!!!! 440 extern int gr_bitmap_assign_selector( grs_bitmap * bmp ); 441 442 //#define GR_GETCOLOR(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )]) 443 //#define gr_getcolor(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )]) 444 //#define BM_XRGB(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )]) 445 446 #define BM_RGB(r,g,b) ( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) ) 447 #define BM_XRGB(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 ) 448 #define GR_GETCOLOR(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 ) 449 #define gr_getcolor(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 ) 450 451 // Given: r,g,b, each in range of 0-63, return the color index that 452 // best matches the input. 453 int gr_find_closest_color( int r, int g, int b ); 454 int gr_find_closest_color_15bpp( int rgb ); 455 456 extern void gr_merge_textures( ubyte * lower, ubyte * upper, ubyte * dest ); 457 extern void gr_merge_textures_1( ubyte * lower, ubyte * upper, ubyte * dest ); 458 extern void gr_merge_textures_2( ubyte * lower, ubyte * upper, ubyte * dest ); 459 extern void gr_merge_textures_3( ubyte * lower, ubyte * upper, ubyte * dest ); 460 461 extern void gr_update(void); 462 463 /* 464 * currently SDL and OGL are the only things that supports toggling 465 * fullscreen. otherwise add other checks to the #if -MPM 466 */ 467 #if (defined(SDL_VIDEO) || defined(OGL)) 468 #define GR_SUPPORTS_FULLSCREEN_TOGGLE 469 470 /* 471 * must return 0 if windowed, 1 if fullscreen 472 */ 473 int gr_check_fullscreen(void); 474 475 /* 476 * returns state after toggling (ie, same as if you had called 477 * check_fullscreen immediatly after) 478 */ 479 int gr_toggle_fullscreen(void); 480 481 #endif 482 483 int gr_toggle_fullscreen_menu(void);//returns state after toggling (ie, same as if you had called check_fullscreen immediatly after) 484 485 #endif 486