2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
9 #include "SDL_opengl.h"
14 #include "gropenglinternal.h"
17 #include "grinternal.h"
24 extern int OGL_fog_mode;
26 #define NEBULA_COLORS 20
29 static void opengl1_rect_internal(int x, int y, int w, int h, int r, int g, int b, int a)
33 vertex *verts[4] = {&v[0], &v[1], &v[2], &v[3]};
35 saved_zbuf = gr_zbuffer_get();
37 // start the frame, no zbuffering, no culling
39 gr_zbuffer_set(GR_ZBUFF_NONE);
48 v[0].flags = PF_PROJECTED;
55 v[1].sx = i2fl(x + w);
60 v[1].flags = PF_PROJECTED;
67 v[2].sx = i2fl(x + w);
68 v[2].sy = i2fl(y + h);
72 v[2].flags = PF_PROJECTED;
80 v[3].sy = i2fl(y + h);
84 v[3].flags = PF_PROJECTED;
92 g3_draw_poly_constant_sw(4, verts, TMAP_FLAG_GOURAUD | TMAP_FLAG_RGB | TMAP_FLAG_ALPHA, 0.1f);
96 // restore zbuffer and culling
97 gr_zbuffer_set(saved_zbuf);
101 static void opengl1_aabitmap_ex_internal(int x,int y,int w,int h,int sx,int sy)
103 if ( (w < 1) || (h < 1) ) {
107 if ( !gr_screen.current_color.is_alphacolor ) {
111 float u_scale, v_scale;
113 if ( !opengl1_tcache_set(gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP,
114 &u_scale, &v_scale, 0, -1, -1, 0) )
116 // Couldn't set texture
117 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
121 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
123 float u0, u1, v0, v1;
124 float x1, x2, y1, y2;
127 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
129 u0 = u_scale*i2fl(sx)/i2fl(bw);
130 v0 = v_scale*i2fl(sy)/i2fl(bh);
132 u1 = u_scale*i2fl(sx+w)/i2fl(bw);
133 v1 = v_scale*i2fl(sy+h)/i2fl(bh);
135 x1 = i2fl(x+gr_screen.offset_x);
136 y1 = i2fl(y+gr_screen.offset_y);
137 x2 = i2fl(x+w+gr_screen.offset_x);
138 y2 = i2fl(y+h+gr_screen.offset_y);
140 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
141 gr_screen.current_color.blue,gr_screen.current_color.alpha);
143 opengl_alloc_render_buffer(4);
145 render_buffer[0].x = x1;
146 render_buffer[0].y = y1;
147 render_buffer[0].u = u0;
148 render_buffer[0].v = v0;
150 render_buffer[1].x = x1;
151 render_buffer[1].y = y2;
152 render_buffer[1].u = u0;
153 render_buffer[1].v = v1;
155 render_buffer[2].x = x2;
156 render_buffer[2].y = y1;
157 render_buffer[2].u = u1;
158 render_buffer[2].v = v0;
160 render_buffer[3].x = x2;
161 render_buffer[3].y = y2;
162 render_buffer[3].u = u1;
163 render_buffer[3].v = v1;
165 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
166 glEnableClientState(GL_VERTEX_ARRAY);
168 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
169 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
171 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
173 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
174 glDisableClientState(GL_VERTEX_ARRAY);
177 static void opengl1_stuff_fog_value(float z, float *f_val)
185 f_float = 1.0f - ((gr_screen.fog_far - z) / (gr_screen.fog_far - gr_screen.fog_near));
187 if (f_float < 0.0f) {
189 } else if (f_float > 1.0f) {
196 static void opengl1_tmapper_internal( int nv, vertex ** verts, uint flags, int is_scaler )
199 float u_scale = 1.0f, v_scale = 1.0f;
201 gr_texture_source texture_source = TEXTURE_SOURCE_NONE;
202 gr_alpha_blend alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA;
203 gr_zbuffer_type zbuffer_type = ZBUFFER_TYPE_NONE;
206 if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) {
207 zbuffer_type = ZBUFFER_TYPE_READ;
209 zbuffer_type = ZBUFFER_TYPE_FULL;
213 int tmap_type = TCACHE_TYPE_NORMAL;
215 ubyte r = 255, g = 255, b = 255, a = 255;
217 if ( !(flags & TMAP_FLAG_TEXTURED) ) {
218 r = gr_screen.current_color.red;
219 g = gr_screen.current_color.green;
220 b = gr_screen.current_color.blue;
223 if (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) {
224 alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE;
226 // Blend with screen pixel using src*alpha+dst
228 if (gr_screen.current_alpha < 1.0f) {
229 r = ubyte((r * gr_screen.current_alpha) + 0.5f);
230 g = ubyte((g * gr_screen.current_alpha) + 0.5f);
231 b = ubyte((b * gr_screen.current_alpha) + 0.5f);
235 if (flags & TMAP_FLAG_BITMAP_SECTION) {
236 SDL_assert( !(flags & TMAP_FLAG_BITMAP_INTERFACE) );
237 tmap_type = TCACHE_TYPE_BITMAP_SECTION;
238 } else if (flags & TMAP_FLAG_BITMAP_INTERFACE) {
239 SDL_assert( !(flags & TMAP_FLAG_BITMAP_SECTION) );
240 tmap_type = TCACHE_TYPE_BITMAP_INTERFACE;
243 if (flags & TMAP_FLAG_TEXTURED) {
244 if ( !opengl1_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale,
245 &v_scale, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy, 0) )
247 mprintf(( "Not rendering a texture because it didn't fit in VRAM!\n" ));
251 // use non-filtered textures for bitmap sections and UI graphics
253 case TCACHE_TYPE_BITMAP_INTERFACE:
254 case TCACHE_TYPE_BITMAP_SECTION:
255 texture_source = TEXTURE_SOURCE_NO_FILTERING;
259 texture_source = TEXTURE_SOURCE_DECAL;
265 opengl1_set_state( texture_source, alpha_blend, zbuffer_type );
267 float ox = gr_screen.offset_x * 16.0f;
268 float oy = gr_screen.offset_y * 16.0f;
270 float fr = 1.0f, fg = 1.0f, fb = 1.0f;
272 if (flags & TMAP_FLAG_PIXEL_FOG) {
280 for (i=nv-1;i>=0;i--) // DDOI - change polygon winding
282 vertex * va = verts[i];
284 sx = (va->sx * 16.0f + ox) / 16.0f;
285 sy = (va->sy * 16.0f + oy) / 16.0f;
287 neb2_get_pixel((int)sx, (int)sy, &r, &g, &b);
298 gr_fog_set(GR_FOGMODE_FOG, ra, ga, ba, -1.0f, -1.0f);
305 opengl_alloc_render_buffer(nv);
309 float sx, sy, sz = 0.99f, rhw = 1.0f;
311 for (i = nv-1; i >= 0; i--) {
312 vertex *va = verts[i];
314 if ( Gr_zbuffering || (flags & TMAP_FLAG_NEBULA) ) {
315 sz = 1.0f - 1.0f / (1.0f + va->z / (32768.0f / 256.0f));
322 if (flags & TMAP_FLAG_CORRECT) {
326 if (flags & TMAP_FLAG_ALPHA) {
330 if (flags & TMAP_FLAG_NEBULA ) {
331 int pal = (verts[i]->b*(NEBULA_COLORS-1))/255;
332 r = gr_palette[pal*3+0];
333 g = gr_palette[pal*3+1];
334 b = gr_palette[pal*3+2];
335 } else if ( (flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD) ) {
336 r = g = b = Gr_gamma_lookup[verts[i]->b];
337 } else if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
338 // Make 0.75 be 256.0f
339 r = Gr_gamma_lookup[verts[i]->r];
340 g = Gr_gamma_lookup[verts[i]->g];
341 b = Gr_gamma_lookup[verts[i]->b];
344 render_buffer[rb_offset].r = r;
345 render_buffer[rb_offset].g = g;
346 render_buffer[rb_offset].b = b;
347 render_buffer[rb_offset].a = a;
349 if ( (flags & TMAP_FLAG_PIXEL_FOG) && (OGL_fog_mode == 1) ) {
352 opengl1_stuff_fog_value(va->z, &f_val);
354 render_buffer[rb_offset].sr = (ubyte)(((fr * f_val) * 255.0f) + 0.5f);
355 render_buffer[rb_offset].sg = (ubyte)(((fg * f_val) * 255.0f) + 0.5f);
356 render_buffer[rb_offset].sb = (ubyte)(((fb * f_val) * 255.0f) + 0.5f);
359 sx = (va->sx * 16.0f + ox) / 16.0f;
360 sy = (va->sy * 16.0f + oy) / 16.0f;
362 if (flags & TMAP_FLAG_TEXTURED) {
363 render_buffer[rb_offset].u = va->u * u_scale;
364 render_buffer[rb_offset].v = va->v * v_scale;
367 render_buffer[rb_offset].x = sx * rhw;
368 render_buffer[rb_offset].y = sy * rhw;
369 render_buffer[rb_offset].z = -sz * rhw;
370 render_buffer[rb_offset].w = rhw;
375 if (flags & TMAP_FLAG_TEXTURED) {
376 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
377 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
380 if ( (gr_screen.current_fog_mode != GR_FOGMODE_NONE) && (OGL_fog_mode == 1) ) {
381 glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
382 vglSecondaryColorPointer(3, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].sr);
385 glEnableClientState(GL_COLOR_ARRAY);
386 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
388 glEnableClientState(GL_VERTEX_ARRAY);
389 glVertexPointer(4, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
391 glDrawArrays(GL_TRIANGLE_FAN, 0, rb_offset);
393 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
394 glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
395 glDisableClientState(GL_COLOR_ARRAY);
396 glDisableClientState(GL_VERTEX_ARRAY);
399 void gr_opengl1_rect(int x,int y,int w,int h)
401 opengl1_rect_internal(x, y, w, h, gr_screen.current_color.red,
402 gr_screen.current_color.green, gr_screen.current_color.blue,
403 gr_screen.current_color.alpha);
406 void gr_opengl1_shade(int x,int y,int w,int h)
413 r = fl2i(gr_screen.current_shader.r*255.0f*shade1);
414 if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
415 g = fl2i(gr_screen.current_shader.g*255.0f*shade1);
416 if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
417 b = fl2i(gr_screen.current_shader.b*255.0f*shade1);
418 if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
419 a = fl2i(gr_screen.current_shader.c*255.0f*shade2);
420 if ( a < 0 ) a = 0; else if ( a > 255 ) a = 255;
422 opengl1_rect_internal(x, y, w, h, r, g, b, a);
425 void gr_opengl1_aabitmap_ex(int x,int y,int w,int h,int sx,int sy)
432 int dx1=x, dx2=x+w-1;
433 int dy1=y, dy2=y+h-1;
436 bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL );
441 if ( count > 1 ) Int3();
445 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
446 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
447 if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
448 if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
449 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
450 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
477 if ( w < 1 ) return; // clipped away!
478 if ( h < 1 ) return; // clipped away!
482 // Make sure clipping algorithm works
486 SDL_assert( w == (dx2-dx1+1) );
487 SDL_assert( h == (dy2-dy1+1) );
488 SDL_assert( sx >= 0 );
489 SDL_assert( sy >= 0 );
490 SDL_assert( sx+w <= bw );
491 SDL_assert( sy+h <= bh );
492 SDL_assert( dx2 >= dx1 );
493 SDL_assert( dy2 >= dy1 );
494 SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) );
495 SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) );
496 SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) );
497 SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) );
500 // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions.
501 opengl1_aabitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
504 void gr_opengl1_aabitmap(int x, int y)
508 bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
509 int dx1=x, dx2=x+w-1;
510 int dy1=y, dy2=y+h-1;
513 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
514 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
515 if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
516 if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
517 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
518 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
520 if ( sx < 0 ) return;
521 if ( sy < 0 ) return;
522 if ( sx >= w ) return;
523 if ( sy >= h ) return;
525 // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
526 gr_opengl1_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
529 void gr_opengl1_string( int sx, int sy, const char *s )
531 int width, spacing, letter;
534 float u_scale, v_scale;
535 float u0, u1, v0, v1;
536 float x1, x2, y1, y2;
540 if ( !Current_font ) {
544 gr_set_bitmap(Current_font->bitmap_id, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
546 if ( !opengl1_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 0, -1, -1, 0 ) ) {
547 // Couldn't set texture
548 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
552 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
554 fbw = 1.0f / i2fl(bw);
555 fbh = 1.0f / i2fl(bh);
557 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
559 // don't want to create a super huge buffer size (i.e. credits text)
560 const int alocsize = 320; // 80 characters max per render call
561 opengl_alloc_render_buffer(alocsize);
563 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
564 gr_screen.current_color.blue, gr_screen.current_color.alpha);
566 glEnableClientState(GL_VERTEX_ARRAY);
567 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
569 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
570 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
574 if (sx==0x8000) { //centered
575 x = get_centered_x(s);
588 y += Current_font->h;
589 if (sx==0x8000) { //centered
590 x = get_centered_x(s);
597 letter = get_char_width(s[0],s[1],&width,&spacing);
600 //not in font, draw as space
608 // Check if this character is totally clipped
609 if ( x + width < gr_screen.clip_left ) continue;
610 if ( y + Current_font->h < gr_screen.clip_top ) continue;
611 if ( x > gr_screen.clip_right ) continue;
612 if ( y > gr_screen.clip_bottom ) continue;
615 if ( x < gr_screen.clip_left ) xd = gr_screen.clip_left - x;
616 if ( y < gr_screen.clip_top ) yd = gr_screen.clip_top - y;
620 wc = width - xd; hc = Current_font->h - yd;
621 if ( xc + wc > gr_screen.clip_right ) wc = gr_screen.clip_right - xc;
622 if ( yc + hc > gr_screen.clip_bottom ) hc = gr_screen.clip_bottom - yc;
624 if ( wc < 1 ) continue;
625 if ( hc < 1 ) continue;
627 float u = i2fl(Current_font->bm_u[letter] + xd);
628 float v = i2fl(Current_font->bm_v[letter] + yd);
630 x1 = i2fl(xc + gr_screen.offset_x);
631 y1 = i2fl(yc + gr_screen.offset_y);
635 u0 = u_scale * (u * fbw);
636 v0 = v_scale * (v * fbh);
638 u1 = u_scale * ((u+i2fl(wc)) * fbw);
639 v1 = v_scale * ((v+i2fl(hc)) * fbh);
641 // maybe go ahead and draw
642 if (rb_offset == alocsize) {
643 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
647 render_buffer[rb_offset].x = x1;
648 render_buffer[rb_offset].y = y1;
649 render_buffer[rb_offset].u = u0;
650 render_buffer[rb_offset].v = v0;
653 render_buffer[rb_offset].x = x1;
654 render_buffer[rb_offset].y = y2;
655 render_buffer[rb_offset].u = u0;
656 render_buffer[rb_offset].v = v1;
659 render_buffer[rb_offset].x = x2;
660 render_buffer[rb_offset].y = y1;
661 render_buffer[rb_offset].u = u1;
662 render_buffer[rb_offset].v = v0;
665 render_buffer[rb_offset].x = x2;
666 render_buffer[rb_offset].y = y2;
667 render_buffer[rb_offset].u = u1;
668 render_buffer[rb_offset].v = v1;
673 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
676 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
677 glDisableClientState(GL_VERTEX_ARRAY);
680 void gr_opengl1_line(int x1,int y1,int x2,int y2)
682 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
684 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
685 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),void());
690 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
691 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
692 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
693 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
695 opengl_alloc_render_buffer(2);
697 if ( x1 == x2 && y1 == y2 ) {
698 render_buffer[0].x = sx1;
699 render_buffer[0].y = sy1;
700 render_buffer[0].z = -0.99f;
702 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
703 gr_screen.current_color.blue, gr_screen.current_color.alpha);
705 glEnableClientState(GL_VERTEX_ARRAY);
706 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
708 glDrawArrays(GL_POINTS, 0, 1);
710 glDisableClientState(GL_VERTEX_ARRAY);
721 } else if ( y1 == y2 ) {
729 render_buffer[0].x = sx2;
730 render_buffer[0].y = sy2;
731 render_buffer[0].z = -0.99f;
733 render_buffer[1].x = sx1;
734 render_buffer[1].y = sy1;
735 render_buffer[1].z = -0.99f;
737 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
738 gr_screen.current_color.blue, gr_screen.current_color.alpha);
740 glEnableClientState(GL_VERTEX_ARRAY);
741 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
743 glDrawArrays(GL_LINES, 0, 2);
745 glDisableClientState(GL_VERTEX_ARRAY);
748 void gr_opengl1_aaline(vertex *v1, vertex *v2)
750 gr_opengl1_line( fl2i(v1->sx), fl2i(v1->sy), fl2i(v2->sx), fl2i(v2->sy) );
753 void gr_opengl1_gradient(int x1,int y1,int x2,int y2)
757 if ( !gr_screen.current_color.is_alphacolor ) {
758 gr_line( x1, y1, x2, y2 );
762 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
763 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),swapped=1);
765 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
767 int aa = swapped ? 0 : gr_screen.current_color.alpha;
768 int ba = swapped ? gr_screen.current_color.alpha : 0;
773 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
774 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
775 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
776 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
784 } else if ( y1 == y2 ) {
792 opengl_alloc_render_buffer(2);
794 render_buffer[0].r = gr_screen.current_color.red;
795 render_buffer[0].g = gr_screen.current_color.green;
796 render_buffer[0].b = gr_screen.current_color.blue;
797 render_buffer[0].a = (ubyte)ba;
798 render_buffer[0].x = sx2;
799 render_buffer[0].y = sy2;
800 render_buffer[0].z = -0.99f;
802 render_buffer[1].r = gr_screen.current_color.red;
803 render_buffer[1].g = gr_screen.current_color.green;
804 render_buffer[1].b = gr_screen.current_color.blue;
805 render_buffer[1].a = (ubyte)aa;
806 render_buffer[1].x = sx1;
807 render_buffer[1].y = sy1;
808 render_buffer[1].z = -0.99f;
810 glEnableClientState(GL_COLOR_ARRAY);
811 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
813 glEnableClientState(GL_VERTEX_ARRAY);
814 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
816 glDrawArrays(GL_LINES, 0, 2);
818 glDisableClientState(GL_COLOR_ARRAY);
819 glDisableClientState(GL_VERTEX_ARRAY);
822 void gr_opengl1_circle( int xc, int yc, int d )
832 if ( (xc+r) < gr_screen.clip_left ) return;
833 if ( (xc-r) > gr_screen.clip_right ) return;
834 if ( (yc+r) < gr_screen.clip_top ) return;
835 if ( (yc-r) > gr_screen.clip_bottom ) return;
838 // Draw the first octant
839 gr_opengl1_line( xc-y, yc-x, xc+y, yc-x );
840 gr_opengl1_line( xc-y, yc+x, xc+y, yc+x );
845 // Draw the second octant
846 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
847 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
855 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
856 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
861 void gr_opengl1_pixel(int x, int y)
868 void gr_opengl1_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct)
870 gr_set_bitmap(bmap1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - pct );
873 gr_set_bitmap(bmap2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, pct );
877 void gr_opengl1_flash(int r, int g, int b)
884 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE );
886 float x1, x2, y1, y2;
887 x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x);
888 y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y);
889 x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x);
890 y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y);
892 glColor4ub((GLubyte)r, (GLubyte)g, (GLubyte)b, 255);
894 opengl_alloc_render_buffer(4);
896 render_buffer[0].x = x1;
897 render_buffer[0].y = y1;
898 render_buffer[0].z = -0.99f;
900 render_buffer[1].x = x1;
901 render_buffer[1].y = y2;
902 render_buffer[1].z = -0.99f;
904 render_buffer[2].x = x2;
905 render_buffer[2].y = y1;
906 render_buffer[2].z = -0.99f;
908 render_buffer[3].x = x2;
909 render_buffer[3].y = y2;
910 render_buffer[3].z = -0.99f;
912 glEnableClientState(GL_VERTEX_ARRAY);
913 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
915 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
917 glDisableClientState(GL_VERTEX_ARRAY);
921 void gr_opengl1_tmapper( int nverts, vertex **verts, uint flags )
923 opengl1_tmapper_internal( nverts, verts, flags, 0 );
926 #define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0))
928 void gr_opengl1_scaler(vertex *va, vertex *vb )
930 float x0, y0, x1, y1;
931 float u0, v0, u1, v1;
932 float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
933 float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
934 float xmin, xmax, ymin, ymax;
935 int dx0, dy0, dx1, dy1;
937 //============= CLIP IT =====================
939 x0 = va->sx; y0 = va->sy;
940 x1 = vb->sx; y1 = vb->sy;
942 xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top);
943 xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom);
945 u0 = va->u; v0 = va->v;
946 u1 = vb->u; v1 = vb->v;
948 // Check for obviously offscreen bitmaps...
949 if ( (y1<=y0) || (x1<=x0) ) return;
950 if ( (x1<xmin ) || (x0>xmax) ) return;
951 if ( (y1<ymin ) || (y0>ymax) ) return;
953 clipped_u0 = u0; clipped_v0 = v0;
954 clipped_u1 = u1; clipped_v1 = v1;
956 clipped_x0 = x0; clipped_y0 = y0;
957 clipped_x1 = x1; clipped_y1 = y1;
959 // Clip the left, moving u0 right as necessary
961 clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1);
965 // Clip the right, moving u1 left as necessary
967 clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1);
971 // Clip the top, moving v0 down as necessary
973 clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1);
977 // Clip the bottom, moving v1 up as necessary
979 clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1);
983 dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1);
984 dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1);
986 if (dx1<=dx0) return;
987 if (dy1<=dy0) return;
989 //============= DRAW IT =====================
995 v[0].sx = clipped_x0;
996 v[0].sy = clipped_y0;
1000 v[0].v = clipped_v0;
1003 v[1].sx = clipped_x1;
1004 v[1].sy = clipped_y0;
1007 v[1].u = clipped_u1;
1008 v[1].v = clipped_v0;
1011 v[2].sx = clipped_x1;
1012 v[2].sy = clipped_y1;
1015 v[2].u = clipped_u1;
1016 v[2].v = clipped_v1;
1019 v[3].sx = clipped_x0;
1020 v[3].sy = clipped_y1;
1023 v[3].u = clipped_u0;
1024 v[3].v = clipped_v1;
1026 opengl1_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 );