]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/gropengl1.cpp
initial graphics system update
[taylor/freespace2.git] / src / graphics / gropengl1.cpp
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 #include "gropengl.h"
10 #include "gropengl1.h"
11 #include "gropenglinternal.h"
12 #include "2d.h"
13 #include "mouse.h"
14 #include "pstypes.h"
15 #include "cfile.h"
16 #include "bmpman.h"
17 #include "grinternal.h"
18
19
20 int OGL_fog_mode = 0;
21
22 static int Inited = 0;
23
24
25 volatile int GL_activate = 0;
26 volatile int GL_deactivate = 0;
27
28 static GLuint Gr_saved_screen_tex = 0;
29
30 static int Gr_opengl_mouse_saved = 0;
31 static int Gr_opengl_mouse_saved_x = 0;
32 static int Gr_opengl_mouse_saved_y = 0;
33 static int Gr_opengl_mouse_saved_w = 0;
34 static int Gr_opengl_mouse_saved_h = 0;
35 static ubyte *Gr_opengl_mouse_saved_data = NULL;
36
37 #define CLAMP(x,r1,r2) do { if ( (x) < (r1) ) (x) = (r1); else if ((x) > (r2)) (x) = (r2); } while(0)
38
39
40 PFNGLSECONDARYCOLORPOINTEREXTPROC vglSecondaryColorPointerEXT = NULL;
41
42
43 static gr_alpha_blend GL_current_alpha_blend = (gr_alpha_blend) -1;
44 static gr_zbuffer_type GL_current_zbuffer_type = (gr_zbuffer_type) -1;
45
46 void opengl1_set_state(gr_texture_source ts, gr_alpha_blend ab, gr_zbuffer_type zt)
47 {
48         opengl1_set_texture_state(ts);
49
50         if (ab != GL_current_alpha_blend) {
51                 switch (ab) {
52                         case ALPHA_BLEND_NONE:                  // 1*SrcPixel + 0*DestPixel
53                                 glBlendFunc(GL_ONE, GL_ZERO);
54                                 break;
55                         case ALPHA_BLEND_ADDITIVE:              // 1*SrcPixel + 1*DestPixel
56                                 glBlendFunc(GL_ONE, GL_ONE);
57                                 break;
58                         case ALPHA_BLEND_ALPHA_ADDITIVE:        // Alpha*SrcPixel + 1*DestPixel
59                                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
60                                 break;
61                         case ALPHA_BLEND_ALPHA_BLEND_ALPHA:     // Alpha*SrcPixel + (1-Alpha)*DestPixel
62                                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
63                                 break;
64                         case ALPHA_BLEND_ALPHA_BLEND_SRC_COLOR: // Alpha*SrcPixel + (1-SrcPixel)*DestPixel
65                                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR);
66                                 break;
67                         default:
68                                 break;
69                 }
70
71                 GL_current_alpha_blend = ab;
72         }
73
74         if (zt != GL_current_zbuffer_type) {
75                 switch (zt) {
76                         case ZBUFFER_TYPE_NONE:
77                                 glDepthFunc(GL_ALWAYS);
78                                 glDepthMask(GL_FALSE);
79                                 break;
80                         case ZBUFFER_TYPE_READ:
81                                 glDepthFunc(GL_LESS);
82                                 glDepthMask(GL_FALSE);
83                                 break;
84                         case ZBUFFER_TYPE_WRITE:
85                                 glDepthFunc(GL_ALWAYS);
86                                 glDepthMask(GL_TRUE);
87                                 break;
88                         case ZBUFFER_TYPE_FULL:
89                                 glDepthFunc(GL_LESS);
90                                 glDepthMask(GL_TRUE);
91                                 break;
92                         default:
93                                 break;
94                 }
95
96                 GL_current_zbuffer_type = zt;
97         }
98 }
99
100 void gr_opengl1_activate(int active)
101 {
102         if (active) {
103                 GL_activate++;
104
105                 // don't grab key/mouse if cmdline says so or if we're fullscreen
106         //      if(!Cmdline_no_grab && !(SDL_GetVideoSurface()->flags & SDL_FULLSCREEN)) {
107         //              SDL_WM_GrabInput(SDL_GRAB_ON);
108         //      }
109         } else {
110                 GL_deactivate++;
111
112                 // let go of mouse/keyboard
113         //      SDL_WM_GrabInput(SDL_GRAB_OFF);
114         }
115 }
116
117 void gr_opengl1_clear()
118 {
119         glClearColor(gr_screen.current_clear_color.red / 255.0,
120                 gr_screen.current_clear_color.green / 255.0,
121                 gr_screen.current_clear_color.blue / 255.0, 1.0);
122
123         glClear ( GL_COLOR_BUFFER_BIT );
124 }
125
126 void gr_opengl1_flip()
127 {
128         if (!Inited) return;
129
130         gr_reset_clip();
131
132         mouse_eval_deltas();
133
134         Gr_opengl_mouse_saved = 0;
135
136         if ( mouse_is_visible() )       {
137                 int mx, my;
138
139                 gr_reset_clip();
140                 mouse_get_pos( &mx, &my );
141
142                 gr_opengl1_save_mouse_area(mx,my,32,32);
143
144                 if (Gr_cursor == -1) {
145 #ifndef NDEBUG
146                         gr_set_color(255,255,255);
147                         gr_line(mx, my, mx+7, my + 7);
148                         gr_line(mx, my, mx+5, my );
149                         gr_line(mx, my, mx, my+5);
150 #endif
151                 } else {
152                         gr_set_bitmap(Gr_cursor);
153                         gr_bitmap(mx, my);
154                 }
155          }
156
157 #ifndef NDEBUG
158         GLenum error = GL_NO_ERROR;
159         int ic = 1;
160         do {
161                 error = glGetError();
162
163                 if (error != GL_NO_ERROR) {
164                         nprintf(("Warning", "!!DEBUG!! OpenGL Error: %d (%d this frame)\n", error, ic));
165                 }
166
167                 ic++;
168         } while (error != GL_NO_ERROR);
169 #endif
170
171         SDL_GL_SwapWindow(GL_window);
172
173         opengl1_tcache_frame();
174
175         int cnt = GL_activate;
176         if ( cnt )      {
177                 GL_activate-=cnt;
178                 opengl1_tcache_flush();
179                 // gr_opengl_clip_cursor(1); /* mouse grab, see opengl_activate */
180         }
181
182         cnt = GL_deactivate;
183         if ( cnt )      {
184                 GL_deactivate-=cnt;
185                 // gr_opengl_clip_cursor(0);  /* mouse grab, see opengl_activate */
186         }
187 }
188
189 void gr_opengl1_set_clip(int x,int y,int w,int h)
190 {
191         // check for sanity of parameters
192         if (x < 0)
193                 x = 0;
194         if (y < 0)
195                 y = 0;
196
197         if (x >= gr_screen.max_w)
198                 x = gr_screen.max_w - 1;
199         if (y >= gr_screen.max_h)
200                 y = gr_screen.max_h - 1;
201
202         if (x + w > gr_screen.max_w)
203                 w = gr_screen.max_w - x;
204         if (y + h > gr_screen.max_h)
205                 h = gr_screen.max_h - y;
206
207         if (w > gr_screen.max_w)
208                 w = gr_screen.max_w;
209         if (h > gr_screen.max_h)
210                 h = gr_screen.max_h;
211
212         gr_screen.offset_x = x;
213         gr_screen.offset_y = y;
214         gr_screen.clip_left = 0;
215         gr_screen.clip_right = w-1;
216         gr_screen.clip_top = 0;
217         gr_screen.clip_bottom = h-1;
218         gr_screen.clip_width = w;
219         gr_screen.clip_height = h;
220
221         x = fl2i((x * GL_viewport_scale_w) + 0.5f) + GL_viewport_x;
222         y = fl2i((y * GL_viewport_scale_h) + 0.5f) + GL_viewport_y;
223         w = fl2i((w * GL_viewport_scale_w) + 0.5f);
224         h = fl2i((h * GL_viewport_scale_h) + 0.5f);
225
226         glEnable(GL_SCISSOR_TEST);
227         glScissor(x, GL_viewport_h-y-h, w, h);
228 }
229
230 void gr_opengl1_reset_clip()
231 {
232         gr_screen.offset_x = 0;
233         gr_screen.offset_y = 0;
234         gr_screen.clip_left = 0;
235         gr_screen.clip_top = 0;
236         gr_screen.clip_right = gr_screen.max_w - 1;
237         gr_screen.clip_bottom = gr_screen.max_h - 1;
238         gr_screen.clip_width = gr_screen.max_w;
239         gr_screen.clip_height = gr_screen.max_h;
240
241         glDisable(GL_SCISSOR_TEST);
242 //      glScissor(0, 0, gr_screen.max_w, gr_screen.max_h);
243 }
244
245
246 void gr_opengl1_set_palette(ubyte *new_palette, int is_alphacolor)
247 {
248 }
249
250
251 void gr_opengl1_print_screen(const char *filename)
252 {
253         char tmp[MAX_FILENAME_LEN];
254         ubyte *buf = NULL;
255
256         strcpy( tmp, filename );
257         strcat( tmp, NOX(".tga"));
258
259         buf = (ubyte*)malloc(GL_viewport_w * GL_viewport_h * 3);
260
261         if (buf == NULL) {
262                 return;
263         }
264
265         CFILE *f = cfopen(tmp, "wb", CFILE_NORMAL, CF_TYPE_ROOT);
266
267         if (f == NULL) {
268                 free(buf);
269                 return;
270         }
271
272         // Write the TGA header
273         cfwrite_ubyte( 0, f );  //      IDLength;
274         cfwrite_ubyte( 0, f );  //      ColorMapType;
275         cfwrite_ubyte( 2, f );  //      ImageType;              // 2 = 24bpp, uncompressed, 10=24bpp rle compressed
276         cfwrite_ushort( 0, f ); // CMapStart;
277         cfwrite_ushort( 0, f ); //      CMapLength;
278         cfwrite_ubyte( 0, f );  // CMapDepth;
279         cfwrite_ushort( 0, f ); //      XOffset;
280         cfwrite_ushort( 0, f ); //      YOffset;
281         cfwrite_ushort( (ushort)GL_viewport_w, f );     //      Width;
282         cfwrite_ushort( (ushort)GL_viewport_h, f );     //      Height;
283         cfwrite_ubyte( 24, f ); //PixelDepth;
284         cfwrite_ubyte( 0, f );  //ImageDesc;
285
286         memset(buf, 0, GL_viewport_w * GL_viewport_h * 3);
287
288         glReadPixels(GL_viewport_x, GL_viewport_y, GL_viewport_w, GL_viewport_h, GL_BGR, GL_UNSIGNED_BYTE, buf);
289
290         cfwrite(buf, GL_viewport_w * GL_viewport_h * 3, 1, f);
291
292         cfclose(f);
293
294         free(buf);
295 }
296
297 int gr_opengl1_supports_res_ingame(int res)
298 {
299         return 1;
300 }
301
302 int gr_opengl1_supports_res_interface(int res)
303 {
304         return 1;
305 }
306
307 void opengl1_cleanup()
308 {
309         if ( !Inited )  return;
310
311
312         gr_reset_clip();
313         gr_clear();
314         gr_flip();
315
316         opengl1_tcache_cleanup();
317
318         Inited = 0;
319 }
320
321 void gr_opengl1_fog_set(int fog_mode, int r, int g, int b, float fog_near, float fog_far)
322 {
323         Assert((r >= 0) && (r < 256));
324         Assert((g >= 0) && (g < 256));
325         Assert((b >= 0) && (b < 256));
326
327         if (fog_mode == GR_FOGMODE_NONE) {
328                 if (gr_screen.current_fog_mode != fog_mode) {
329                         glDisable(GL_FOG);
330
331                         if (OGL_fog_mode == 1) {
332                                 glDisable(GL_COLOR_SUM);
333                         }
334                 }
335
336                 gr_screen.current_fog_mode = fog_mode;
337
338                 return;
339         }
340
341         if (gr_screen.current_fog_mode != fog_mode) {
342                 glEnable(GL_FOG);
343
344                 if (OGL_fog_mode == 1) {
345                         glEnable(GL_COLOR_SUM);
346                 } else if (OGL_fog_mode == 2) {
347                         glFogi(GL_FOG_MODE, GL_LINEAR);
348                 }
349
350                 gr_screen.current_fog_mode = fog_mode;
351         }
352
353         if ( (gr_screen.current_fog_color.red != r) ||
354                         (gr_screen.current_fog_color.green != g) ||
355                         (gr_screen.current_fog_color.blue != b) ) {
356                 GLfloat fc[4];
357
358                 gr_opengl_init_color( &gr_screen.current_fog_color, r, g, b );
359
360                 fc[0] = (float)r/255.0;
361                 fc[1] = (float)g/255.0;
362                 fc[2] = (float)b/255.0;
363                 fc[3] = 1.0;
364
365                 glFogfv(GL_FOG_COLOR, fc);
366         }
367
368         if( (fog_near >= 0.0f) && (fog_far >= 0.0f) &&
369                         ((fog_near != gr_screen.fog_near) ||
370                         (fog_far != gr_screen.fog_far)) ) {
371                 gr_screen.fog_near = fog_near;
372                 gr_screen.fog_far = fog_far;
373
374                 if (OGL_fog_mode == 2) {
375                         glFogf(GL_FOG_START, fog_near);
376                         glFogf(GL_FOG_END, fog_far);
377                 }
378         }
379 }
380
381 void gr_opengl1_get_pixel(int x, int y, int *r, int *g, int *b)
382 {
383         // Not used.
384 }
385
386 void gr_opengl1_set_cull(int cull)
387 {
388         if (cull) {
389                 glEnable (GL_CULL_FACE);
390                 glFrontFace (GL_CCW);
391         } else {
392                 glDisable (GL_CULL_FACE);
393         }
394 }
395
396 void gr_opengl1_filter_set(int filter)
397 {
398 }
399
400
401 void gr_opengl1_zbuffer_clear(int mode)
402 {
403         if (mode) {
404                 gr_zbuffering = 1;
405                 gr_zbuffering_mode = GR_ZBUFF_FULL;
406                 gr_global_zbuffering = 1;
407
408                 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_NONE, ZBUFFER_TYPE_FULL );
409                 glClear ( GL_DEPTH_BUFFER_BIT );
410         } else {
411                 gr_zbuffering = 0;
412                 gr_zbuffering_mode = GR_ZBUFF_NONE;
413                 gr_global_zbuffering = 0;
414         }
415 }
416
417 void gr_opengl1_fade_in(int instantaneous)
418 {
419         // Empty - DDOI
420 }
421
422 void gr_opengl1_fade_out(int instantaneous)
423 {
424         // Empty - DDOI
425 }
426
427 void gr_opengl1_get_region(int front, int w, int h, ubyte *data)
428 {
429         if (front) {
430                 glReadBuffer(GL_FRONT);
431         } else {
432                 glReadBuffer(GL_BACK);
433         }
434
435         opengl1_set_state(TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE);
436
437         glPixelStorei(GL_UNPACK_ROW_LENGTH, GL_viewport_w);
438
439         int x = GL_viewport_x;
440         int y = (GL_viewport_y+GL_viewport_h)-h-1;
441
442         if (gr_screen.bytes_per_pixel == 2) {
443                 glReadPixels(x, y, w, h, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, data);
444         } else if (gr_screen.bytes_per_pixel == 4) {
445                 glReadPixels(x, y, w, h, GL_BGRA, GL_UNSIGNED_BYTE, data);
446         }
447
448         glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
449 }
450
451 void gr_opengl1_save_mouse_area(int x, int y, int w, int h)
452 {
453         int x1, y1, x2, y2;
454
455         w = fl2i((w * GL_viewport_scale_w) + 0.5f);
456         h = fl2i((h * GL_viewport_scale_h) + 0.5f);
457
458         x1 = x;
459         y1 = y;
460         x2 = x+w-1;
461         y2 = y+h-1;
462
463         CLAMP(x1, 0, GL_viewport_w);
464         CLAMP(x2, 0, GL_viewport_w);
465         CLAMP(y1, 0, GL_viewport_h);
466         CLAMP(y2, 0, GL_viewport_h);
467
468         Gr_opengl_mouse_saved_x = x1;
469         Gr_opengl_mouse_saved_y = y1;
470         Gr_opengl_mouse_saved_w = x2 - x1 + 1;
471         Gr_opengl_mouse_saved_h = y2 - y1 + 1;
472
473         if ( (Gr_opengl_mouse_saved_w < 1) || (Gr_opengl_mouse_saved_h < 1) ) {
474                 return;
475         }
476
477         if (Gr_opengl_mouse_saved_data == NULL) {
478                 Gr_opengl_mouse_saved_data = (ubyte*)malloc(w * h * gr_screen.bytes_per_pixel);
479
480                 if ( !Gr_opengl_mouse_saved_data ) {
481                         return;
482                 }
483         }
484
485         opengl1_set_state(TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE);
486
487         x1 = GL_viewport_x+Gr_opengl_mouse_saved_x;
488         y1 = (GL_viewport_y+GL_viewport_h)-Gr_opengl_mouse_saved_y-Gr_opengl_mouse_saved_h;
489
490         glReadBuffer(GL_BACK);
491         glReadPixels(x1, y1, Gr_opengl_mouse_saved_w, Gr_opengl_mouse_saved_h,
492                         GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, Gr_opengl_mouse_saved_data);
493
494         Gr_opengl_mouse_saved = 1;
495 }
496
497 int gr_opengl1_save_screen()
498 {
499         gr_reset_clip();
500
501         if (Gr_saved_screen_tex) {
502                 mprintf(( "Screen already saved!\n" ));
503                 return -1;
504         }
505
506         glGenTextures(1, &Gr_saved_screen_tex);
507
508         if ( !Gr_saved_screen_tex ) {
509                 mprintf(( "Couldn't create texture for saved screen!\n" ));
510                 return -1;
511         }
512
513         opengl1_set_state(TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_NONE, ZBUFFER_TYPE_NONE);
514
515         glBindTexture(GL_TEXTURE_2D, Gr_saved_screen_tex);
516
517         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
518         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
519         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
520         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
521         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
522
523         glReadBuffer(GL_FRONT);
524         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GL_viewport_x, GL_viewport_y,
525                         GL_viewport_w, GL_viewport_h, 0);
526
527         if (Gr_opengl_mouse_saved) {
528                 int x = Gr_opengl_mouse_saved_x;
529                 int y = GL_viewport_h-Gr_opengl_mouse_saved_y-Gr_opengl_mouse_saved_h;
530
531                 glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, Gr_opengl_mouse_saved_w,
532                                 Gr_opengl_mouse_saved_h, GL_BGRA, GL_UNSIGNED_BYTE,
533                                 Gr_opengl_mouse_saved_data);
534         }
535
536         glBindTexture(GL_TEXTURE_2D, 0);
537
538         return 0;
539 }
540
541 void gr_opengl1_restore_screen(int id)
542 {
543         gr_reset_clip();
544
545         if ( !Gr_saved_screen_tex ) {
546                 gr_clear();
547                 return;
548         }
549
550         glBindTexture(GL_TEXTURE_2D, Gr_saved_screen_tex);
551
552         if (Gr_opengl_mouse_saved) {
553                 int x = Gr_opengl_mouse_saved_x;
554                 int y = GL_viewport_h-Gr_opengl_mouse_saved_y-Gr_opengl_mouse_saved_h;
555
556                 glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, Gr_opengl_mouse_saved_w,
557                                 Gr_opengl_mouse_saved_h, GL_BGRA, GL_UNSIGNED_BYTE,
558                                 Gr_opengl_mouse_saved_data);
559         }
560
561         glMatrixMode(GL_MODELVIEW);
562         glPushMatrix();
563         glLoadIdentity();
564         glScalef(1.0f, -1.0f, 1.0f);
565
566         int tex_coord[] = { 0, 0, 0, 1, 1, 1, 1, 0 };
567         int ver_coord[] = { GL_viewport_x, GL_viewport_y, GL_viewport_x,
568                         GL_viewport_h, GL_viewport_w, GL_viewport_h, GL_viewport_w,
569                         GL_viewport_y
570         };
571
572         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
573         glEnableClientState(GL_VERTEX_ARRAY);
574
575         glTexCoordPointer(2, GL_INT, 0, &tex_coord);
576         glVertexPointer(2, GL_INT, 0, &ver_coord);
577
578         glDrawArrays(GL_QUADS, 0, 4);
579
580         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
581         glDisableClientState(GL_VERTEX_ARRAY);
582
583         glPopMatrix();
584
585         glBindTexture(GL_TEXTURE_2D, 0);
586 }
587
588 void gr_opengl1_free_screen(int id)
589 {
590         if (Gr_saved_screen_tex) {
591                 glDeleteTextures(1, &Gr_saved_screen_tex);
592                 Gr_saved_screen_tex = 0;
593         }
594 }
595
596 void gr_opengl1_dump_frame_start(int first_frame, int frames_between_dumps)
597 {
598         STUB_FUNCTION;
599 }
600
601 void gr_opengl1_dump_frame_stop()
602 {
603         STUB_FUNCTION;
604 }
605
606 void gr_opengl1_dump_frame()
607 {
608         STUB_FUNCTION;
609 }
610
611 uint gr_opengl1_lock()
612 {
613         STUB_FUNCTION;
614
615         return 1;
616 }
617
618 void gr_opengl1_unlock()
619 {
620 }
621
622 void gr_opengl1_zbias(int bias)
623 {
624         if (bias) {
625                 glEnable(GL_POLYGON_OFFSET_FILL);
626                 glPolygonOffset(0.0, -bias);
627         } else {
628                 glDisable(GL_POLYGON_OFFSET_FILL);
629         }
630 }
631
632 void opengl1_init_func_pointers()
633 {
634         gr_screen.gf_flip = gr_opengl1_flip;
635         gr_screen.gf_set_clip = gr_opengl1_set_clip;
636         gr_screen.gf_reset_clip = gr_opengl1_reset_clip;
637         gr_screen.gf_set_font = grx_set_font;
638
639         gr_screen.gf_set_color = gr_opengl_set_color;
640         gr_screen.gf_set_bitmap = gr_opengl_set_bitmap;
641         gr_screen.gf_create_shader = gr_opengl_create_shader;
642         gr_screen.gf_set_shader = gr_opengl_set_shader;
643         gr_screen.gf_clear = gr_opengl1_clear;
644
645         gr_screen.gf_aabitmap = gr_opengl1_aabitmap;
646         gr_screen.gf_aabitmap_ex = gr_opengl1_aabitmap_ex;
647
648         gr_screen.gf_rect = gr_opengl1_rect;
649         gr_screen.gf_shade = gr_opengl1_shade;
650         gr_screen.gf_string = gr_opengl1_string;
651         gr_screen.gf_circle = gr_opengl1_circle;
652
653         gr_screen.gf_line = gr_opengl1_line;
654         gr_screen.gf_aaline = gr_opengl1_aaline;
655         gr_screen.gf_pixel = gr_opengl1_pixel;
656         gr_screen.gf_scaler = gr_opengl1_scaler;
657         gr_screen.gf_tmapper = gr_opengl1_tmapper;
658
659         gr_screen.gf_gradient = gr_opengl1_gradient;
660
661         gr_screen.gf_set_palette = gr_opengl1_set_palette;
662         gr_screen.gf_get_color = gr_opengl_get_color;
663         gr_screen.gf_init_color = gr_opengl_init_color;
664         gr_screen.gf_init_alphacolor = gr_opengl_init_alphacolor;
665         gr_screen.gf_set_color_fast = gr_opengl_set_color_fast;
666         gr_screen.gf_print_screen = gr_opengl1_print_screen;
667
668         gr_screen.gf_fade_in = gr_opengl1_fade_in;
669         gr_screen.gf_fade_out = gr_opengl1_fade_out;
670         gr_screen.gf_flash = gr_opengl1_flash;
671
672         gr_screen.gf_zbuffer_get = gr_opengl_zbuffer_get;
673         gr_screen.gf_zbuffer_set = gr_opengl_zbuffer_set;
674         gr_screen.gf_zbuffer_clear = gr_opengl1_zbuffer_clear;
675
676         gr_screen.gf_save_screen = gr_opengl1_save_screen;
677         gr_screen.gf_restore_screen = gr_opengl1_restore_screen;
678         gr_screen.gf_free_screen = gr_opengl1_free_screen;
679
680         gr_screen.gf_dump_frame_start = gr_opengl1_dump_frame_start;
681         gr_screen.gf_dump_frame_stop = gr_opengl1_dump_frame_stop;
682         gr_screen.gf_dump_frame = gr_opengl1_dump_frame;
683
684         gr_screen.gf_set_gamma = gr_opengl1_set_gamma;
685
686         gr_screen.gf_lock = gr_opengl1_lock;
687         gr_screen.gf_unlock = gr_opengl1_unlock;
688
689         gr_screen.gf_fog_set = gr_opengl1_fog_set;
690
691         gr_screen.gf_get_region = gr_opengl1_get_region;
692
693         gr_screen.gf_get_pixel = gr_opengl1_get_pixel;
694
695         gr_screen.gf_set_cull = gr_opengl1_set_cull;
696
697         gr_screen.gf_cross_fade = gr_opengl1_cross_fade;
698
699         gr_screen.gf_filter_set = gr_opengl1_filter_set;
700
701         gr_screen.gf_set_clear_color = gr_opengl_set_clear_color;
702
703         gr_screen.gf_preload_init = gr_opengl1_preload_init;
704         gr_screen.gf_preload = gr_opengl1_preload;
705
706         gr_screen.gf_zbias = gr_opengl1_zbias;
707
708         gr_screen.gf_force_windowed = gr_opengl_force_windowed;
709         gr_screen.gf_force_fullscreen = gr_opengl_force_fullscreen;
710
711         gr_screen.gf_activate = gr_opengl1_activate;
712 }
713
714 void opengl1_init()
715 {
716
717         if ( Inited )   {
718                 return;
719         }
720
721         /*
722           1 = use secondary color ext
723           2 = use opengl linear fog
724          */
725         OGL_fog_mode = 2;
726
727         if ( SDL_GL_ExtensionSupported("GL_EXT_secondary_color") ) {
728                 vglSecondaryColorPointerEXT = (PFNGLSECONDARYCOLORPOINTEREXTPROC)SDL_GL_GetProcAddress("glSecondaryColorPointerEXT");
729                 Assert( vglSecondaryColorPointerEXT != NULL );
730                 OGL_fog_mode = 1;
731                 mprintf(("  Using extension: GL_EXT_secondary_color\n"));
732         }
733
734         mprintf(("\n"));
735
736         glShadeModel(GL_SMOOTH);
737         glEnable(GL_DITHER);
738         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
739         glHint(GL_FOG_HINT, GL_NICEST);
740
741         glEnable(GL_DEPTH_TEST);
742         glEnable(GL_BLEND);
743
744         glEnable(GL_TEXTURE_2D);
745
746         glDepthRange(0.0, 1.0);
747
748         glPixelStorei(GL_PACK_ALIGNMENT, 1);
749         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
750
751         glFlush();
752
753
754         Bm_pixel_format = BM_PIXEL_FORMAT_ARGB;
755         Gr_bitmap_poly = 1;
756
757         opengl1_init_func_pointers();
758         opengl1_tcache_init(1);
759
760         gr_opengl1_clear();
761
762         Inited = 1;
763 }