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
12 #include "gropengl1.h"
13 #include "gropenglinternal.h"
15 #include "grinternal.h"
22 extern int OGL_fog_mode;
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_stuff_fog_value(float z, float *f_val)
183 f_float = 1.0f - ((gr_screen.fog_far - z) / (gr_screen.fog_far - gr_screen.fog_near));
185 if (f_float < 0.0f) {
187 } else if (f_float > 1.0f) {
194 static void opengl1_tmapper_internal( int nv, vertex ** verts, uint flags, int is_scaler )
197 float u_scale = 1.0f, v_scale = 1.0f;
199 // Make nebula use the texture mapper... this blends the colors better.
200 if ( flags & TMAP_FLAG_NEBULA ){
204 gr_texture_source texture_source = (gr_texture_source)-1;
205 gr_alpha_blend alpha_blend = (gr_alpha_blend)-1;
206 gr_zbuffer_type zbuffer_type = (gr_zbuffer_type)-1;
209 if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) {
210 zbuffer_type = ZBUFFER_TYPE_READ;
212 zbuffer_type = ZBUFFER_TYPE_FULL;
215 zbuffer_type = ZBUFFER_TYPE_NONE;
220 int tmap_type = TCACHE_TYPE_NORMAL;
224 if ( flags & TMAP_FLAG_TEXTURED ) {
227 r = gr_screen.current_color.red;
228 g = gr_screen.current_color.green;
229 b = gr_screen.current_color.blue;
232 if (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) {
233 tmap_type = TCACHE_TYPE_NORMAL;
234 alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE;
236 // Blend with screen pixel using src*alpha+dst
240 if (gr_screen.current_alpha <= 1.0f) {
241 r = fl2i((r * gr_screen.current_alpha) + 0.5f);
242 g = fl2i((g * gr_screen.current_alpha) + 0.5f);
243 b = fl2i((b * gr_screen.current_alpha) + 0.5f);
246 alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA;
250 if (flags & TMAP_FLAG_BITMAP_SECTION) {
251 SDL_assert( !(flags & TMAP_FLAG_BITMAP_INTERFACE) );
252 tmap_type = TCACHE_TYPE_BITMAP_SECTION;
253 } else if (flags & TMAP_FLAG_BITMAP_INTERFACE) {
254 SDL_assert( !(flags & TMAP_FLAG_BITMAP_SECTION) );
255 tmap_type = TCACHE_TYPE_BITMAP_INTERFACE;
258 texture_source = TEXTURE_SOURCE_NONE;
260 if (flags & TMAP_FLAG_TEXTURED) {
261 if ( !opengl1_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale,
262 &v_scale, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy, 0) )
264 mprintf(( "Not rendering a texture because it didn't fit in VRAM!\n" ));
268 // use non-filtered textures for bitmap sections and UI graphics
270 case TCACHE_TYPE_BITMAP_INTERFACE:
271 case TCACHE_TYPE_BITMAP_SECTION:
272 texture_source = TEXTURE_SOURCE_NO_FILTERING;
276 texture_source = TEXTURE_SOURCE_DECAL;
282 opengl1_set_state( texture_source, alpha_blend, zbuffer_type );
284 float fr = 1.0f, fg = 1.0f, fb = 1.0f;
286 if (flags & TMAP_FLAG_PIXEL_FOG) {
295 for (i=nv-1;i>=0;i--) // DDOI - change polygon winding
297 vertex * va = verts[i];
299 x = fl2i(va->sx*16.0f);
300 y = fl2i(va->sy*16.0f);
302 x += gr_screen.offset_x*16;
303 y += gr_screen.offset_y*16;
305 sx = i2fl(x) / 16.0f;
306 sy = i2fl(y) / 16.0f;
308 neb2_get_pixel((int)sx, (int)sy, &r, &g, &b);
319 gr_fog_set(GR_FOGMODE_FOG, ra, ga, ba, -1.0f, -1.0f);
326 opengl_alloc_render_buffer(nv);
331 float sx, sy, sz, rhw;
334 for (i = nv-1; i >= 0; i--) {
335 vertex * va = verts[i];
337 if ( Gr_zbuffering || (flags & TMAP_FLAG_NEBULA) ) {
338 sz = 1.0 - 1.0 / (1.0 + va->z / (32768.0 / 256.0));
347 if (flags & TMAP_FLAG_CORRECT) {
353 if (flags & TMAP_FLAG_ALPHA) {
359 if (flags & TMAP_FLAG_NEBULA ) {
360 int pal = (verts[i]->b*(NEBULA_COLORS-1))/255;
361 r = gr_palette[pal*3+0];
362 g = gr_palette[pal*3+1];
363 b = gr_palette[pal*3+2];
364 } else if ( (flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD) ) {
365 r = Gr_gamma_lookup[verts[i]->b];
366 g = Gr_gamma_lookup[verts[i]->b];
367 b = Gr_gamma_lookup[verts[i]->b];
368 } else if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
369 // Make 0.75 be 256.0f
370 r = Gr_gamma_lookup[verts[i]->r];
371 g = Gr_gamma_lookup[verts[i]->g];
372 b = Gr_gamma_lookup[verts[i]->b];
374 // use constant RGB values...
377 render_buffer[rb_offset].r = r;
378 render_buffer[rb_offset].g = g;
379 render_buffer[rb_offset].b = b;
380 render_buffer[rb_offset].a = a;
382 if ( (flags & TMAP_FLAG_PIXEL_FOG) && (OGL_fog_mode == 1) ) {
385 opengl1_stuff_fog_value(va->z, &f_val);
387 render_buffer[rb_offset].sr = fl2i(((fr * f_val) * 255.0f) + 0.5f);
388 render_buffer[rb_offset].sg = fl2i(((fg * f_val) * 255.0f) + 0.5f);
389 render_buffer[rb_offset].sb = fl2i(((fb * f_val) * 255.0f) + 0.5f);
392 x = fl2i(va->sx*16.0f);
393 y = fl2i(va->sy*16.0f);
395 x += gr_screen.offset_x*16;
396 y += gr_screen.offset_y*16;
398 sx = i2fl(x) / 16.0f;
399 sy = i2fl(y) / 16.0f;
401 if ( flags & TMAP_FLAG_TEXTURED ) {
402 render_buffer[rb_offset].u = va->u * u_scale;
403 render_buffer[rb_offset].v = va->v * v_scale;
406 render_buffer[rb_offset].x = sx * rhw;
407 render_buffer[rb_offset].y = sy * rhw;
408 render_buffer[rb_offset].z = -sz * rhw;
409 render_buffer[rb_offset].w = rhw;
414 if (flags & TMAP_FLAG_TEXTURED) {
415 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
416 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
419 if ( (gr_screen.current_fog_mode != GR_FOGMODE_NONE) && (OGL_fog_mode == 1) ) {
420 glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
421 vglSecondaryColorPointer(3, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].sr);
424 glEnableClientState(GL_COLOR_ARRAY);
425 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
427 glEnableClientState(GL_VERTEX_ARRAY);
428 glVertexPointer(4, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
430 glDrawArrays(GL_TRIANGLE_FAN, 0, rb_offset);
432 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
433 glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
434 glDisableClientState(GL_COLOR_ARRAY);
435 glDisableClientState(GL_VERTEX_ARRAY);
438 void gr_opengl1_rect(int x,int y,int w,int h)
440 opengl1_rect_internal(x, y, w, h, gr_screen.current_color.red,
441 gr_screen.current_color.green, gr_screen.current_color.blue,
442 gr_screen.current_color.alpha);
445 void gr_opengl1_shade(int x,int y,int w,int h)
452 r = fl2i(gr_screen.current_shader.r*255.0f*shade1);
453 if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
454 g = fl2i(gr_screen.current_shader.g*255.0f*shade1);
455 if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
456 b = fl2i(gr_screen.current_shader.b*255.0f*shade1);
457 if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
458 a = fl2i(gr_screen.current_shader.c*255.0f*shade2);
459 if ( a < 0 ) a = 0; else if ( a > 255 ) a = 255;
461 opengl1_rect_internal(x, y, w, h, r, g, b, a);
464 void gr_opengl1_aabitmap_ex(int x,int y,int w,int h,int sx,int sy)
471 int dx1=x, dx2=x+w-1;
472 int dy1=y, dy2=y+h-1;
475 bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL );
480 if ( count > 1 ) Int3();
484 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
485 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
486 if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
487 if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
488 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
489 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
516 if ( w < 1 ) return; // clipped away!
517 if ( h < 1 ) return; // clipped away!
521 // Make sure clipping algorithm works
525 SDL_assert( w == (dx2-dx1+1) );
526 SDL_assert( h == (dy2-dy1+1) );
527 SDL_assert( sx >= 0 );
528 SDL_assert( sy >= 0 );
529 SDL_assert( sx+w <= bw );
530 SDL_assert( sy+h <= bh );
531 SDL_assert( dx2 >= dx1 );
532 SDL_assert( dy2 >= dy1 );
533 SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) );
534 SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) );
535 SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) );
536 SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) );
539 // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions.
540 opengl1_aabitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
543 void gr_opengl1_aabitmap(int x, int y)
547 bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
548 int dx1=x, dx2=x+w-1;
549 int dy1=y, dy2=y+h-1;
552 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
553 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
554 if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
555 if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
556 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
557 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
559 if ( sx < 0 ) return;
560 if ( sy < 0 ) return;
561 if ( sx >= w ) return;
562 if ( sy >= h ) return;
564 // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
565 gr_opengl1_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
568 void gr_opengl1_string( int sx, int sy, const char *s )
570 int width, spacing, letter;
573 float u_scale, v_scale;
574 float u0, u1, v0, v1;
575 float x1, x2, y1, y2;
579 if ( !Current_font ) {
583 gr_set_bitmap(Current_font->bitmap_id, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
585 if ( !opengl1_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 0, -1, -1, 0 ) ) {
586 // Couldn't set texture
587 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
591 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
593 fbw = 1.0f / i2fl(bw);
594 fbh = 1.0f / i2fl(bh);
596 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
598 // don't want to create a super huge buffer size (i.e. credits text)
599 const int alocsize = 320; // 80 characters max per render call
600 opengl_alloc_render_buffer(alocsize);
602 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
603 gr_screen.current_color.blue, gr_screen.current_color.alpha);
605 glEnableClientState(GL_VERTEX_ARRAY);
606 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
608 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
609 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
614 if (sx==0x8000) { //centered
615 x = get_centered_x(s);
628 y += Current_font->h;
629 if (sx==0x8000) { //centered
630 x = get_centered_x(s);
637 letter = get_char_width(s[0],s[1],&width,&spacing);
640 //not in font, draw as space
648 // Check if this character is totally clipped
649 if ( x + width < gr_screen.clip_left ) continue;
650 if ( y + Current_font->h < gr_screen.clip_top ) continue;
651 if ( x > gr_screen.clip_right ) continue;
652 if ( y > gr_screen.clip_bottom ) continue;
655 if ( x < gr_screen.clip_left ) xd = gr_screen.clip_left - x;
656 if ( y < gr_screen.clip_top ) yd = gr_screen.clip_top - y;
660 wc = width - xd; hc = Current_font->h - yd;
661 if ( xc + wc > gr_screen.clip_right ) wc = gr_screen.clip_right - xc;
662 if ( yc + hc > gr_screen.clip_bottom ) hc = gr_screen.clip_bottom - yc;
664 if ( wc < 1 ) continue;
665 if ( hc < 1 ) continue;
667 float u = i2fl(Current_font->bm_u[letter] + xd);
668 float v = i2fl(Current_font->bm_v[letter] + yd);
670 x1 = i2fl(xc + gr_screen.offset_x);
671 y1 = i2fl(yc + gr_screen.offset_y);
675 u0 = u_scale * (u * fbw);
676 v0 = v_scale * (v * fbh);
678 u1 = u_scale * ((u+i2fl(wc)) * fbw);
679 v1 = v_scale * ((v+i2fl(hc)) * fbh);
681 // maybe go ahead and draw
682 if (rb_offset == alocsize) {
683 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
687 render_buffer[rb_offset].x = x1;
688 render_buffer[rb_offset].y = y1;
689 render_buffer[rb_offset].u = u0;
690 render_buffer[rb_offset].v = v0;
693 render_buffer[rb_offset].x = x1;
694 render_buffer[rb_offset].y = y2;
695 render_buffer[rb_offset].u = u0;
696 render_buffer[rb_offset].v = v1;
699 render_buffer[rb_offset].x = x2;
700 render_buffer[rb_offset].y = y1;
701 render_buffer[rb_offset].u = u1;
702 render_buffer[rb_offset].v = v0;
705 render_buffer[rb_offset].x = x2;
706 render_buffer[rb_offset].y = y2;
707 render_buffer[rb_offset].u = u1;
708 render_buffer[rb_offset].v = v1;
713 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
716 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
717 glDisableClientState(GL_VERTEX_ARRAY);
720 void gr_opengl1_line(int x1,int y1,int x2,int y2)
722 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
724 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
725 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),void());
730 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5;
731 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5;
732 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5;
733 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5;
735 opengl_alloc_render_buffer(2);
737 if ( x1 == x2 && y1 == y2 ) {
738 render_buffer[0].x = sx1;
739 render_buffer[0].y = sy1;
740 render_buffer[0].z = -0.99f;
742 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
743 gr_screen.current_color.blue, gr_screen.current_color.alpha);
745 glEnableClientState(GL_VERTEX_ARRAY);
746 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
748 glDrawArrays(GL_POINTS, 0, 1);
750 glDisableClientState(GL_VERTEX_ARRAY);
761 } else if ( y1 == y2 ) {
769 render_buffer[0].x = sx2;
770 render_buffer[0].y = sy2;
771 render_buffer[0].z = -0.99f;
773 render_buffer[1].x = sx1;
774 render_buffer[1].y = sy1;
775 render_buffer[1].z = -0.99f;
777 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
778 gr_screen.current_color.blue, gr_screen.current_color.alpha);
780 glEnableClientState(GL_VERTEX_ARRAY);
781 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
783 glDrawArrays(GL_LINES, 0, 2);
785 glDisableClientState(GL_VERTEX_ARRAY);
788 void gr_opengl1_aaline(vertex *v1, vertex *v2)
790 gr_opengl1_line( fl2i(v1->sx), fl2i(v1->sy), fl2i(v2->sx), fl2i(v2->sy) );
793 void gr_opengl1_gradient(int x1,int y1,int x2,int y2)
797 if ( !gr_screen.current_color.is_alphacolor ) {
798 gr_line( x1, y1, x2, y2 );
802 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
803 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),swapped=1);
805 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
807 int aa = swapped ? 0 : gr_screen.current_color.alpha;
808 int ba = swapped ? gr_screen.current_color.alpha : 0;
813 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5;
814 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5;
815 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5;
816 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5;
824 } else if ( y1 == y2 ) {
832 opengl_alloc_render_buffer(2);
834 render_buffer[0].r = gr_screen.current_color.red;
835 render_buffer[0].g = gr_screen.current_color.green;
836 render_buffer[0].b = gr_screen.current_color.blue;
837 render_buffer[0].a = ba;
838 render_buffer[0].x = sx2;
839 render_buffer[0].y = sy2;
840 render_buffer[0].z = -0.99f;
842 render_buffer[1].r = gr_screen.current_color.red;
843 render_buffer[1].g = gr_screen.current_color.green;
844 render_buffer[1].b = gr_screen.current_color.blue;
845 render_buffer[1].a = aa;
846 render_buffer[1].x = sx1;
847 render_buffer[1].y = sy1;
848 render_buffer[1].z = -0.99f;
850 glEnableClientState(GL_COLOR_ARRAY);
851 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
853 glEnableClientState(GL_VERTEX_ARRAY);
854 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
856 glDrawArrays(GL_LINES, 0, 2);
858 glDisableClientState(GL_COLOR_ARRAY);
859 glDisableClientState(GL_VERTEX_ARRAY);
862 void gr_opengl1_circle( int xc, int yc, int d )
872 if ( (xc+r) < gr_screen.clip_left ) return;
873 if ( (xc-r) > gr_screen.clip_right ) return;
874 if ( (yc+r) < gr_screen.clip_top ) return;
875 if ( (yc-r) > gr_screen.clip_bottom ) return;
878 // Draw the first octant
879 gr_opengl1_line( xc-y, yc-x, xc+y, yc-x );
880 gr_opengl1_line( xc-y, yc+x, xc+y, yc+x );
885 // Draw the second octant
886 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
887 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
895 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
896 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
901 void gr_opengl1_pixel(int x, int y)
908 void gr_opengl1_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct)
910 gr_set_bitmap(bmap1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - pct );
913 gr_set_bitmap(bmap2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, pct );
917 void gr_opengl1_flash(int r, int g, int b)
924 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE );
926 float x1, x2, y1, y2;
927 x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x);
928 y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y);
929 x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x);
930 y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y);
932 glColor4ub(r, g, b, 255);
934 opengl_alloc_render_buffer(4);
936 render_buffer[0].x = x1;
937 render_buffer[0].y = y1;
938 render_buffer[0].z = -0.99f;
940 render_buffer[1].x = x1;
941 render_buffer[1].y = y2;
942 render_buffer[1].z = -0.99f;
944 render_buffer[2].x = x2;
945 render_buffer[2].y = y1;
946 render_buffer[2].z = -0.99f;
948 render_buffer[3].x = x2;
949 render_buffer[3].y = y2;
950 render_buffer[3].z = -0.99f;
952 glEnableClientState(GL_VERTEX_ARRAY);
953 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
955 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
957 glDisableClientState(GL_VERTEX_ARRAY);
961 void gr_opengl1_tmapper( int nverts, vertex **verts, uint flags )
963 opengl1_tmapper_internal( nverts, verts, flags, 0 );
966 #define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0))
968 void gr_opengl1_scaler(vertex *va, vertex *vb )
970 float x0, y0, x1, y1;
971 float u0, v0, u1, v1;
972 float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
973 float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
974 float xmin, xmax, ymin, ymax;
975 int dx0, dy0, dx1, dy1;
977 //============= CLIP IT =====================
979 x0 = va->sx; y0 = va->sy;
980 x1 = vb->sx; y1 = vb->sy;
982 xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top);
983 xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom);
985 u0 = va->u; v0 = va->v;
986 u1 = vb->u; v1 = vb->v;
988 // Check for obviously offscreen bitmaps...
989 if ( (y1<=y0) || (x1<=x0) ) return;
990 if ( (x1<xmin ) || (x0>xmax) ) return;
991 if ( (y1<ymin ) || (y0>ymax) ) return;
993 clipped_u0 = u0; clipped_v0 = v0;
994 clipped_u1 = u1; clipped_v1 = v1;
996 clipped_x0 = x0; clipped_y0 = y0;
997 clipped_x1 = x1; clipped_y1 = y1;
999 // Clip the left, moving u0 right as necessary
1001 clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1);
1005 // Clip the right, moving u1 left as necessary
1007 clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1);
1011 // Clip the top, moving v0 down as necessary
1013 clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1);
1017 // Clip the bottom, moving v1 up as necessary
1019 clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1);
1023 dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1);
1024 dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1);
1026 if (dx1<=dx0) return;
1027 if (dy1<=dy0) return;
1029 //============= DRAW IT =====================
1035 v[0].sx = clipped_x0;
1036 v[0].sy = clipped_y0;
1039 v[0].u = clipped_u0;
1040 v[0].v = clipped_v0;
1043 v[1].sx = clipped_x1;
1044 v[1].sy = clipped_y0;
1047 v[1].u = clipped_u1;
1048 v[1].v = clipped_v0;
1051 v[2].sx = clipped_x1;
1052 v[2].sy = clipped_y1;
1055 v[2].u = clipped_u1;
1056 v[2].v = clipped_v1;
1059 v[3].sx = clipped_x0;
1060 v[3].sy = clipped_y1;
1063 v[3].u = clipped_u0;
1064 v[3].v = clipped_v1;
1066 opengl1_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 );