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