]> icculus.org git repositories - taylor/freespace2.git/blob - include/2d.h
fix issue with looping audio streams
[taylor/freespace2.git] / include / 2d.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Graphics/2d.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file for 2d primitives.
16  *
17  * $Log$
18  * Revision 1.4  2005/03/29 23:52:10  taylor
19  * have gr_set_bitmap() use default options again so we don't have to always specify them (copied from fs2_open)
20  *
21  * Revision 1.3  2004/09/20 01:31:44  theoddone33
22  * GCC 3.4 fixes.
23  *
24  * Revision 1.2  2002/06/09 04:41:12  relnev
25  * added copyright header
26  *
27  * Revision 1.1.1.1  2002/05/03 03:28:12  root
28  * Initial import.
29  *
30  * 
31  * 16    8/30/99 5:01p Dave
32  * Made d3d do less state changing in the nebula. Use new chat server for
33  * PXO.
34  * 
35  * 15    8/16/99 9:45a Jefff
36  * changes to cursor management to allow a 2nd temporary cursor
37  * 
38  * 14    7/15/99 3:07p Dave
39  * 32 bit detection support. Mouse coord commandline.
40  * 
41  * 13    7/14/99 9:42a Dave
42  * Put in clear_color debug function. Put in base for 3dnow stuff / P3
43  * stuff
44  * 
45  * 12    7/09/99 9:51a Dave
46  * Added thick polyline code.
47  * 
48  * 11    6/29/99 10:35a Dave
49  * Interface polygon bitmaps! Whee!
50  * 
51  * 10    2/03/99 11:44a Dave
52  * Fixed d3d transparent textures.
53  * 
54  * 9     1/30/99 5:08p Dave
55  * More new hi-res stuff.Support for nice D3D textures.
56  * 
57  * 8     1/24/99 11:36p Dave
58  * First full rev of beam weapons. Very customizable. Removed some bogus
59  * Int3()'s in low level net code.
60  * 
61  * 7     12/21/98 5:02p Dave
62  * Modified all hud elements to be multi-resolution friendly.
63  * 
64  * 6     12/18/98 1:49a Dave
65  * Fixed Fred initialization problem resulting from hi-res mode changes.
66  * 
67  * 5     12/18/98 1:13a Dave
68  * Rough 1024x768 support for Direct3D. Proper detection and usage through
69  * the launcher.
70  * 
71  * 4     12/06/98 2:36p Dave
72  * Drastically improved nebula fogging.
73  * 
74  * 3     11/11/98 5:37p Dave
75  * Checkin for multiplayer testing.
76  * 
77  * 2     10/07/98 10:52a Dave
78  * Initial checkin.
79  * 
80  * 1     10/07/98 10:48a Dave
81  * 
82  * 75    5/20/98 9:45p John
83  * added code so the places in code that change half the palette don't
84  * have to clear the screen.
85  * 
86  * 74    5/06/98 5:30p John
87  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
88  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
89  * DirectX header files and libs that fixed the Direct3D alpha blending
90  * problems.
91  * 
92  * 73    4/14/98 12:15p John
93  * Made 16-bpp movies work.
94  * 
95  * 72    4/10/98 5:20p John
96  * Changed RGB in lighting structure to be ubytes.  Removed old
97  * not-necessary 24 bpp software stuff.
98  * 
99  * 71    3/25/98 8:07p John
100  * Restructured software rendering into two modules; One for windowed
101  * debug mode and one for DirectX fullscreen.   
102  * 
103  * 70    3/24/98 8:31a John
104  * Added function to set gamma
105  * 
106  * 69    3/17/98 5:55p John
107  * Added code to dump Glide frames.   Moved Allender's  "hack" code out of
108  * Freespace.cpp into the proper place, graphics lib.
109  * 
110  * 68    3/12/98 5:36p John
111  * Took out any unused shaders.  Made shader code take rgbc instead of
112  * matrix and vector since noone used it like a matrix and it would have
113  * been impossible to do in hardware.   Made Glide implement a basic
114  * shader for online help.  
115  * 
116  * 67    3/10/98 4:18p John
117  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
118  * & Glide have popups and print screen.  Took out all >8bpp software
119  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
120  * support Fred.  Made zbuffering key off of functions rather than one
121  * global variable.
122  * 
123  * 66    2/07/98 7:50p John
124  * Added code so that we can use the old blending type of alphacolors if
125  * we want to.  Made the stars use them.
126  * 
127  * 65    1/08/98 1:54p John
128  * Added code to fix palette problems when Alt+Tabbing
129  * 
130  * 64    12/30/97 6:46p John
131  * Added first rev of palette fade in out functions
132  * 
133  * 63    12/03/97 10:47a John
134  * added functions to save/restore entire screens.
135  * 
136  * 62    12/02/97 3:59p John
137  * Added first rev of thruster glow, along with variable levels of
138  * translucency, which retquired some restructing of palman.
139  * 
140  * 61    11/20/97 9:51a John
141  * added code to force screen to 16-bit even if rendering 8.
142  * 
143  * 60    11/03/97 10:08p Hoffoss
144  * Changed gr_get_string_size to utilize an optional length specifier, if
145  * you want to use non-null terminated strings.
146  * 
147  * 59    10/19/97 12:55p John
148  * new code to lock / unlock surfaces for smooth directx integration.
149  * 
150  * 58    10/03/97 10:02a John
151  * added better comments for lines.
152  * 
153  * 57    10/03/97 9:10a John
154  * added better antialiased line drawer
155  * 
156  * 56    9/23/97 10:45a John
157  * made so you can tell bitblt code to rle a bitmap by passing flag to
158  * gr_set_bitmap
159  * 
160  * 55    9/07/97 10:01p Lawrance
161  * add in support for animating mouse pointer
162  * 
163  * 54    8/04/97 4:47p John
164  * added gr_aascaler.
165  * 
166  * 53    7/16/97 3:07p John
167  * 
168  * 52    7/10/97 2:06p John
169  * added code to specify alphablending type for bitmaps.
170  * 
171  * 51    6/25/97 2:35p John
172  * added some functions to use the windows font for Fred.
173  * 
174  * 50    6/17/97 7:04p John
175  * added d3d support for gradients.
176  * fixed some color bugs by adding screen signatures instead of watching
177  * flags and palette changes.
178  * 
179  * 49    6/17/97 12:03p John
180  * Moved color/alphacolor functions into their own module.  Made all color
181  * functions be part of the low-level graphics drivers, not just the
182  * grsoft.
183  * 
184  * 48    6/13/97 5:35p John
185  * added some antialiased bitmaps and lines
186  * 
187  * 47    6/11/97 5:49p John
188  * Changed palette code to only recalculate alphacolors when needed, not
189  * when palette changes.
190  * 
191  * 46    6/11/97 4:11p John
192  * addec function to get font height
193  * 
194  * 45    6/11/97 1:12p John
195  * Started fixing all the text colors in the game.
196  * 
197  * 44    6/09/97 9:24a John
198  * Changed the way fonts are set.
199  * 
200  * 43    6/06/97 4:41p John
201  * Fixed alpha colors to be smoothly integrated into gr_set_color_fast
202  * code.
203  * 
204  * 42    6/05/97 4:53p John
205  * First rev of new antialiased font stuff.
206  * 
207  * 41    5/29/97 3:09p John
208  * Took out debug menu.  
209  * Made software scaler draw larger bitmaps.
210  * Optimized Direct3D some.
211  * 
212  * 40    5/14/97 10:53a John
213  * fixed some discrepencies between d3d and software palette setting.
214  * 
215  * 39    5/12/97 3:09p John
216  * fixed a stupid macro bug.
217  * 
218  * 38    5/12/97 12:27p John
219  * Restructured Graphics Library to add support for multiple renderers.
220  * 
221  * 37    4/28/97 4:46p John
222  * 
223  * 36    4/23/97 5:26p John
224  * First rev of new debug console stuff.
225  * 
226  * 35    3/12/97 2:51p John
227  * Added some test code for tmapper.  
228  * 
229  * 34    3/12/97 9:25a John
230  * fixed a bug with zbuffering.  Reenabled it by default.
231  * 
232  * 33    3/04/97 3:36p John
233  * took out old debug "h' key.   Made zbuffer flag bit bit field so you
234  * can turn on/off each value.   Fixed a bug with turret rotation where
235  * different handedness turrets wouldn't work.   Fixed a bug with two
236  * large ships within each other's radius not rendering correctly.
237  * 
238  * 32    1/27/97 9:08a John
239  * Added code to turn zbuffering on/off in call to g3_start_frame
240  * 
241  * 31    1/09/97 11:35a John
242  * Added some 2d functions to get/put screen images.
243  * 
244  * 30    1/07/97 2:01p John
245  * Fairly fast zbuffering for object sorting.
246  * 
247  * 29    1/06/97 2:44p John
248  * Added in slow (but correct) zbuffering
249  * 
250  * 28    12/11/96 12:41p John
251  * Added new code to draw 3d laser using 2d ellipses.
252  * 
253  * 27    12/10/96 10:37a John
254  * Restructured texture mapper to remove some overhead from each scanline
255  * setup.  This gave about a 30% improvement drawing trans01.pof, which is
256  * a really complex model.  In the process, I cleaned up the scanline
257  * functions and separated them into different modules for each pixel
258  * depth.   
259  * 
260  * 26    11/21/96 11:21a John
261  * Made gr_get_string_size handle multi line text.
262  * Took out gr_get_multiline_string_size
263  * 
264  * 25    11/20/96 10:01a Hoffoss
265  * A few minor improvements.
266  * 
267  * 24    11/18/96 4:35p Allender
268  * new 16bpp gradient functions
269  * 
270  * 23    11/18/96 12:36p John
271  * Added code to dump screen to a PCX file.
272  * 
273  * 22    11/18/96 11:40a John
274  * Added faster gr_set_color method.
275  * 
276  * 21    11/15/96 3:34p Allender
277  * added bpp variable to the shader structure
278  * 
279  * 20    11/13/96 6:47p John
280  * Added gr_flip function.
281  * 
282  * 19    11/13/96 10:10a John
283  * Increases MAX_WIDTH & HEIGHT for Jasen's massive 1600x1200 display.
284  * 
285  * 18    10/30/96 10:36a Lawrance
286  * added gr_diamond function
287  * 
288  * 17    10/26/96 2:56p John
289  * Got gradient code working.
290  * 
291  * 16    10/26/96 1:40p John
292  * Added some now primitives to the 2d library and
293  * cleaned up some old ones.
294  *
295  * $NoKeywords: $
296  */
297
298 #ifndef _GRAPHICS_H
299 #define _GRAPHICS_H
300
301 /* ========================= pixel plotters =========================
302 In the 2d/texture mapper, bitmaps to be drawn will be passed by number.
303 The 2d function will call a bmpman function to get the bitmap into whatever
304 format it needs.  Then it will render.   The only pixels that will ever 
305 get drawn go thru the 2d/texture mapper libraries only.   This will make
306 supporting accelerators and psx easier.   Colors will always be set with
307 the color set functions.
308
309 gr_surface_flip()       switch onscreen, offscreen
310
311 gr_set_clip(x,y,w,h)    // sets the clipping region
312 gr_reset_clip(x,y,w,h)  // sets the clipping region
313 gr_set_color --? 8bpp, 15bpp?
314 gr_set_font(int fontnum)
315 // see GR_ALPHABLEND defines for values for alphablend_mode
316 // see GR_BITBLT_MODE defines for bitblt_mode.
317 // Alpha = scaler for intensity
318 gr_set_bitmap( int bitmap_num, int alphblend_mode, int bitblt_mode, float alpha )       
319 gr_set_shader( int value )  0=normal -256=darken, 256=brighten
320 gr_set_palette( ubyte * palette ) 
321
322 gr_clear()      // clears entire clipping region
323 gr_bitmap(x,y)
324 gr_bitmap_ex(x,y,w,h,sx,sy)
325 gr_rect(x,y,w,h)
326 gr_shade(x,y,w,h)
327 gr_string(x,y,char * text)
328 gr_line(x1,y1,x2,y2)
329
330  
331 */
332
333 #include "pstypes.h"
334 #include "tmapper.h"
335
336 // This is a structure used by the shader to keep track
337 // of the values you want to use in the shade primitive.
338 typedef struct shader {
339         uint    screen_sig;                                     // current mode this is in
340         float   r,g,b,c;                                                // factors and constant
341         ubyte   lookup[256];
342 } shader;
343
344 #define AC_TYPE_NONE            0               // Not an alphacolor
345 #define AC_TYPE_HUD             1               // Doesn't change hue depending on background.  Used for HUD stuff.
346 #define AC_TYPE_BLEND   2               // Changes hue depending on background.  Used for stars, etc.
347
348 // NEVER REFERENCE THESE VALUES OUTSIDE OF THE GRAPHICS LIBRARY!!!
349 // If you need to get the rgb values of a "color" struct call
350 // gr_get_colors after calling gr_set_colors_fast.
351 typedef struct color {
352         uint            screen_sig;
353         ubyte           red;
354         ubyte           green;
355         ubyte           blue;
356         ubyte           alpha;
357         ubyte           ac_type;                                                        // The type of alphacolor.  See AC_TYPE_??? defines
358         int             is_alphacolor;
359         ubyte           raw8;
360         int             alphacolor;
361         int             magic;          
362 } color;
363
364 #define GR_ALPHABLEND_NONE                      0               // no blending
365 #define GR_ALPHABLEND_FILTER            1               // 50/50 mix of foreground, background, using intensity as alpha
366
367 #define GR_BITBLT_MODE_NORMAL           0               // Normal bitblting
368 #define GR_BITBLT_MODE_RLE                      1               // RLE would be faster
369
370 // fog modes
371 #define GR_FOGMODE_NONE                         0               // set this to turn off fog
372 #define GR_FOGMODE_FOG                          1               // linear fog
373
374 typedef struct screen {
375         uint    signature;                      // changes when mode or palette or width or height changes
376         int     max_w, max_h;           // Width and height
377         int     res;                                    // GR_640 or GR_1024
378         int     mode;                                   // What mode gr_init was called with.
379         int use_sections;                       // whether to use bitmap sections or not
380         float   aspect;                         // Aspect ratio
381         int     bits_per_pixel; // How many bits per pixel it is. (7,8,15,16,24,32)
382         int     bytes_per_pixel;        // How many bytes per pixel (1,2,3,4)
383         int     offset_x, offset_y;             // The offsets into the screen
384         int     clip_width, clip_height;
385         int fullscreen;
386         int viewport_offset_x;
387         int viewport_offset_y;
388         float viewport_scale_factor_x;
389         float viewport_scale_factor_y;
390
391         float fog_near, fog_far;
392
393         // the clip_l,r,t,b are used internally.  left and top are
394         // actually always 0, but it's nice to have the code work with
395         // arbitrary clipping regions.
396         int             clip_left, clip_right, clip_top, clip_bottom;   
397
398         int             current_alphablend_mode;                // See GR_ALPHABLEND defines above
399         int             current_bitblt_mode;                            // See GR_BITBLT_MODE defines above
400         int             current_fog_mode;                                       // See GR_FOGMODE_* defines above
401         int             current_bitmap;
402         int             current_bitmap_sx;                              // bitmap x section
403         int             current_bitmap_sy;                              // bitmap y section
404         color           current_color;
405         color           current_fog_color;                              // current fog color
406         color           current_clear_color;                            // current clear color
407         shader  current_shader;
408         float           current_alpha;
409
410         //switch onscreen, offscreen
411         void (*gf_flip)();
412
413         // Fade the screen in/out
414         void (*gf_fade_in)(int instantaneous);
415         void (*gf_fade_out)(int instantaneous);
416
417         // Flash the screen
418         void (*gf_flash)( int r, int g, int b );
419
420         // sets the clipping region
421         void (*gf_set_clip)(int x, int y, int w, int h);
422
423         // resets the clipping region to entire screen
424         void (*gf_reset_clip)();
425
426         // clears entire clipping region to current color
427         void (*gf_clear)();
428
429         void (*gf_aabitmap)(int x, int y);
430         void (*gf_aabitmap_ex)(int x, int y, int w, int h, int sx, int sy);
431
432         void (*gf_rect)(int x, int y, int w, int h);
433         void (*gf_shade)(int x, int y, int w, int h);
434         void (*gf_string)(int x, int y, const char * text);
435
436         // Draw a gradient line... x1,y1 is bright, x2,y2 is transparent.
437         void (*gf_gradient)(int x1, int y1, int x2, int y2);
438  
439         void (*gf_circle)(int x, int y, int r);
440
441         // Integer line. Used to draw a fast but pixely line.  
442         void (*gf_line)(int x1, int y1, int x2, int y2);
443
444         // Draws an antialiased line is the current color is an 
445         // alphacolor, otherwise just draws a fast line.  This
446         // gets called internally by g3_draw_line.   This assumes
447         // the vertex's are already clipped, so call g3_draw_line
448         // not this if you have two 3d points.
449         void (*gf_aaline)(vertex *v1, vertex *v2);
450
451         void (*gf_pixel)( int x, int y );
452
453         // Scales current bitmap between va and vb with clipping
454         void (*gf_scaler)(vertex *va, vertex *vb );
455
456         // Scales current bitmap between va and vb with clipping, draws an aabitmap
457         void (*gf_aascaler)(vertex *va, vertex *vb );
458
459         // Texture maps the current bitmap.  See TMAP_FLAG_?? defines for flag values
460         void (*gf_tmapper)(int nv, vertex *verts[], uint flags );
461
462         // dumps the current screen to a file
463         void (*gf_print_screen)(const char * filename);
464
465         // Call once before rendering anything.
466         void (*gf_start_frame)();
467
468         // Call after rendering is over.
469         void (*gf_stop_frame)();
470
471         // Clears the zbuffer.  If use_zbuffer is FALSE, then zbuffering mode is ignored and zbuffer is always off.
472         void (*gf_zbuffer_clear)(int use_zbuffer);
473         
474         // Saves screen. Returns an id you pass to restore and free.
475         int (*gf_save_screen)();
476         
477         // Resets clip region and copies entire saved screen to the screen.
478         void (*gf_restore_screen)(int id);
479
480         // Frees up a saved screen.
481         void (*gf_free_screen)(int id);
482
483         // CODE FOR DUMPING FRAMES TO A FILE
484         // Begin frame dumping
485         void (*gf_dump_frame_start)( int first_frame_number, int nframes_between_dumps );
486
487         // Dump the current frame to file
488         void (*gf_dump_frame)();
489
490         // Dump the current frame to file
491         void (*gf_dump_frame_stop)();
492
493         // Begin video stream
494         void (*gf_stream_start)(int x, int y, int w, int h);
495
496         // Process frame of video stream
497         void (*gf_stream_frame)(ubyte *frame);
498
499         // Stop video stream
500         void (*gf_stream_stop)();
501
502         // Sets the gamma
503         void (*gf_set_gamma)(float gamma);
504
505         // Lock/unlock the screen
506         // Returns non-zero if sucessful (memory pointer)
507         uint (*gf_lock)();
508         void (*gf_unlock)();
509
510         // grab a region of the screen. assumes data is large enough
511         void (*gf_get_region)(int front, int w, int h, ubyte *data);
512
513         // set fog attributes
514         void (*gf_fog_set)(int fog_mode, int r, int g, int b, float fog_near, float fog_far);   
515
516         // poly culling
517         void (*gf_set_cull)(int cull);
518
519         // cross fade
520         void (*gf_cross_fade)(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct);
521
522         void (*gf_preload_init)();
523         int (*gf_preload)(int bitmap_num, int is_aabitmap);
524
525         void (*gf_zbias)(int bias);
526
527         void (*gf_set_viewport)(int width, int height);
528
529         void (*gf_activate)(int active);
530
531         void (*gf_release_texture)(int handle);
532 } screen;
533
534 // handy macro
535 #define GR_MAYBE_CLEAR_RES(bmap)                do  { int bmw = -1; int bmh = -1; if(bmap != -1){ bm_get_info( bmap, &bmw, &bmh); if((bmw != gr_screen.max_w) || (bmh != gr_screen.max_h)){gr_clear();} } else {gr_clear();} } while(0);
536
537 //Window's interface to set up graphics:
538 //--------------------------------------
539 // Call this at application startup
540
541 #define GR_OPENGL                               (100)           // OpenGL (generic)
542 #define GR_WXGL                                 (101)           // OpenGL for use with wxWidgets toolkit
543 #define GR_STUB                                 (102)           // Stubbed out for standalone server
544
545 // resolution constants   - always keep resolutions in ascending order and starting from 0  
546 #define GR_NUM_RESOLUTIONS                      2
547 #define GR_640                                                  0               // 640 x 480
548 #define GR_1024                                         1               // 1024 x 768
549
550 extern int gr_init();
551
552 // Call this when your app ends.
553 extern void gr_close();
554
555 extern screen gr_screen;
556
557 #define GR_ZBUFF_NONE   0
558 #define GR_ZBUFF_WRITE  (1<<0)
559 #define GR_ZBUFF_READ   (1<<1)
560 #define GR_ZBUFF_FULL   (GR_ZBUFF_WRITE|GR_ZBUFF_READ)
561
562 // Returns -1 if couldn't init font, otherwise returns the
563 // font id number.  If you call this twice with the same typeface,
564 // it will return the same font number both times.  This font is
565 // then set to be the current font, and default font if none is 
566 // yet specified.
567 int gr_init_font( const char * typeface );
568
569 // Does formatted printing.  This calls gr_string after formatting,
570 // so if you don't need to format the string, then call gr_string
571 // directly.
572 extern void __cdecl gr_printf( int x, int y, const char * format, ... );
573
574 // Returns the size of the string in pixels in w and h
575 extern void gr_get_string_size( int *w, int *h, const char * text, int len = 9999 );
576
577 // Returns the height of the current font
578 extern int gr_get_font_height();
579
580 extern void gr_set_palette(const char *name, ubyte *palette, int restrict_to_128 = 0);
581
582 // These two functions use a Windows mono font.  Only for use
583 // in the editor, please.
584 void gr_get_string_size_win(int *w, int *h, const char *text);
585 void gr_string_win(int x, int y, const char *s );
586
587 // set the mouse pointer to a specific bitmap, used for animating cursors
588 #define GR_CURSOR_LOCK          1
589 #define GR_CURSOR_UNLOCK        2
590 void gr_set_cursor_bitmap(int n, int lock = 0);
591 int gr_get_cursor_bitmap();
592 extern int Web_cursor_bitmap;
593
594 // Called by OS when application gets/looses focus
595 extern void gr_activate(int active);
596
597 #define GR_CALL(x)                      (*x)
598
599 // These macros make the function indirection look like the
600 // old Descent-style gr_xxx calls.
601
602 #define gr_print_screen         GR_CALL(gr_screen.gf_print_screen)
603
604 #define gr_flip                         GR_CALL(gr_screen.gf_flip)
605
606 #define gr_set_clip                     GR_CALL(gr_screen.gf_set_clip)
607 #define gr_reset_clip           GR_CALL(gr_screen.gf_reset_clip)
608
609 void gr_set_color_fast(color *dst);
610 void gr_get_color(int *r, int *g, int *b);
611 void gr_get_colorf(float *r, float *g, float *b, float *a);
612 void gr_init_color(color *c, int r, int g, int b);
613 void gr_init_alphacolor(color *clr, int r, int g, int b, int alpha, int type);
614 void gr_set_color(int r, int g, int b);
615
616 // Sets the current bitmap
617 void gr_set_bitmap(int bitmap_num, int alphablend = GR_ALPHABLEND_NONE, int bitbltmode = GR_BITBLT_MODE_NORMAL, float alpha = 1.0f, int sx = -1, int sy = -1);
618
619 __inline bool gr_is_32bit()
620 {
621         return (gr_screen.bytes_per_pixel == 4);
622 }
623
624 #define gr_clear                                GR_CALL(gr_screen.gf_clear)
625
626 // Call this to create a shader.
627 // This function takes a while, so don't call it once a frame!
628 // r,g,b, and c should be between -1.0 and 1.0f
629
630 // The matrix is used as follows:
631 // Dest(r) = Src(r)*r + Src(g)*r + Src(b)*r + c;
632 // Dest(g) = Src(r)*g + Src(g)*g + Src(b)*g + c;
633 // Dest(b) = Src(r)*b + Src(g)*b + Src(b)*b + c;
634 // For instance, to convert to greyscale, use
635 // .3 .3 .3  0
636 // To turn everything green, use:
637 //  0 .3  0  0
638 void gr_create_shader(shader *shade, float r, float g, float b, float c);
639
640 // Initialize the "shader" by calling gr_create_shader()
641 // Passing a NULL makes a shader that turns everything black.
642 void gr_set_shader(shader *shade);
643
644 #define gr_aabitmap                     GR_CALL(gr_screen.gf_aabitmap)
645 #define gr_aabitmap_ex          GR_CALL(gr_screen.gf_aabitmap_ex)
646 #define gr_rect                         GR_CALL(gr_screen.gf_rect)
647 #define gr_shade                                GR_CALL(gr_screen.gf_shade)
648 #define gr_string                               GR_CALL(gr_screen.gf_string)
649
650 #define gr_circle                               GR_CALL(gr_screen.gf_circle)
651
652 #define gr_line                         GR_CALL(gr_screen.gf_line)
653 #define gr_aaline                               GR_CALL(gr_screen.gf_aaline)
654 #define gr_pixel                                GR_CALL(gr_screen.gf_pixel)
655 #define gr_scaler                               GR_CALL(gr_screen.gf_scaler)
656 #define gr_aascaler                     GR_CALL(gr_screen.gf_aascaler)
657 #define gr_tmapper                      GR_CALL(gr_screen.gf_tmapper)
658
659 #define gr_gradient                     GR_CALL(gr_screen.gf_gradient)
660
661
662 #define gr_fade_in                      GR_CALL(gr_screen.gf_fade_in)
663 #define gr_fade_out                     GR_CALL(gr_screen.gf_fade_out)
664 #define gr_flash                                GR_CALL(gr_screen.gf_flash)
665
666
667 // Retrieves the zbuffer mode.
668 int gr_zbuffer_get();
669
670 // Sets mode.  Returns previous mode.
671 int gr_zbuffer_set(int mode);
672
673 #define gr_zbuffer_clear        GR_CALL(gr_screen.gf_zbuffer_clear)
674
675
676 #define gr_save_screen          GR_CALL(gr_screen.gf_save_screen)
677 #define gr_restore_screen       GR_CALL(gr_screen.gf_restore_screen)
678 #define gr_free_screen          GR_CALL(gr_screen.gf_free_screen)
679
680 #define gr_dump_frame_start     GR_CALL(gr_screen.gf_dump_frame_start)
681 #define gr_dump_frame_stop              GR_CALL(gr_screen.gf_dump_frame_stop)
682 #define gr_dump_frame                   GR_CALL(gr_screen.gf_dump_frame)
683
684 #define gr_stream_start         GR_CALL(gr_screen.gf_stream_start)
685 #define gr_stream_frame         GR_CALL(gr_screen.gf_stream_frame)
686 #define gr_stream_stop          GR_CALL(gr_screen.gf_stream_stop)
687
688 void gr_set_gamma(float gamma);
689
690 #define gr_lock                         GR_CALL(gr_screen.gf_lock)
691 #define gr_unlock                               GR_CALL(gr_screen.gf_unlock)
692
693 #define gr_get_region           GR_CALL(gr_screen.gf_get_region)
694
695 #define gr_fog_set                      GR_CALL(gr_screen.gf_fog_set)
696
697 #define gr_set_cull                     GR_CALL(gr_screen.gf_set_cull)
698
699 #define gr_cross_fade           GR_CALL(gr_screen.gf_cross_fade)
700
701 // set the color to be used when clearing the background
702 void gr_set_clear_color(int r, int g, int b);
703
704 #define gr_preload_init         GR_CALL(gr_screen.gf_preload_init)
705 #define gr_preload                      GR_CALL(gr_screen.gf_preload)
706
707 #define gr_zbias                        GR_CALL(gr_screen.gf_zbias)
708
709 #define gr_set_viewport         GR_CALL(gr_screen.gf_set_viewport)
710
711 #define gr_release_texture      GR_CALL(gr_screen.gf_release_texture)
712
713 void gr_force_fullscreen();
714 void gr_force_windowed();
715 void gr_toggle_fullscreen();
716
717 // new bitmap functions
718 void gr_bitmap(int x, int y);
719
720 // special function for drawing polylines. this function is specifically intended for
721 // polylines where each section is no more than 90 degrees away from a previous section.
722 // Moreover, it is _really_ intended for use with 45 degree angles. 
723 void gr_pline_special(vector **pts, int num_pts, int thickness);
724
725 // return next power-of-2
726 inline int next_pow2(int p)
727 {
728         if (p < 0)
729                 return 0;
730
731         --p;
732         p |= p >> 1;
733         p |= p >> 2;
734         p |= p >> 4;
735         p |= p >> 8;
736         p |= p >> 16;
737
738         return p+1;
739 }
740
741 inline int is_pow2(int p)
742 {
743         return (p && !(p & (p-1)));
744 }
745
746 #endif
747