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_tmapper_internal( int nv, vertex ** verts, uint flags, int is_scaler )
180 float u_scale = 1.0f, v_scale = 1.0f;
182 gr_texture_source texture_source = TEXTURE_SOURCE_NONE;
183 gr_alpha_blend alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA;
184 gr_zbuffer_type zbuffer_type = ZBUFFER_TYPE_NONE;
187 if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) {
188 zbuffer_type = ZBUFFER_TYPE_READ;
190 zbuffer_type = ZBUFFER_TYPE_FULL;
194 int tmap_type = TCACHE_TYPE_NORMAL;
196 ubyte r = 255, g = 255, b = 255, a = 255;
198 if ( !(flags & TMAP_FLAG_TEXTURED) ) {
199 r = gr_screen.current_color.red;
200 g = gr_screen.current_color.green;
201 b = gr_screen.current_color.blue;
204 if (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) {
205 alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE;
207 // Blend with screen pixel using src*alpha+dst
209 if (gr_screen.current_alpha < 1.0f) {
210 r = ubyte((r * gr_screen.current_alpha) + 0.5f);
211 g = ubyte((g * gr_screen.current_alpha) + 0.5f);
212 b = ubyte((b * gr_screen.current_alpha) + 0.5f);
216 if (flags & TMAP_FLAG_BITMAP_SECTION) {
217 SDL_assert( !(flags & TMAP_FLAG_BITMAP_INTERFACE) );
218 tmap_type = TCACHE_TYPE_BITMAP_SECTION;
219 } else if (flags & TMAP_FLAG_BITMAP_INTERFACE) {
220 SDL_assert( !(flags & TMAP_FLAG_BITMAP_SECTION) );
221 tmap_type = TCACHE_TYPE_BITMAP_INTERFACE;
224 if (flags & TMAP_FLAG_TEXTURED) {
225 if ( !opengl1_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale,
226 &v_scale, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy, 0) )
228 mprintf(( "Not rendering a texture because it didn't fit in VRAM!\n" ));
232 // use non-filtered textures for bitmap sections and UI graphics
234 case TCACHE_TYPE_BITMAP_INTERFACE:
235 case TCACHE_TYPE_BITMAP_SECTION:
236 texture_source = TEXTURE_SOURCE_NO_FILTERING;
240 texture_source = TEXTURE_SOURCE_DECAL;
246 opengl1_set_state( texture_source, alpha_blend, zbuffer_type );
248 float ox = gr_screen.offset_x * 16.0f;
249 float oy = gr_screen.offset_y * 16.0f;
251 float fr = 1.0f, fg = 1.0f, fb = 1.0f;
253 if (flags & TMAP_FLAG_PIXEL_FOG) {
261 for (i=nv-1;i>=0;i--) // DDOI - change polygon winding
263 vertex * va = verts[i];
265 sx = (va->sx * 16.0f + ox) / 16.0f;
266 sy = (va->sy * 16.0f + oy) / 16.0f;
268 neb2_get_pixel((int)sx, (int)sy, &r, &g, &b);
279 gr_fog_set(GR_FOGMODE_FOG, ra, ga, ba, -1.0f, -1.0f);
286 opengl_alloc_render_buffer(nv);
290 float sx, sy, sz = 0.99f, rhw = 1.0f;
292 for (i = nv-1; i >= 0; i--) {
293 vertex *va = verts[i];
295 if ( Gr_zbuffering || (flags & TMAP_FLAG_NEBULA) ) {
296 sz = 1.0f - 1.0f / (1.0f + va->z / (32768.0f / 256.0f));
303 if (flags & TMAP_FLAG_CORRECT) {
307 if (flags & TMAP_FLAG_ALPHA) {
311 if (flags & TMAP_FLAG_NEBULA ) {
312 int pal = (verts[i]->b*(NEBULA_COLORS-1))/255;
313 r = gr_palette[pal*3+0];
314 g = gr_palette[pal*3+1];
315 b = gr_palette[pal*3+2];
316 } else if ( (flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD) ) {
317 r = g = b = Gr_gamma_lookup[verts[i]->b];
318 } else if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
319 // Make 0.75 be 256.0f
320 r = Gr_gamma_lookup[verts[i]->r];
321 g = Gr_gamma_lookup[verts[i]->g];
322 b = Gr_gamma_lookup[verts[i]->b];
325 render_buffer[rb_offset].r = r;
326 render_buffer[rb_offset].g = g;
327 render_buffer[rb_offset].b = b;
328 render_buffer[rb_offset].a = a;
330 if ( (flags & TMAP_FLAG_PIXEL_FOG) && (OGL_fog_mode == 1) ) {
333 opengl_stuff_fog_value(va->z, &f_val);
335 render_buffer[rb_offset].sr = (ubyte)(((fr * f_val) * 255.0f) + 0.5f);
336 render_buffer[rb_offset].sg = (ubyte)(((fg * f_val) * 255.0f) + 0.5f);
337 render_buffer[rb_offset].sb = (ubyte)(((fb * f_val) * 255.0f) + 0.5f);
340 sx = (va->sx * 16.0f + ox) / 16.0f;
341 sy = (va->sy * 16.0f + oy) / 16.0f;
343 if (flags & TMAP_FLAG_TEXTURED) {
344 render_buffer[rb_offset].u = va->u * u_scale;
345 render_buffer[rb_offset].v = va->v * v_scale;
348 render_buffer[rb_offset].x = sx * rhw;
349 render_buffer[rb_offset].y = sy * rhw;
350 render_buffer[rb_offset].z = -sz * rhw;
351 render_buffer[rb_offset].w = rhw;
356 if (flags & TMAP_FLAG_TEXTURED) {
357 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
358 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
361 if ( (gr_screen.current_fog_mode != GR_FOGMODE_NONE) && (OGL_fog_mode == 1) ) {
362 glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
363 vglSecondaryColorPointer(3, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].sr);
366 glEnableClientState(GL_COLOR_ARRAY);
367 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
369 glEnableClientState(GL_VERTEX_ARRAY);
370 glVertexPointer(4, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
372 glDrawArrays(GL_TRIANGLE_FAN, 0, rb_offset);
374 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
375 glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
376 glDisableClientState(GL_COLOR_ARRAY);
377 glDisableClientState(GL_VERTEX_ARRAY);
380 void gr_opengl1_rect(int x,int y,int w,int h)
382 opengl1_rect_internal(x, y, w, h, gr_screen.current_color.red,
383 gr_screen.current_color.green, gr_screen.current_color.blue,
384 gr_screen.current_color.alpha);
387 void gr_opengl1_shade(int x,int y,int w,int h)
394 r = fl2i(gr_screen.current_shader.r*255.0f*shade1);
395 if ( r < 0 ) r = 0; else if ( r > 255 ) r = 255;
396 g = fl2i(gr_screen.current_shader.g*255.0f*shade1);
397 if ( g < 0 ) g = 0; else if ( g > 255 ) g = 255;
398 b = fl2i(gr_screen.current_shader.b*255.0f*shade1);
399 if ( b < 0 ) b = 0; else if ( b > 255 ) b = 255;
400 a = fl2i(gr_screen.current_shader.c*255.0f*shade2);
401 if ( a < 0 ) a = 0; else if ( a > 255 ) a = 255;
403 opengl1_rect_internal(x, y, w, h, r, g, b, a);
406 void gr_opengl1_aabitmap_ex(int x,int y,int w,int h,int sx,int sy)
413 int dx1=x, dx2=x+w-1;
414 int dy1=y, dy2=y+h-1;
417 bm_get_info( gr_screen.current_bitmap, &bw, &bh, NULL );
422 if ( count > 1 ) Int3();
426 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
427 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
428 if ( dx1 < gr_screen.clip_left ) { sx += gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
429 if ( dy1 < gr_screen.clip_top ) { sy += gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
430 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
431 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
458 if ( w < 1 ) return; // clipped away!
459 if ( h < 1 ) return; // clipped away!
463 // Make sure clipping algorithm works
467 SDL_assert( w == (dx2-dx1+1) );
468 SDL_assert( h == (dy2-dy1+1) );
469 SDL_assert( sx >= 0 );
470 SDL_assert( sy >= 0 );
471 SDL_assert( sx+w <= bw );
472 SDL_assert( sy+h <= bh );
473 SDL_assert( dx2 >= dx1 );
474 SDL_assert( dy2 >= dy1 );
475 SDL_assert( (dx1 >= gr_screen.clip_left ) && (dx1 <= gr_screen.clip_right) );
476 SDL_assert( (dx2 >= gr_screen.clip_left ) && (dx2 <= gr_screen.clip_right) );
477 SDL_assert( (dy1 >= gr_screen.clip_top ) && (dy1 <= gr_screen.clip_bottom) );
478 SDL_assert( (dy2 >= gr_screen.clip_top ) && (dy2 <= gr_screen.clip_bottom) );
481 // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions.
482 opengl1_aabitmap_ex_internal(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
485 void gr_opengl1_aabitmap(int x, int y)
489 bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
490 int dx1=x, dx2=x+w-1;
491 int dy1=y, dy2=y+h-1;
494 if ((dx1 > gr_screen.clip_right ) || (dx2 < gr_screen.clip_left)) return;
495 if ((dy1 > gr_screen.clip_bottom ) || (dy2 < gr_screen.clip_top)) return;
496 if ( dx1 < gr_screen.clip_left ) { sx = gr_screen.clip_left-dx1; dx1 = gr_screen.clip_left; }
497 if ( dy1 < gr_screen.clip_top ) { sy = gr_screen.clip_top-dy1; dy1 = gr_screen.clip_top; }
498 if ( dx2 > gr_screen.clip_right ) { dx2 = gr_screen.clip_right; }
499 if ( dy2 > gr_screen.clip_bottom ) { dy2 = gr_screen.clip_bottom; }
501 if ( sx < 0 ) return;
502 if ( sy < 0 ) return;
503 if ( sx >= w ) return;
504 if ( sy >= h ) return;
506 // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
507 gr_opengl1_aabitmap_ex(dx1,dy1,dx2-dx1+1,dy2-dy1+1,sx,sy);
510 void gr_opengl1_string( int sx, int sy, const char *s )
512 int width, spacing, letter;
515 float u_scale, v_scale;
516 float u0, u1, v0, v1;
517 float x1, x2, y1, y2;
521 if ( !Current_font ) {
525 gr_set_bitmap(Current_font->bitmap_id, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
527 if ( !opengl1_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 0, -1, -1, 0 ) ) {
528 // Couldn't set texture
529 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
533 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
535 fbw = 1.0f / i2fl(bw);
536 fbh = 1.0f / i2fl(bh);
538 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
540 // don't want to create a super huge buffer size (i.e. credits text)
541 const int alocsize = 320; // 80 characters max per render call
542 opengl_alloc_render_buffer(alocsize);
544 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
545 gr_screen.current_color.blue, gr_screen.current_color.alpha);
547 glEnableClientState(GL_VERTEX_ARRAY);
548 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
550 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
551 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
555 if (sx==0x8000) { //centered
556 x = get_centered_x(s);
569 y += Current_font->h;
570 if (sx==0x8000) { //centered
571 x = get_centered_x(s);
578 letter = get_char_width(s[0],s[1],&width,&spacing);
581 //not in font, draw as space
589 // Check if this character is totally clipped
590 if ( x + width < gr_screen.clip_left ) continue;
591 if ( y + Current_font->h < gr_screen.clip_top ) continue;
592 if ( x > gr_screen.clip_right ) continue;
593 if ( y > gr_screen.clip_bottom ) continue;
596 if ( x < gr_screen.clip_left ) xd = gr_screen.clip_left - x;
597 if ( y < gr_screen.clip_top ) yd = gr_screen.clip_top - y;
601 wc = width - xd; hc = Current_font->h - yd;
602 if ( xc + wc > gr_screen.clip_right ) wc = gr_screen.clip_right - xc;
603 if ( yc + hc > gr_screen.clip_bottom ) hc = gr_screen.clip_bottom - yc;
605 if ( wc < 1 ) continue;
606 if ( hc < 1 ) continue;
608 float u = i2fl(Current_font->bm_u[letter] + xd);
609 float v = i2fl(Current_font->bm_v[letter] + yd);
611 x1 = i2fl(xc + gr_screen.offset_x);
612 y1 = i2fl(yc + gr_screen.offset_y);
616 u0 = u_scale * (u * fbw);
617 v0 = v_scale * (v * fbh);
619 u1 = u_scale * ((u+i2fl(wc)) * fbw);
620 v1 = v_scale * ((v+i2fl(hc)) * fbh);
622 // maybe go ahead and draw
623 if (rb_offset == alocsize) {
624 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
628 render_buffer[rb_offset].x = x1;
629 render_buffer[rb_offset].y = y1;
630 render_buffer[rb_offset].u = u0;
631 render_buffer[rb_offset].v = v0;
634 render_buffer[rb_offset].x = x1;
635 render_buffer[rb_offset].y = y2;
636 render_buffer[rb_offset].u = u0;
637 render_buffer[rb_offset].v = v1;
640 render_buffer[rb_offset].x = x2;
641 render_buffer[rb_offset].y = y1;
642 render_buffer[rb_offset].u = u1;
643 render_buffer[rb_offset].v = v0;
646 render_buffer[rb_offset].x = x2;
647 render_buffer[rb_offset].y = y2;
648 render_buffer[rb_offset].u = u1;
649 render_buffer[rb_offset].v = v1;
654 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
657 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
658 glDisableClientState(GL_VERTEX_ARRAY);
661 void gr_opengl1_line(int x1,int y1,int x2,int y2)
663 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
665 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
666 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),void());
671 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
672 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
673 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
674 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
676 opengl_alloc_render_buffer(2);
678 if ( x1 == x2 && y1 == y2 ) {
679 render_buffer[0].x = sx1;
680 render_buffer[0].y = sy1;
681 render_buffer[0].z = -0.99f;
683 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
684 gr_screen.current_color.blue, gr_screen.current_color.alpha);
686 glEnableClientState(GL_VERTEX_ARRAY);
687 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
689 glDrawArrays(GL_POINTS, 0, 1);
691 glDisableClientState(GL_VERTEX_ARRAY);
702 } else if ( y1 == y2 ) {
710 render_buffer[0].x = sx2;
711 render_buffer[0].y = sy2;
712 render_buffer[0].z = -0.99f;
714 render_buffer[1].x = sx1;
715 render_buffer[1].y = sy1;
716 render_buffer[1].z = -0.99f;
718 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
719 gr_screen.current_color.blue, gr_screen.current_color.alpha);
721 glEnableClientState(GL_VERTEX_ARRAY);
722 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
724 glDrawArrays(GL_LINES, 0, 2);
726 glDisableClientState(GL_VERTEX_ARRAY);
729 void gr_opengl1_aaline(vertex *v1, vertex *v2)
731 gr_opengl1_line( fl2i(v1->sx), fl2i(v1->sy), fl2i(v2->sx), fl2i(v2->sy) );
734 void gr_opengl1_gradient(int x1,int y1,int x2,int y2)
738 if ( !gr_screen.current_color.is_alphacolor ) {
739 gr_line( x1, y1, x2, y2 );
743 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
744 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),swapped=1);
746 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
748 int aa = swapped ? 0 : gr_screen.current_color.alpha;
749 int ba = swapped ? gr_screen.current_color.alpha : 0;
754 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
755 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
756 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
757 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
765 } else if ( y1 == y2 ) {
773 opengl_alloc_render_buffer(2);
775 render_buffer[0].r = gr_screen.current_color.red;
776 render_buffer[0].g = gr_screen.current_color.green;
777 render_buffer[0].b = gr_screen.current_color.blue;
778 render_buffer[0].a = (ubyte)ba;
779 render_buffer[0].x = sx2;
780 render_buffer[0].y = sy2;
781 render_buffer[0].z = -0.99f;
783 render_buffer[1].r = gr_screen.current_color.red;
784 render_buffer[1].g = gr_screen.current_color.green;
785 render_buffer[1].b = gr_screen.current_color.blue;
786 render_buffer[1].a = (ubyte)aa;
787 render_buffer[1].x = sx1;
788 render_buffer[1].y = sy1;
789 render_buffer[1].z = -0.99f;
791 glEnableClientState(GL_COLOR_ARRAY);
792 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
794 glEnableClientState(GL_VERTEX_ARRAY);
795 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
797 glDrawArrays(GL_LINES, 0, 2);
799 glDisableClientState(GL_COLOR_ARRAY);
800 glDisableClientState(GL_VERTEX_ARRAY);
803 void gr_opengl1_circle( int xc, int yc, int d )
813 if ( (xc+r) < gr_screen.clip_left ) return;
814 if ( (xc-r) > gr_screen.clip_right ) return;
815 if ( (yc+r) < gr_screen.clip_top ) return;
816 if ( (yc-r) > gr_screen.clip_bottom ) return;
819 // Draw the first octant
820 gr_opengl1_line( xc-y, yc-x, xc+y, yc-x );
821 gr_opengl1_line( xc-y, yc+x, xc+y, yc+x );
826 // Draw the second octant
827 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
828 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
836 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
837 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
842 void gr_opengl1_pixel(int x, int y)
849 void gr_opengl1_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct)
851 gr_set_bitmap(bmap1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - pct );
854 gr_set_bitmap(bmap2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, pct );
858 void gr_opengl1_flash(int r, int g, int b)
865 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE );
867 float x1, x2, y1, y2;
868 x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x);
869 y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y);
870 x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x);
871 y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y);
873 glColor4ub((GLubyte)r, (GLubyte)g, (GLubyte)b, 255);
875 opengl_alloc_render_buffer(4);
877 render_buffer[0].x = x1;
878 render_buffer[0].y = y1;
879 render_buffer[0].z = -0.99f;
881 render_buffer[1].x = x1;
882 render_buffer[1].y = y2;
883 render_buffer[1].z = -0.99f;
885 render_buffer[2].x = x2;
886 render_buffer[2].y = y1;
887 render_buffer[2].z = -0.99f;
889 render_buffer[3].x = x2;
890 render_buffer[3].y = y2;
891 render_buffer[3].z = -0.99f;
893 glEnableClientState(GL_VERTEX_ARRAY);
894 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
896 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
898 glDisableClientState(GL_VERTEX_ARRAY);
902 void gr_opengl1_tmapper( int nverts, vertex **verts, uint flags )
904 opengl1_tmapper_internal( nverts, verts, flags, 0 );
907 #define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0))
909 void gr_opengl1_scaler(vertex *va, vertex *vb )
911 float x0, y0, x1, y1;
912 float u0, v0, u1, v1;
913 float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
914 float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
915 float xmin, xmax, ymin, ymax;
916 int dx0, dy0, dx1, dy1;
918 //============= CLIP IT =====================
920 x0 = va->sx; y0 = va->sy;
921 x1 = vb->sx; y1 = vb->sy;
923 xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top);
924 xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom);
926 u0 = va->u; v0 = va->v;
927 u1 = vb->u; v1 = vb->v;
929 // Check for obviously offscreen bitmaps...
930 if ( (y1<=y0) || (x1<=x0) ) return;
931 if ( (x1<xmin ) || (x0>xmax) ) return;
932 if ( (y1<ymin ) || (y0>ymax) ) return;
934 clipped_u0 = u0; clipped_v0 = v0;
935 clipped_u1 = u1; clipped_v1 = v1;
937 clipped_x0 = x0; clipped_y0 = y0;
938 clipped_x1 = x1; clipped_y1 = y1;
940 // Clip the left, moving u0 right as necessary
942 clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1);
946 // Clip the right, moving u1 left as necessary
948 clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1);
952 // Clip the top, moving v0 down as necessary
954 clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1);
958 // Clip the bottom, moving v1 up as necessary
960 clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1);
964 dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1);
965 dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1);
967 if (dx1<=dx0) return;
968 if (dy1<=dy0) return;
970 //============= DRAW IT =====================
976 v[0].sx = clipped_x0;
977 v[0].sy = clipped_y0;
984 v[1].sx = clipped_x1;
985 v[1].sy = clipped_y0;
992 v[2].sx = clipped_x1;
993 v[2].sy = clipped_y1;
1000 v[3].sx = clipped_x0;
1001 v[3].sy = clipped_y1;
1004 v[3].u = clipped_u0;
1005 v[3].v = clipped_v1;
1007 opengl1_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 );