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 #define NEBULA_COLORS 20
27 static void opengl1_rect_internal(int x, int y, int w, int h, int r, int g, int b, int a)
31 vertex *verts[4] = {&v[0], &v[1], &v[2], &v[3]};
33 saved_zbuf = gr_zbuffer_get();
35 // start the frame, no zbuffering, no culling
37 gr_zbuffer_set(GR_ZBUFF_NONE);
46 v[0].flags = PF_PROJECTED;
53 v[1].sx = i2fl(x + w);
58 v[1].flags = PF_PROJECTED;
65 v[2].sx = i2fl(x + w);
66 v[2].sy = i2fl(y + h);
70 v[2].flags = PF_PROJECTED;
78 v[3].sy = i2fl(y + h);
82 v[3].flags = PF_PROJECTED;
90 g3_draw_poly_constant_sw(4, verts, TMAP_FLAG_GOURAUD | TMAP_FLAG_RGB | TMAP_FLAG_ALPHA, 0.1f);
94 // restore zbuffer and culling
95 gr_zbuffer_set(saved_zbuf);
99 static void opengl1_aabitmap_ex_internal(int x,int y,int w,int h,int sx,int sy)
101 if ( (w < 1) || (h < 1) ) {
105 if ( !gr_screen.current_color.is_alphacolor ) {
109 float u_scale, v_scale;
111 if ( !opengl1_tcache_set(gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP,
112 &u_scale, &v_scale, 0, -1, -1, 0) )
114 // Couldn't set texture
115 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
119 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
121 float u0, u1, v0, v1;
122 float x1, x2, y1, y2;
125 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
127 u0 = u_scale*i2fl(sx)/i2fl(bw);
128 v0 = v_scale*i2fl(sy)/i2fl(bh);
130 u1 = u_scale*i2fl(sx+w)/i2fl(bw);
131 v1 = v_scale*i2fl(sy+h)/i2fl(bh);
133 x1 = i2fl(x+gr_screen.offset_x);
134 y1 = i2fl(y+gr_screen.offset_y);
135 x2 = i2fl(x+w+gr_screen.offset_x);
136 y2 = i2fl(y+h+gr_screen.offset_y);
138 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
139 gr_screen.current_color.blue,gr_screen.current_color.alpha);
141 opengl_alloc_render_buffer(4);
143 render_buffer[0].x = x1;
144 render_buffer[0].y = y1;
145 render_buffer[0].u = u0;
146 render_buffer[0].v = v0;
148 render_buffer[1].x = x1;
149 render_buffer[1].y = y2;
150 render_buffer[1].u = u0;
151 render_buffer[1].v = v1;
153 render_buffer[2].x = x2;
154 render_buffer[2].y = y1;
155 render_buffer[2].u = u1;
156 render_buffer[2].v = v0;
158 render_buffer[3].x = x2;
159 render_buffer[3].y = y2;
160 render_buffer[3].u = u1;
161 render_buffer[3].v = v1;
163 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
164 glEnableClientState(GL_VERTEX_ARRAY);
166 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
167 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
169 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
171 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
172 glDisableClientState(GL_VERTEX_ARRAY);
175 static void opengl1_tmapper_internal( int nv, vertex ** verts, uint flags, int is_scaler )
178 float u_scale = 1.0f, v_scale = 1.0f;
180 gr_texture_source texture_source = TEXTURE_SOURCE_NONE;
181 gr_alpha_blend alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA;
182 gr_zbuffer_type zbuffer_type = ZBUFFER_TYPE_NONE;
185 if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) {
186 zbuffer_type = ZBUFFER_TYPE_READ;
188 zbuffer_type = ZBUFFER_TYPE_FULL;
192 int tmap_type = TCACHE_TYPE_NORMAL;
194 ubyte r = 255, g = 255, b = 255, a = 255;
196 if ( !(flags & TMAP_FLAG_TEXTURED) ) {
197 r = gr_screen.current_color.red;
198 g = gr_screen.current_color.green;
199 b = gr_screen.current_color.blue;
202 if (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) {
203 alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE;
205 // Blend with screen pixel using src*alpha+dst
207 if (gr_screen.current_alpha < 1.0f) {
208 r = ubyte((r * gr_screen.current_alpha) + 0.5f);
209 g = ubyte((g * gr_screen.current_alpha) + 0.5f);
210 b = ubyte((b * gr_screen.current_alpha) + 0.5f);
214 if (flags & TMAP_FLAG_BITMAP_SECTION) {
215 SDL_assert( !(flags & TMAP_FLAG_BITMAP_INTERFACE) );
216 tmap_type = TCACHE_TYPE_BITMAP_SECTION;
217 } else if (flags & TMAP_FLAG_BITMAP_INTERFACE) {
218 SDL_assert( !(flags & TMAP_FLAG_BITMAP_SECTION) );
219 tmap_type = TCACHE_TYPE_BITMAP_INTERFACE;
222 if (flags & TMAP_FLAG_TEXTURED) {
223 if ( !opengl1_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale,
224 &v_scale, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy, 0) )
226 mprintf(( "Not rendering a texture because it didn't fit in VRAM!\n" ));
230 // use non-filtered textures for bitmap sections and UI graphics
232 case TCACHE_TYPE_BITMAP_INTERFACE:
233 case TCACHE_TYPE_BITMAP_SECTION:
234 texture_source = TEXTURE_SOURCE_NO_FILTERING;
238 texture_source = TEXTURE_SOURCE_DECAL;
244 opengl1_set_state( texture_source, alpha_blend, zbuffer_type );
246 float ox = gr_screen.offset_x * 16.0f;
247 float oy = gr_screen.offset_y * 16.0f;
249 if (flags & TMAP_FLAG_PIXEL_FOG) {
256 for (i = nv-1; i >= 0; i--) {
257 vertex * va = verts[i];
259 sx = (va->sx * 16.0f + ox) / 16.0f;
260 sy = (va->sy * 16.0f + oy) / 16.0f;
262 neb2_get_pixel((int)sx, (int)sy, &r, &g, &b);
273 gr_opengl1_fog_set(GR_FOGMODE_FOG, ra, ga, ba, -1.0f, -1.0f);
276 opengl_alloc_render_buffer(nv);
280 float sx, sy, sz = 0.99f, rhw = 1.0f;
282 bool bZval = (Gr_zbuffering || (flags & TMAP_FLAG_NEBULA));
283 bool bCorrect = (flags & TMAP_FLAG_CORRECT);
284 bool bAlpha = (flags & TMAP_FLAG_ALPHA);
285 bool bNebula = (flags & TMAP_FLAG_NEBULA);
286 bool bRamp = ((flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD));
287 bool bRGB = ((flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD));
288 bool bTextured = (flags & TMAP_FLAG_TEXTURED);
290 for (i = nv-1; i >= 0; i--) {
291 vertex *va = verts[i];
294 sz = 1.0f - 1.0f / (1.0f + va->z / (32768.0f / 256.0f));
310 // Make 0.75 be 256.0f
311 r = Gr_gamma_lookup[va->r];
312 g = Gr_gamma_lookup[va->g];
313 b = Gr_gamma_lookup[va->b];
314 } else if (bNebula) {
315 int pal = (va->b*(NEBULA_COLORS-1))/255;
316 r = gr_palette[pal*3+0];
317 g = gr_palette[pal*3+1];
318 b = gr_palette[pal*3+2];
320 r = g = b = Gr_gamma_lookup[va->b];
323 render_buffer[rb_offset].r = r;
324 render_buffer[rb_offset].g = g;
325 render_buffer[rb_offset].b = b;
326 render_buffer[rb_offset].a = a;
328 sx = (va->sx * 16.0f + ox) / 16.0f;
329 sy = (va->sy * 16.0f + oy) / 16.0f;
332 render_buffer[rb_offset].u = va->u * u_scale;
333 render_buffer[rb_offset].v = va->v * v_scale;
336 render_buffer[rb_offset].x = sx * rhw;
337 render_buffer[rb_offset].y = sy * rhw;
338 render_buffer[rb_offset].z = -sz * rhw;
339 render_buffer[rb_offset].w = rhw;
344 if (flags & TMAP_FLAG_TEXTURED) {
345 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
346 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
349 glEnableClientState(GL_COLOR_ARRAY);
350 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
352 glEnableClientState(GL_VERTEX_ARRAY);
353 glVertexPointer(4, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
355 glDrawArrays(GL_TRIANGLE_FAN, 0, rb_offset);
357 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
358 glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
359 glDisableClientState(GL_COLOR_ARRAY);
360 glDisableClientState(GL_VERTEX_ARRAY);
363 void gr_opengl1_rect(int x,int y,int w,int h)
365 opengl1_rect_internal(x, y, w, h, gr_screen.current_color.red,
366 gr_screen.current_color.green, gr_screen.current_color.blue,
367 gr_screen.current_color.alpha);
370 void gr_opengl1_shade(int x,int y,int w,int h)
377 r = fl2i(gr_screen.current_shader.r*255.0f*shade1);
378 if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
379 g = fl2i(gr_screen.current_shader.g*255.0f*shade1);
380 if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
381 b = fl2i(gr_screen.current_shader.b*255.0f*shade1);
382 if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
383 a = fl2i(gr_screen.current_shader.c*255.0f*shade2);
384 if ( a < 0 ) a = 0; else if ( a > 255 ) a = 255;
386 opengl1_rect_internal(x, y, w, h, r, g, b, a);
389 void gr_opengl1_aabitmap_ex(int x,int y,int w,int h,int sx,int sy)
396 int dx1=x, dx2=x+w-1;
397 int dy1=y, dy2=y+h-1;
400 bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL );
405 if ( count > 1 ) Int3();
409 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
410 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
411 if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
412 if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
413 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
414 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
441 if ( w < 1 ) return; // clipped away!
442 if ( h < 1 ) return; // clipped away!
446 // Make sure clipping algorithm works
450 SDL_assert( w == (dx2-dx1+1) );
451 SDL_assert( h == (dy2-dy1+1) );
452 SDL_assert( sx >= 0 );
453 SDL_assert( sy >= 0 );
454 SDL_assert( sx+w <= bw );
455 SDL_assert( sy+h <= bh );
456 SDL_assert( dx2 >= dx1 );
457 SDL_assert( dy2 >= dy1 );
458 SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) );
459 SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) );
460 SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) );
461 SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) );
464 // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions.
465 opengl1_aabitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
468 void gr_opengl1_aabitmap(int x, int y)
472 bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
473 int dx1=x, dx2=x+w-1;
474 int dy1=y, dy2=y+h-1;
477 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
478 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
479 if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
480 if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
481 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
482 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
484 if ( sx < 0 ) return;
485 if ( sy < 0 ) return;
486 if ( sx >= w ) return;
487 if ( sy >= h ) return;
489 // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
490 gr_opengl1_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
493 void gr_opengl1_string( int sx, int sy, const char *s )
495 int width, spacing, letter;
498 float u_scale, v_scale;
499 float u0, u1, v0, v1;
500 float x1, x2, y1, y2;
504 if ( !Current_font ) {
508 gr_set_bitmap(Current_font->bitmap_id, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
510 if ( !opengl1_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 0, -1, -1, 0 ) ) {
511 // Couldn't set texture
512 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
516 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
518 fbw = 1.0f / i2fl(bw);
519 fbh = 1.0f / i2fl(bh);
521 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
523 // don't want to create a super huge buffer size (i.e. credits text)
524 const int alocsize = 320; // 80 characters max per render call
525 opengl_alloc_render_buffer(alocsize);
527 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
528 gr_screen.current_color.blue, gr_screen.current_color.alpha);
530 glEnableClientState(GL_VERTEX_ARRAY);
531 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
533 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
534 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
538 if (sx==0x8000) { //centered
539 x = get_centered_x(s);
552 y += Current_font->h;
553 if (sx==0x8000) { //centered
554 x = get_centered_x(s);
561 letter = get_char_width(s[0],s[1],&width,&spacing);
564 //not in font, draw as space
572 // Check if this character is totally clipped
573 if ( x + width < gr_screen.clip_left ) continue;
574 if ( y + Current_font->h < gr_screen.clip_top ) continue;
575 if ( x > gr_screen.clip_right ) continue;
576 if ( y > gr_screen.clip_bottom ) continue;
579 if ( x < gr_screen.clip_left ) xd = gr_screen.clip_left - x;
580 if ( y < gr_screen.clip_top ) yd = gr_screen.clip_top - y;
584 wc = width - xd; hc = Current_font->h - yd;
585 if ( xc + wc > gr_screen.clip_right ) wc = gr_screen.clip_right - xc;
586 if ( yc + hc > gr_screen.clip_bottom ) hc = gr_screen.clip_bottom - yc;
588 if ( wc < 1 ) continue;
589 if ( hc < 1 ) continue;
591 float u = i2fl(Current_font->bm_u[letter] + xd);
592 float v = i2fl(Current_font->bm_v[letter] + yd);
594 x1 = i2fl(xc + gr_screen.offset_x);
595 y1 = i2fl(yc + gr_screen.offset_y);
599 u0 = u_scale * (u * fbw);
600 v0 = v_scale * (v * fbh);
602 u1 = u_scale * ((u+i2fl(wc)) * fbw);
603 v1 = v_scale * ((v+i2fl(hc)) * fbh);
605 // maybe go ahead and draw
606 if (rb_offset == alocsize) {
607 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
611 render_buffer[rb_offset].x = x1;
612 render_buffer[rb_offset].y = y1;
613 render_buffer[rb_offset].u = u0;
614 render_buffer[rb_offset].v = v0;
617 render_buffer[rb_offset].x = x1;
618 render_buffer[rb_offset].y = y2;
619 render_buffer[rb_offset].u = u0;
620 render_buffer[rb_offset].v = v1;
623 render_buffer[rb_offset].x = x2;
624 render_buffer[rb_offset].y = y1;
625 render_buffer[rb_offset].u = u1;
626 render_buffer[rb_offset].v = v0;
629 render_buffer[rb_offset].x = x2;
630 render_buffer[rb_offset].y = y2;
631 render_buffer[rb_offset].u = u1;
632 render_buffer[rb_offset].v = v1;
637 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
640 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
641 glDisableClientState(GL_VERTEX_ARRAY);
644 void gr_opengl1_line(int x1,int y1,int x2,int y2)
646 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
648 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
649 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),void());
654 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
655 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
656 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
657 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
659 opengl_alloc_render_buffer(2);
661 if ( x1 == x2 && y1 == y2 ) {
662 render_buffer[0].x = sx1;
663 render_buffer[0].y = sy1;
664 render_buffer[0].z = -0.99f;
666 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
667 gr_screen.current_color.blue, gr_screen.current_color.alpha);
669 glEnableClientState(GL_VERTEX_ARRAY);
670 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
672 glDrawArrays(GL_POINTS, 0, 1);
674 glDisableClientState(GL_VERTEX_ARRAY);
685 } else if ( y1 == y2 ) {
693 render_buffer[0].x = sx2;
694 render_buffer[0].y = sy2;
695 render_buffer[0].z = -0.99f;
697 render_buffer[1].x = sx1;
698 render_buffer[1].y = sy1;
699 render_buffer[1].z = -0.99f;
701 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
702 gr_screen.current_color.blue, gr_screen.current_color.alpha);
704 glEnableClientState(GL_VERTEX_ARRAY);
705 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
707 glDrawArrays(GL_LINES, 0, 2);
709 glDisableClientState(GL_VERTEX_ARRAY);
712 void gr_opengl1_aaline(vertex *v1, vertex *v2)
714 gr_opengl1_line( fl2i(v1->sx), fl2i(v1->sy), fl2i(v2->sx), fl2i(v2->sy) );
717 void gr_opengl1_gradient(int x1,int y1,int x2,int y2)
721 if ( !gr_screen.current_color.is_alphacolor ) {
722 gr_line( x1, y1, x2, y2 );
726 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
727 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),swapped=1);
729 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
731 int aa = swapped ? 0 : gr_screen.current_color.alpha;
732 int ba = swapped ? gr_screen.current_color.alpha : 0;
737 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
738 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
739 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
740 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
748 } else if ( y1 == y2 ) {
756 opengl_alloc_render_buffer(2);
758 render_buffer[0].r = gr_screen.current_color.red;
759 render_buffer[0].g = gr_screen.current_color.green;
760 render_buffer[0].b = gr_screen.current_color.blue;
761 render_buffer[0].a = (ubyte)ba;
762 render_buffer[0].x = sx2;
763 render_buffer[0].y = sy2;
764 render_buffer[0].z = -0.99f;
766 render_buffer[1].r = gr_screen.current_color.red;
767 render_buffer[1].g = gr_screen.current_color.green;
768 render_buffer[1].b = gr_screen.current_color.blue;
769 render_buffer[1].a = (ubyte)aa;
770 render_buffer[1].x = sx1;
771 render_buffer[1].y = sy1;
772 render_buffer[1].z = -0.99f;
774 glEnableClientState(GL_COLOR_ARRAY);
775 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
777 glEnableClientState(GL_VERTEX_ARRAY);
778 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
780 glDrawArrays(GL_LINES, 0, 2);
782 glDisableClientState(GL_COLOR_ARRAY);
783 glDisableClientState(GL_VERTEX_ARRAY);
786 void gr_opengl1_circle( int xc, int yc, int d )
796 if ( (xc+r) < gr_screen.clip_left ) return;
797 if ( (xc-r) > gr_screen.clip_right ) return;
798 if ( (yc+r) < gr_screen.clip_top ) return;
799 if ( (yc-r) > gr_screen.clip_bottom ) return;
802 // Draw the first octant
803 gr_opengl1_line( xc-y, yc-x, xc+y, yc-x );
804 gr_opengl1_line( xc-y, yc+x, xc+y, yc+x );
809 // Draw the second octant
810 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
811 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
819 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
820 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
825 void gr_opengl1_pixel(int x, int y)
832 void gr_opengl1_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct)
834 gr_set_bitmap(bmap1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - pct );
837 gr_set_bitmap(bmap2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, pct );
841 void gr_opengl1_flash(int r, int g, int b)
848 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE );
850 float x1, x2, y1, y2;
851 x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x);
852 y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y);
853 x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x);
854 y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y);
856 glColor4ub((GLubyte)r, (GLubyte)g, (GLubyte)b, 255);
858 opengl_alloc_render_buffer(4);
860 render_buffer[0].x = x1;
861 render_buffer[0].y = y1;
862 render_buffer[0].z = -0.99f;
864 render_buffer[1].x = x1;
865 render_buffer[1].y = y2;
866 render_buffer[1].z = -0.99f;
868 render_buffer[2].x = x2;
869 render_buffer[2].y = y1;
870 render_buffer[2].z = -0.99f;
872 render_buffer[3].x = x2;
873 render_buffer[3].y = y2;
874 render_buffer[3].z = -0.99f;
876 glEnableClientState(GL_VERTEX_ARRAY);
877 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
879 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
881 glDisableClientState(GL_VERTEX_ARRAY);
885 void gr_opengl1_tmapper( int nverts, vertex **verts, uint flags )
887 opengl1_tmapper_internal( nverts, verts, flags, 0 );
890 #define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0))
892 void gr_opengl1_scaler(vertex *va, vertex *vb )
894 float x0, y0, x1, y1;
895 float u0, v0, u1, v1;
896 float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
897 float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
898 float xmin, xmax, ymin, ymax;
899 int dx0, dy0, dx1, dy1;
901 //============= CLIP IT =====================
903 x0 = va->sx; y0 = va->sy;
904 x1 = vb->sx; y1 = vb->sy;
906 xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top);
907 xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom);
909 u0 = va->u; v0 = va->v;
910 u1 = vb->u; v1 = vb->v;
912 // Check for obviously offscreen bitmaps...
913 if ( (y1<=y0) || (x1<=x0) ) return;
914 if ( (x1<xmin ) || (x0>xmax) ) return;
915 if ( (y1<ymin ) || (y0>ymax) ) return;
917 clipped_u0 = u0; clipped_v0 = v0;
918 clipped_u1 = u1; clipped_v1 = v1;
920 clipped_x0 = x0; clipped_y0 = y0;
921 clipped_x1 = x1; clipped_y1 = y1;
923 // Clip the left, moving u0 right as necessary
925 clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1);
929 // Clip the right, moving u1 left as necessary
931 clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1);
935 // Clip the top, moving v0 down as necessary
937 clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1);
941 // Clip the bottom, moving v1 up as necessary
943 clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1);
947 dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1);
948 dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1);
950 if (dx1<=dx0) return;
951 if (dy1<=dy0) return;
953 //============= DRAW IT =====================
959 v[0].sx = clipped_x0;
960 v[0].sy = clipped_y0;
967 v[1].sx = clipped_x1;
968 v[1].sy = clipped_y0;
975 v[2].sx = clipped_x1;
976 v[2].sy = clipped_y1;
983 v[3].sx = clipped_x0;
984 v[3].sy = clipped_y1;
990 opengl1_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 );