]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/gropengl.cpp
update opengl stubs
[taylor/freespace2.git] / src / graphics / gropengl.cpp
1 /*
2  * $Logfile: /Freespace2/code/Graphics/GrOpenGL.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Code that uses the OpenGL graphics library
8  *
9  * $Log$
10  * Revision 1.8  2002/05/29 03:30:05  relnev
11  * update opengl stubs
12  *
13  * Revision 1.7  2002/05/29 02:52:32  theoddone33
14  * Enable OpenGL renderer
15  *
16  * Revision 1.6  2002/05/28 04:56:51  theoddone33
17  * runs a little bit now
18  *
19  * Revision 1.5  2002/05/28 04:07:28  theoddone33
20  * New graphics stubbing arrangement
21  *
22  * Revision 1.4  2002/05/27 23:39:34  relnev
23  * 0
24  *
25  * Revision 1.3  2002/05/27 22:35:01  theoddone33
26  * more symbols
27  *
28  * Revision 1.2  2002/05/27 22:32:02  theoddone33
29  * throw all d3d stuff at opengl
30  *
31  * Revision 1.1.1.1  2002/05/03 03:28:09  root
32  * Initial import.
33  *
34  * 
35  * 10    7/14/99 9:42a Dave
36  * Put in clear_color debug function. Put in base for 3dnow stuff / P3
37  * stuff
38  * 
39  * 9     7/09/99 9:51a Dave
40  * Added thick polyline code.
41  * 
42  * 8     6/29/99 10:35a Dave
43  * Interface polygon bitmaps! Whee!
44  * 
45  * 7     2/03/99 11:44a Dave
46  * Fixed d3d transparent textures.
47  * 
48  * 6     1/24/99 11:37p Dave
49  * First full rev of beam weapons. Very customizable. Removed some bogus
50  * Int3()'s in low level net code.
51  * 
52  * 5     12/18/98 1:13a Dave
53  * Rough 1024x768 support for Direct3D. Proper detection and usage through
54  * the launcher.
55  * 
56  * 4     12/06/98 2:36p Dave
57  * Drastically improved nebula fogging.
58  * 
59  * 3     11/11/98 5:37p Dave
60  * Checkin for multiplayer testing.
61  * 
62  * 2     10/07/98 10:53a Dave
63  * Initial checkin.
64  * 
65  * 1     10/07/98 10:49a Dave
66  * 
67  * 14    5/20/98 9:46p John
68  * added code so the places in code that change half the palette don't
69  * have to clear the screen.
70  * 
71  * 13    5/06/98 5:30p John
72  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
73  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
74  * DirectX header files and libs that fixed the Direct3D alpha blending
75  * problems.
76  * 
77  * 12    4/14/98 12:15p John
78  * Made 16-bpp movies work.
79  * 
80  * 11    3/12/98 5:36p John
81  * Took out any unused shaders.  Made shader code take rgbc instead of
82  * matrix and vector since noone used it like a matrix and it would have
83  * been impossible to do in hardware.   Made Glide implement a basic
84  * shader for online help.  
85  * 
86  * 10    3/10/98 4:18p John
87  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
88  * & Glide have popups and print screen.  Took out all >8bpp software
89  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
90  * support Fred.  Made zbuffering key off of functions rather than one
91  * global variable.
92  * 
93  * 9     12/02/97 4:00p John
94  * Added first rev of thruster glow, along with variable levels of
95  * translucency, which retquired some restructing of palman.
96  * 
97  * 8     10/03/97 9:10a John
98  * added better antialiased line drawer
99  * 
100  * 7     9/23/97 10:45a John
101  * made so you can tell bitblt code to rle a bitmap by passing flag to
102  * gr_set_bitmap
103  * 
104  * 6     9/09/97 11:01a Sandeep
105  * fixed warning level 4 bugs
106  * 
107  * 5     7/10/97 2:06p John
108  * added code to specify alphablending type for bitmaps.
109  * 
110  * 4     6/17/97 7:04p John
111  * added d3d support for gradients.
112  * fixed some color bugs by adding screen signatures instead of watching
113  * flags and palette changes.
114  * 
115  * 3     6/12/97 2:50a Lawrance
116  * bm_unlock() now passed bitmap number, not pointer
117  * 
118  * 2     6/11/97 1:12p John
119  * Started fixing all the text colors in the game.
120  * 
121  * 1     5/12/97 12:14p John
122  *
123  * $NoKeywords: $
124  */
125
126 #ifndef PLAT_UNIX
127 #include <windows.h>
128 #include <windowsx.h>
129 #endif
130
131 #include "osapi.h"
132 #include "2d.h"
133 #include "bmpman.h"
134 #include "floating.h"
135 #include "palman.h"
136 #include "grinternal.h"
137 #include "gropengl.h"
138 #include "line.h"
139
140 static int Inited = 0;
141 #ifdef PLAT_UNIX
142 // Throw in some dummy functions - DDOI
143
144 int D3D_32bit = 0;              // grd3d.cpp
145 int D3D_fog_mode = -1;          // grd3d.cpp
146 int D3D_inited = 0;             // grd3d.cpp
147 int D3D_zbias = 1;              // grd3d.cpp
148 int D3d_rendition_uvs = 0;      // grd3d.cpp
149
150 void gr_dd_activate(int active)         // grdirectdraw.cpp
151 {
152         STUB_FUNCTION;
153 }
154
155 void gr_directdraw_cleanup()            // grdirectdraw.cpp
156 {
157         STUB_FUNCTION;
158 }
159
160 void gr_directdraw_force_windowed()     // grdirectdraw.cpp
161 {
162         STUB_FUNCTION;
163 }
164
165 void gr_directdraw_init()
166 {
167         STUB_FUNCTION;
168 }
169
170
171 void gr_d3d_preload(int x, int y)
172 {
173         STUB_FUNCTION;
174 }
175
176 void d3d_start_frame()
177 {
178         STUB_FUNCTION;
179 }
180
181 void d3d_stop_frame()
182 {
183         STUB_FUNCTION;
184 }
185
186 void d3d_flush ()
187 {
188         STUB_FUNCTION;
189 }
190
191 void d3d_zbias (int a)
192 {
193         STUB_FUNCTION;
194 }
195 #endif
196
197 void gr_opengl_activate(int b)
198 {
199         STUB_FUNCTION;
200 }
201
202 void gr_opengl_preload_init()
203 {
204         STUB_FUNCTION;
205 }
206
207 void gr_opengl_pixel(int x, int y)
208 {
209         if ( x < gr_screen.clip_left ) return;
210         if ( x > gr_screen.clip_right ) return;
211         if ( y < gr_screen.clip_top ) return;
212         if ( y > gr_screen.clip_bottom ) return;
213 }
214
215 void gr_opengl_clear()
216 {
217         STUB_FUNCTION;
218 }
219
220 void gr_opengl_flip()
221 {
222 #ifdef PLAT_UNIX
223         if (Inited) SDL_GL_SwapBuffers ();
224 #endif
225 }
226
227 void gr_opengl_flip_window(uint _hdc, int x, int y, int w, int h )
228 {
229         STUB_FUNCTION;
230 }
231
232 void gr_opengl_set_clip(int x,int y,int w,int h)
233 {
234         // check for sanity of parameters
235         if (x < 0)
236                 x = 0;
237         if (y < 0)
238                 y = 0;
239
240         if (x >= gr_screen.max_w)
241                 x = gr_screen.max_w - 1;
242         if (y >= gr_screen.max_h)
243                 y = gr_screen.max_h - 1;
244
245         if (x + w > gr_screen.max_w)
246                 w = gr_screen.max_w - x;
247         if (y + h > gr_screen.max_h)
248                 h = gr_screen.max_h - y;
249         
250         if (w > gr_screen.max_w)
251                 w = gr_screen.max_w;
252         if (h > gr_screen.max_h)
253                 h = gr_screen.max_h;
254         
255         gr_screen.offset_x = x;
256         gr_screen.offset_y = y;
257         gr_screen.clip_left = 0;
258         gr_screen.clip_right = w-1;
259         gr_screen.clip_top = 0;
260         gr_screen.clip_bottom = h-1;
261         gr_screen.clip_width = w;
262         gr_screen.clip_height = h;
263         
264         STUB_FUNCTION;
265 }
266
267 void gr_opengl_reset_clip()
268 {
269         gr_screen.offset_x = 0;
270         gr_screen.offset_y = 0;
271         gr_screen.clip_left = 0;
272         gr_screen.clip_top = 0;
273         gr_screen.clip_right = gr_screen.max_w - 1;
274         gr_screen.clip_bottom = gr_screen.max_h - 1;
275         gr_screen.clip_width = gr_screen.max_w;
276         gr_screen.clip_height = gr_screen.max_h;
277         
278         STUB_FUNCTION;
279 }
280
281 void gr_opengl_set_font(int fontnum)
282 {
283         STUB_FUNCTION;
284 }
285
286 void gr_opengl_set_color( int r, int g, int b )
287 {
288         Assert((r >= 0) && (r < 256));
289         Assert((g >= 0) && (g < 256));
290         Assert((b >= 0) && (b < 256));
291
292         gr_screen.current_color.red = (unsigned char)r;
293         gr_screen.current_color.green = (unsigned char)g;
294         gr_screen.current_color.blue = (unsigned char)b;
295         
296 //      STUB_FUNCTION;
297 #warning STUB_FUNCTION: gr_opengl_set_color
298 }
299
300 void gr_opengl_set_bitmap( int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha, int sx, int sy )
301 {
302         gr_screen.current_alpha = alpha;
303         gr_screen.current_alphablend_mode = alphablend_mode;
304         gr_screen.current_bitblt_mode = bitblt_mode;
305         gr_screen.current_bitmap = bitmap_num;
306
307         gr_screen.current_bitmap_sx = sx;
308         gr_screen.current_bitmap_sy = sy;
309         
310         STUB_FUNCTION;
311 }
312
313 void gr_opengl_create_shader(shader * shade, float r, float g, float b, float c )
314 {
315         shade->screen_sig = gr_screen.signature;
316         shade->r = r;
317         shade->g = g;
318         shade->b = b;
319         shade->c = c;
320         
321         STUB_FUNCTION;
322 }
323
324 void gr_opengl_set_shader( shader * shade )
325 {       
326         if ( shade )    {
327                 if (shade->screen_sig != gr_screen.signature)   {
328                         gr_create_shader( shade, shade->r, shade->g, shade->b, shade->c );
329                 }
330                 gr_screen.current_shader = *shade;
331         } else {
332                 gr_create_shader( &gr_screen.current_shader, 0.0f, 0.0f, 0.0f, 0.0f );
333         }
334         
335         STUB_FUNCTION;
336 }
337
338
339 void gr_opengl_bitmap_ex(int x,int y,int w,int h,int sx,int sy)
340 {
341         int i,j;
342         bitmap * bmp;
343         ubyte * sptr;
344
345         bmp = bm_lock( gr_screen.current_bitmap, 8, 0 );
346         sptr = (ubyte *)( bmp->data + (sy*bmp->w+sx) );
347
348 //      mprintf(( "x=%d, y=%d, w=%d, h=%d\n", x, y, w, h ));
349 //      mprintf(( "sx=%d, sy=%d, bw=%d, bh=%d\n", sx, sy, bmp->w, bmp->h ));
350
351         for (i=0; i<h; i++ )    {
352                 for ( j=0; j<w; j++ )   {
353                         gr_set_color( gr_palette[sptr[j]*3+0], gr_palette[sptr[j]*3+1], gr_palette[sptr[j]*3+2] );
354                         gr_pixel( x+j, i+y );
355                 }
356                 sptr += bmp->w;
357         }
358         bm_unlock(gr_screen.current_bitmap);
359         
360         STUB_FUNCTION;
361 }
362
363 void gr_opengl_bitmap(int x, int y)
364 {
365         int w, h;
366
367         bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
368         int dx1=x, dx2=x+w-1;
369         int dy1=y, dy2=y+h-1;
370         int sx=0, sy=0;
371
372         if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
373         if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
374         if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
375         if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
376         if ( dx2 > gr_screen.clip_right )       { dx2 = gr_screen.clip_right; }
377         if ( dy2 > gr_screen.clip_bottom )      { dy2 = gr_screen.clip_bottom; }
378
379         if ( sx < 0 ) return;
380         if ( sy < 0 ) return;
381         if ( sx >= w ) return;
382         if ( sy >= h ) return;
383
384         // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
385
386         gr_bitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);        
387 }
388
389 static void opengl_scanline(int x1,int x2,int y)
390 {
391         STUB_FUNCTION;
392 }
393
394 void gr_opengl_rect(int x,int y,int w,int h)
395 {
396         int i, swapped=0;
397         int x1 = x, x2;
398         int y1 = y, y2;
399
400         if ( w > 0 )
401                  x2 = x + w - 1;
402         else
403                  x2 = x + w + 1;
404
405         if ( h > 0 )
406                 y2 = y + h - 1;
407         else
408                 y2 = y + h + 1;
409                 
410         if ( x2 < x1 )  {
411                 int tmp;        
412                 tmp = x1;
413                 x1 = x2;
414                 x2 = tmp;
415                 w = -w;
416                 swapped = 1;
417         }
418
419         if ( y2 < y1 )  {
420                 int tmp;        
421                 tmp = y1;
422                 y1 = y2;
423                 y2 = tmp;
424                 h = -h;
425                 swapped = 1;
426         }
427
428         for (i=0; i<h; i++ )
429                 opengl_scanline( x1, x2, y1+i );
430                 
431         STUB_FUNCTION;
432 }
433
434
435 void gr_opengl_shade(int x,int y,int w,int h)
436 {
437         STUB_FUNCTION;
438 }
439
440 void opengl_mtext(int x, int y, char *s, int len )
441 {
442         STUB_FUNCTION;
443 }
444
445 void gr_opengl_string(int x,int y,char * text)
446 {
447         char *p, *p1;
448         int w, h;
449
450         p1 = text;
451         do {
452                 p = strchr( p1, '\n' );
453                 if ( p ) { 
454                         *p = 0;
455                         p++;
456                 }
457                 gr_get_string_size( &w, &h, p1 );
458
459                 if ( x == 0x8000 )
460                         opengl_mtext(gr_screen.offset_x+(gr_screen.clip_width-w)/2,y+gr_screen.offset_y,p1,strlen(p1));
461                 else
462                         opengl_mtext(gr_screen.offset_x+x,y+gr_screen.offset_y,p1,strlen(p1));
463
464                 p1 = p;
465                 if ( p1 && (strlen(p1) < 1) ) p1 = NULL;
466                 y += h;
467         } while(p1!=NULL);
468 }
469
470
471
472
473 void gr_opengl_circle( int xc, int yc, int d )
474 {
475         int p,x, y, r;
476
477         r = d/2;
478         p=3-d;
479         x=0;
480         y=r;
481
482         // Big clip
483         if ( (xc+r) < gr_screen.clip_left ) return;
484         if ( (xc-r) > gr_screen.clip_right ) return;
485         if ( (yc+r) < gr_screen.clip_top ) return;
486         if ( (yc-r) > gr_screen.clip_bottom ) return;
487
488         while(x<y)      {
489                 // Draw the first octant
490                 opengl_scanline( xc-y, xc+y, yc-x );
491                 opengl_scanline( xc-y, xc+y, yc+x );
492
493                 if (p<0) 
494                         p=p+(x<<2)+6;
495                 else    {
496                         // Draw the second octant
497                         opengl_scanline( xc-x, xc+x, yc-y );
498                         opengl_scanline( xc-x, xc+x, yc+y );
499                         p=p+((x-y)<<2)+10;
500                         y--;
501                 }
502                 x++;
503         }
504         if(x==y)        {
505                 opengl_scanline( xc-x, xc+x, yc-y );
506                 opengl_scanline( xc-x, xc+x, yc+y );
507         }
508         return;
509 }
510
511
512 void gr_opengl_line(int x1,int y1,int x2,int y2)
513 {
514         int i;
515    int xstep,ystep;
516    int dy=y2-y1;
517    int dx=x2-x1;
518    int error_term=0;
519         int clipped = 0, swapped=0;
520
521         INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1);
522                 
523         if(dy<0)        {
524                 dy=-dy;
525       ystep=-1;
526         }       else    {
527       ystep=1;
528         }
529
530    if(dx<0)     {
531       dx=-dx;
532       xstep=-1;
533    } else {
534       xstep=1;
535         }
536
537         if(dx>dy)       {
538
539                 for(i=dx+1;i>0;i--) {
540                         gr_pixel( x1, y1 ); 
541                         x1 += xstep;
542          error_term+=dy;
543
544          if(error_term>dx)      {
545                                 error_term-=dx;
546             y1+=ystep;
547          }
548       }
549    } else {
550
551       for(i=dy+1;i>0;i--)       {
552                         gr_pixel( x1, y1 ); 
553                         y1 += ystep;
554          error_term+=dx;
555          if(error_term>0)       {
556             error_term-=dy;
557             x1+=xstep;
558          }
559
560       }
561
562    }
563    
564    STUB_FUNCTION;
565 }
566
567 #define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0))
568
569 void gr_opengl_scaler(vertex *va, vertex *vb )
570 {
571         float x0, y0, x1, y1;
572         float u0, v0, u1, v1;
573         float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
574         float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
575         float xmin, xmax, ymin, ymax;
576         int dx0, dy0, dx1, dy1;
577
578         //============= CLIP IT =====================
579
580         x0 = va->sx; y0 = va->sy;
581         x1 = vb->sx; y1 = vb->sy;
582
583         xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top);
584         xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom);
585
586         u0 = va->u; v0 = va->v;
587         u1 = vb->u; v1 = vb->v;
588
589         // Check for obviously offscreen bitmaps...
590         if ( (y1<=y0) || (x1<=x0) ) return;
591         if ( (x1<xmin ) || (x0>xmax) ) return;
592         if ( (y1<ymin ) || (y0>ymax) ) return;
593
594         clipped_u0 = u0; clipped_v0 = v0;
595         clipped_u1 = u1; clipped_v1 = v1;
596
597         clipped_x0 = x0; clipped_y0 = y0;
598         clipped_x1 = x1; clipped_y1 = y1;
599
600         // Clip the left, moving u0 right as necessary
601         if ( x0 < xmin )        {
602                 clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1);
603                 clipped_x0 = xmin;
604         }
605
606         // Clip the right, moving u1 left as necessary
607         if ( x1 > xmax )        {
608                 clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1);
609                 clipped_x1 = xmax;
610         }
611
612         // Clip the top, moving v0 down as necessary
613         if ( y0 < ymin )        {
614                 clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1);
615                 clipped_y0 = ymin;
616         }
617
618         // Clip the bottom, moving v1 up as necessary
619         if ( y1 > ymax )        {
620                 clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1);
621                 clipped_y1 = ymax;
622         }
623         
624         dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1);
625         dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1);
626
627         if (dx1<=dx0) return;
628         if (dy1<=dy0) return;
629
630         //============= DRAW IT =====================
631         int u, v, du, dv;
632         int y, w;
633         ubyte * sbits;
634         bitmap * bp;
635         ubyte * spixels;
636         float tmpu, tmpv;
637
638         tmpu = (clipped_u1-clipped_u0) / (dx1-dx0);
639         if ( fl_abs(tmpu) < 0.001f ) {
640                 return;         // scaled up way too far!
641         }
642         tmpv = (clipped_v1-clipped_v0) / (dy1-dy0);
643         if ( fl_abs(tmpv) < 0.001f ) {
644                 return;         // scaled up way too far!
645         }
646
647         bp = bm_lock( gr_screen.current_bitmap, 8, 0 );
648
649         du = fl2f(tmpu*(bp->w-1));
650         dv = fl2f(tmpv*(bp->h-1));
651
652         v = fl2f(clipped_v0*(bp->h-1));
653         u = fl2f(clipped_u0*(bp->w-1)); 
654         w = dx1 - dx0 + 1;
655
656         spixels = (ubyte *)bp->data;
657
658         for (y=dy0; y<=dy1; y++ )                       {
659                 sbits = &spixels[bp->rowsize*(v>>16)];
660
661                 int x, tmp_u;
662                 tmp_u = u;
663                 for (x=0; x<w; x++ )                    {
664                         ubyte c = sbits[ tmp_u >> 16 ];
665                         if ( c != 255 ) {
666                                 gr_set_color( gr_palette[c*3+0], gr_palette[c*3+1], gr_palette[c*3+2] );
667                                 gr_pixel( x+dx0, y );
668                         }
669                         tmp_u += du;
670                 }
671                 v += dv;
672         }
673
674         bm_unlock(gr_screen.current_bitmap);
675
676         STUB_FUNCTION;
677 }
678
679
680
681 void gr_opengl_tmapper( int nv, vertex * verts[], uint flags )
682 {
683         STUB_FUNCTION;
684 }
685
686
687 void gr_opengl_gradient(int x1,int y1,int x2,int y2)
688 {
689         STUB_FUNCTION;
690 }
691
692 void gr_opengl_set_palette(ubyte *new_palette, int is_alphacolor)
693 {
694         STUB_FUNCTION;
695 }
696
697 void gr_opengl_get_color( int * r, int * g, int * b )
698 {
699         if (r) *r = gr_screen.current_color.red;
700         if (g) *g = gr_screen.current_color.green;
701         if (b) *b = gr_screen.current_color.blue;
702         
703         STUB_FUNCTION;
704 }
705
706 void gr_opengl_init_color(color *c, int r, int g, int b)
707 {
708         gr_screen.current_color.screen_sig = gr_screen.signature;
709         gr_screen.current_color.red = (unsigned char)r;
710         gr_screen.current_color.green = (unsigned char)g;
711         gr_screen.current_color.blue = (unsigned char)b;
712         
713         STUB_FUNCTION;
714 }
715
716 void gr_opengl_set_color_fast(color *dst)
717 {
718         if ( dst->screen_sig != gr_screen.signature )   {
719                 gr_init_color( dst, dst->red, dst->green, dst->blue );
720                 return;
721         }
722         gr_screen.current_color = *dst;
723         
724         STUB_FUNCTION;
725 }
726
727 void gr_opengl_print_screen(char *filename)
728 {
729         STUB_FUNCTION;
730 }
731
732 int gr_opengl_supports_res_ingame(int res)
733 {
734         STUB_FUNCTION;
735         
736         return 1;
737 }
738
739 int gr_opengl_supports_res_interface(int res)
740 {
741         STUB_FUNCTION;
742         
743         return 1;
744 }
745
746 void gr_opengl_cleanup()
747 {
748         if ( !Inited )  return;
749
750         gr_reset_clip();
751         gr_clear();
752         gr_flip();
753
754         Inited = 0;
755 }
756
757 void gr_opengl_fog_set(int fog_mode, int r, int g, int b, float near, float far)
758 {
759         STUB_FUNCTION;
760 }
761
762 void gr_opengl_get_pixel(int x, int y, int *r, int *g, int *b)
763 {
764         STUB_FUNCTION;
765 }
766
767 void gr_opengl_get_region(int front, int w, int g, ubyte *data)
768 {
769         STUB_FUNCTION;
770 }
771
772 void gr_opengl_set_cull(int cull)
773 {
774         STUB_FUNCTION;
775 }
776
777 void gr_opengl_filter_set(int filter)
778 {
779         STUB_FUNCTION;
780 }
781
782 // cross fade
783 void gr_opengl_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct)
784 {
785         STUB_FUNCTION;
786 }
787
788 int gr_opengl_tcache_set(int bitmap_id, int bitmap_type, float *u_ratio, float *v_ratio, int fail_on_full = 0, int sx = -1, int sy = -1, int force = 0)
789 {
790         STUB_FUNCTION;
791         
792         return 1;
793 }
794
795 void gr_opengl_set_clear_color(int r, int g, int b)
796 {
797         STUB_FUNCTION;
798 }
799
800 void gr_opengl_aabitmap(int x, int y)
801 {
802         STUB_FUNCTION;
803 }
804
805 void gr_opengl_aabitmap_ex(int x,int y,int w,int h,int sx,int sy)
806 {
807         STUB_FUNCTION;
808 }
809
810 void gr_opengl_aaline(vertex *v1, vertex *v2)
811 {
812         STUB_FUNCTION;
813 }
814
815 void gr_opengl_init_alphacolor( color *clr, int r, int g, int b, int alpha, int type )
816 {
817         STUB_FUNCTION;
818 }
819
820 void gr_opengl_flash(int r, int g, int b)
821 {
822         STUB_FUNCTION;
823 }
824
825 int gr_opengl_zbuffer_get()
826 {
827         STUB_FUNCTION;
828         
829         return GR_ZBUFF_NONE;
830 }
831
832 int gr_opengl_zbuffer_set(int mode)
833 {
834         STUB_FUNCTION;
835         
836         return GR_ZBUFF_NONE;
837 }
838
839 void gr_opengl_zbuffer_clear(int mode)
840 {
841         STUB_FUNCTION;
842 }
843
844 void gr_opengl_set_gamma(float gamma)
845 {
846         STUB_FUNCTION;
847 }
848
849 void gr_opengl_fade_in(int instantaneous)
850 {
851         STUB_FUNCTION;
852 }
853
854 void gr_opengl_fade_out(int instantaneous)
855 {
856         STUB_FUNCTION;
857 }
858
859 int gr_opengl_save_screen()
860 {
861         STUB_FUNCTION;
862         
863         return -1;
864 }
865
866 void gr_opengl_restore_screen(int id)
867 {
868         STUB_FUNCTION;
869 }
870
871 void gr_opengl_free_screen(int id)
872 {
873         STUB_FUNCTION;
874 }
875
876 void gr_opengl_dump_frame_start(int first_frame, int frames_between_dumps)
877 {
878         STUB_FUNCTION;
879 }
880
881 void gr_opengl_dump_frame_stop()
882 {
883         STUB_FUNCTION;
884 }
885
886 void gr_opengl_dump_frame()
887 {
888         STUB_FUNCTION;
889 }
890
891 uint gr_opengl_lock()
892 {
893         STUB_FUNCTION;
894         
895         return 1;
896 }
897         
898 void gr_opengl_unlock()
899 {
900 }
901         
902 void gr_opengl_init()
903 {
904         if ( Inited )   {
905                 gr_opengl_cleanup();
906                 Inited = 0;
907         }
908
909         mprintf(( "Initializing opengl graphics device...\n" ));
910         Inited = 1;
911
912 #ifdef PLAT_UNIX
913         if (SDL_InitSubSystem (SDL_INIT_VIDEO) < 0)
914         {
915                 fprintf (stderr, "Couldn't init SDL: %s", SDL_GetError());
916                 exit (1);
917         }
918
919         atexit (SDL_Quit);
920
921         if (SDL_SetVideoMode (640, 480, 16, SDL_OPENGL) == NULL)
922         {
923                 fprintf (stderr, "Couldn't set video mode: %s", SDL_GetError ());
924                 exit (1);
925         }
926 #endif
927         gr_opengl_clear();
928
929         Gr_current_red = &Gr_red;
930         Gr_current_blue = &Gr_blue;
931         Gr_current_green = &Gr_green;
932         Gr_current_alpha = &Gr_alpha;
933                                 
934         gr_screen.gf_flip = gr_opengl_flip;
935         gr_screen.gf_flip_window = gr_opengl_flip_window;
936         gr_screen.gf_set_clip = gr_opengl_set_clip;
937         gr_screen.gf_reset_clip = gr_opengl_reset_clip;
938         gr_screen.gf_set_font = gr_opengl_set_font;
939         
940         gr_screen.gf_set_color = gr_opengl_set_color;
941         gr_screen.gf_set_bitmap = gr_opengl_set_bitmap;
942         gr_screen.gf_create_shader = gr_opengl_create_shader;
943         gr_screen.gf_set_shader = gr_opengl_set_shader;
944         gr_screen.gf_clear = gr_opengl_clear;
945         // gr_screen.gf_bitmap = gr_opengl_bitmap;
946         // gr_screen.gf_bitmap_ex = gr_opengl_bitmap_ex;
947         gr_screen.gf_aabitmap = gr_opengl_aabitmap;
948         gr_screen.gf_aabitmap_ex = gr_opengl_aabitmap_ex;
949         
950         gr_screen.gf_rect = gr_opengl_rect;
951         gr_screen.gf_shade = gr_opengl_shade;
952         gr_screen.gf_string = gr_opengl_string;
953         gr_screen.gf_circle = gr_opengl_circle;
954
955         gr_screen.gf_line = gr_opengl_line;
956         gr_screen.gf_aaline = gr_opengl_aaline;
957         gr_screen.gf_pixel = gr_opengl_pixel;
958         gr_screen.gf_scaler = gr_opengl_scaler;
959         gr_screen.gf_tmapper = gr_opengl_tmapper;
960
961         gr_screen.gf_gradient = gr_opengl_gradient;
962
963         gr_screen.gf_set_palette = gr_opengl_set_palette;
964         gr_screen.gf_get_color = gr_opengl_get_color;
965         gr_screen.gf_init_color = gr_opengl_init_color;
966         gr_screen.gf_init_alphacolor = gr_opengl_init_alphacolor;
967         gr_screen.gf_set_color_fast = gr_opengl_set_color_fast;
968         gr_screen.gf_print_screen = gr_opengl_print_screen;
969
970         gr_screen.gf_fade_in = gr_opengl_fade_in;
971         gr_screen.gf_fade_out = gr_opengl_fade_out;
972         gr_screen.gf_flash = gr_opengl_flash;
973         
974         gr_screen.gf_zbuffer_get = gr_opengl_zbuffer_get;
975         gr_screen.gf_zbuffer_set = gr_opengl_zbuffer_set;
976         gr_screen.gf_zbuffer_clear = gr_opengl_zbuffer_clear;
977         
978         gr_screen.gf_save_screen = gr_opengl_save_screen;
979         gr_screen.gf_restore_screen = gr_opengl_restore_screen;
980         gr_screen.gf_free_screen = gr_opengl_free_screen;
981         
982         gr_screen.gf_dump_frame_start = gr_opengl_dump_frame_start;
983         gr_screen.gf_dump_frame_stop = gr_opengl_dump_frame_stop;
984         gr_screen.gf_dump_frame = gr_opengl_dump_frame;
985         
986         gr_screen.gf_set_gamma = gr_opengl_set_gamma;
987         
988         gr_screen.gf_lock = gr_opengl_lock;
989         gr_screen.gf_unlock = gr_opengl_unlock;
990         
991         gr_screen.gf_fog_set = gr_opengl_fog_set;       
992
993         gr_screen.gf_get_region = gr_opengl_get_region;
994
995         gr_screen.gf_get_pixel = gr_opengl_get_pixel;
996
997         gr_screen.gf_set_cull = gr_opengl_set_cull;
998
999         gr_screen.gf_cross_fade = gr_opengl_cross_fade;
1000
1001         gr_screen.gf_filter_set = gr_opengl_filter_set;
1002
1003         gr_screen.gf_tcache_set = gr_opengl_tcache_set;
1004
1005         gr_screen.gf_set_clear_color = gr_opengl_set_clear_color;
1006 }
1007