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)
29 int saved_zbuf = gr_zbuffer_get();
31 // no zbuffering, no culling
32 gr_zbuffer_set(GR_ZBUFF_NONE);
33 gr_opengl_set_cull(0);
35 opengl1_set_state(TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE);
37 opengl_alloc_render_buffer(4);
39 render_buffer[0].x = i2fl(x);
40 render_buffer[0].y = i2fl(y);
42 render_buffer[1].x = i2fl(x);
43 render_buffer[1].y = i2fl(y + h);
45 render_buffer[2].x = i2fl(x + w);
46 render_buffer[2].y = i2fl(y);
48 render_buffer[3].x = i2fl(x + w);
49 render_buffer[3].y = i2fl(y + h);
51 r = Gr_gamma_lookup[r];
52 g = Gr_gamma_lookup[g];
53 b = Gr_gamma_lookup[b];
55 glColor4ub((ubyte)r, (ubyte)g, (ubyte)b, (ubyte)a);
57 glEnableClientState(GL_VERTEX_ARRAY);
59 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
61 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
63 glDisableClientState(GL_VERTEX_ARRAY);
65 // restore zbuffer and culling
66 gr_zbuffer_set(saved_zbuf);
67 gr_opengl_set_cull(1);
70 static void opengl1_aabitmap_ex_internal(int x,int y,int w,int h,int sx,int sy)
72 if ( (w < 1) || (h < 1) ) {
76 if ( !gr_screen.current_color.is_alphacolor ) {
80 float u_scale, v_scale;
82 if ( !opengl1_tcache_set(gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP,
83 &u_scale, &v_scale, 0, -1, -1, 0) )
85 // Couldn't set texture
86 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
90 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
96 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
98 u0 = u_scale*i2fl(sx)/i2fl(bw);
99 v0 = v_scale*i2fl(sy)/i2fl(bh);
101 u1 = u_scale*i2fl(sx+w)/i2fl(bw);
102 v1 = v_scale*i2fl(sy+h)/i2fl(bh);
104 x1 = i2fl(x+gr_screen.offset_x);
105 y1 = i2fl(y+gr_screen.offset_y);
106 x2 = i2fl(x+w+gr_screen.offset_x);
107 y2 = i2fl(y+h+gr_screen.offset_y);
109 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
110 gr_screen.current_color.blue,gr_screen.current_color.alpha);
112 opengl_alloc_render_buffer(4);
114 render_buffer[0].x = x1;
115 render_buffer[0].y = y1;
116 render_buffer[0].u = u0;
117 render_buffer[0].v = v0;
119 render_buffer[1].x = x1;
120 render_buffer[1].y = y2;
121 render_buffer[1].u = u0;
122 render_buffer[1].v = v1;
124 render_buffer[2].x = x2;
125 render_buffer[2].y = y1;
126 render_buffer[2].u = u1;
127 render_buffer[2].v = v0;
129 render_buffer[3].x = x2;
130 render_buffer[3].y = y2;
131 render_buffer[3].u = u1;
132 render_buffer[3].v = v1;
134 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
135 glEnableClientState(GL_VERTEX_ARRAY);
137 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
138 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
140 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
142 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
143 glDisableClientState(GL_VERTEX_ARRAY);
146 static void opengl1_tmapper_internal( int nv, vertex ** verts, uint flags, int is_scaler )
149 float u_scale = 1.0f, v_scale = 1.0f;
151 gr_texture_source texture_source = TEXTURE_SOURCE_NONE;
152 gr_alpha_blend alpha_blend = ALPHA_BLEND_ALPHA_BLEND_ALPHA;
153 gr_zbuffer_type zbuffer_type = ZBUFFER_TYPE_NONE;
156 if ( is_scaler || (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) ) {
157 zbuffer_type = ZBUFFER_TYPE_READ;
159 zbuffer_type = ZBUFFER_TYPE_FULL;
163 int tmap_type = TCACHE_TYPE_NORMAL;
165 ubyte r = 255, g = 255, b = 255, a = 255;
167 if ( !(flags & TMAP_FLAG_TEXTURED) ) {
168 r = gr_screen.current_color.red;
169 g = gr_screen.current_color.green;
170 b = gr_screen.current_color.blue;
173 if (gr_screen.current_alphablend_mode == GR_ALPHABLEND_FILTER) {
174 alpha_blend = ALPHA_BLEND_ALPHA_ADDITIVE;
176 // Blend with screen pixel using src*alpha+dst
178 if (gr_screen.current_alpha < 1.0f) {
179 r = ubyte((r * gr_screen.current_alpha) + 0.5f);
180 g = ubyte((g * gr_screen.current_alpha) + 0.5f);
181 b = ubyte((b * gr_screen.current_alpha) + 0.5f);
185 if (flags & TMAP_FLAG_BITMAP_SECTION) {
186 SDL_assert( !(flags & TMAP_FLAG_BITMAP_INTERFACE) );
187 tmap_type = TCACHE_TYPE_BITMAP_SECTION;
188 } else if (flags & TMAP_FLAG_BITMAP_INTERFACE) {
189 SDL_assert( !(flags & TMAP_FLAG_BITMAP_SECTION) );
190 tmap_type = TCACHE_TYPE_BITMAP_INTERFACE;
193 if (flags & TMAP_FLAG_TEXTURED) {
194 if ( !opengl1_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale,
195 &v_scale, 0, gr_screen.current_bitmap_sx, gr_screen.current_bitmap_sy, 0) )
197 mprintf(( "Not rendering a texture because it didn't fit in VRAM!\n" ));
201 // use non-filtered textures for bitmap sections and UI graphics
203 case TCACHE_TYPE_BITMAP_INTERFACE:
204 case TCACHE_TYPE_BITMAP_SECTION:
205 texture_source = TEXTURE_SOURCE_NO_FILTERING;
209 texture_source = TEXTURE_SOURCE_DECAL;
215 opengl1_set_state( texture_source, alpha_blend, zbuffer_type );
217 float ox = gr_screen.offset_x * 16.0f;
218 float oy = gr_screen.offset_y * 16.0f;
220 if (flags & TMAP_FLAG_PIXEL_FOG) {
227 for (i = nv-1; i >= 0; i--) {
228 vertex * va = verts[i];
230 sx = (va->sx * 16.0f + ox) / 16.0f;
231 sy = (va->sy * 16.0f + oy) / 16.0f;
233 neb2_get_pixel((int)sx, (int)sy, &fr, &fg, &fb);
244 gr_opengl1_fog_set(GR_FOGMODE_FOG, ra, ga, ba, -1.0f, -1.0f);
247 opengl_alloc_render_buffer(nv);
251 float sx, sy, sz = 0.99f, rhw = 1.0f;
253 bool bZval = (Gr_zbuffering || (flags & TMAP_FLAG_NEBULA));
254 bool bCorrect = ((flags & TMAP_FLAG_CORRECT) == TMAP_FLAG_CORRECT);
255 bool bAlpha = ((flags & TMAP_FLAG_ALPHA) == TMAP_FLAG_ALPHA);
256 bool bNebula = ((flags & TMAP_FLAG_NEBULA) == TMAP_FLAG_NEBULA);
257 bool bRamp = ((flags & TMAP_FLAG_RAMP) && (flags & TMAP_FLAG_GOURAUD));
258 bool bRGB = ((flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD));
259 bool bTextured = ((flags & TMAP_FLAG_TEXTURED) == TMAP_FLAG_TEXTURED);
261 for (i = nv-1; i >= 0; i--) {
262 vertex *va = verts[i];
265 sz = 1.0f - 1.0f / (1.0f + va->z / (32768.0f / 256.0f));
281 // Make 0.75 be 256.0f
282 r = (ubyte)Gr_gamma_lookup[va->r];
283 g = (ubyte)Gr_gamma_lookup[va->g];
284 b = (ubyte)Gr_gamma_lookup[va->b];
285 } else if (bNebula) {
286 int pal = (va->b*(NEBULA_COLORS-1))/255;
287 r = gr_palette[pal*3+0];
288 g = gr_palette[pal*3+1];
289 b = gr_palette[pal*3+2];
291 r = g = b = (ubyte)Gr_gamma_lookup[va->b];
294 render_buffer[rb_offset].r = r;
295 render_buffer[rb_offset].g = g;
296 render_buffer[rb_offset].b = b;
297 render_buffer[rb_offset].a = a;
299 sx = (va->sx * 16.0f + ox) / 16.0f;
300 sy = (va->sy * 16.0f + oy) / 16.0f;
303 render_buffer[rb_offset].u = va->u * u_scale;
304 render_buffer[rb_offset].v = va->v * v_scale;
307 render_buffer[rb_offset].x = sx * rhw;
308 render_buffer[rb_offset].y = sy * rhw;
309 render_buffer[rb_offset].z = -sz * rhw;
310 render_buffer[rb_offset].w = rhw;
315 if (flags & TMAP_FLAG_TEXTURED) {
316 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
317 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
320 glEnableClientState(GL_COLOR_ARRAY);
321 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
323 glEnableClientState(GL_VERTEX_ARRAY);
324 glVertexPointer(4, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
326 glDrawArrays(GL_TRIANGLE_FAN, 0, rb_offset);
328 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
329 glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
330 glDisableClientState(GL_COLOR_ARRAY);
331 glDisableClientState(GL_VERTEX_ARRAY);
334 void gr_opengl1_rect(int x,int y,int w,int h)
336 opengl1_rect_internal(x, y, w, h, gr_screen.current_color.red,
337 gr_screen.current_color.green, gr_screen.current_color.blue,
338 gr_screen.current_color.alpha);
341 void gr_opengl1_shade(int x,int y,int w,int h)
348 r = fl2i(gr_screen.current_shader.r*255.0f*shade1);
350 g = fl2i(gr_screen.current_shader.g*255.0f*shade1);
352 b = fl2i(gr_screen.current_shader.b*255.0f*shade1);
354 a = fl2i(gr_screen.current_shader.c*255.0f*shade2);
357 opengl1_rect_internal(x, y, w, h, r, g, b, a);
360 void gr_opengl1_aabitmap_ex(int x,int y,int w,int h,int sx,int sy)
362 if ( (x > gr_screen.clip_right ) || ((x+w-1) < gr_screen.clip_left) )
365 if ( (y > gr_screen.clip_bottom ) || ((y+h-1) < gr_screen.clip_top) )
368 opengl1_aabitmap_ex_internal(x, y, w, h, sx, sy);
371 void gr_opengl1_aabitmap(int x, int y)
375 bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
377 gr_opengl1_aabitmap_ex(x, y, w, h, 0, 0);
380 void gr_opengl1_string( int sx, int sy, const char *s )
382 int width, spacing, letter;
385 float u_scale, v_scale;
386 float u0, u1, v0, v1;
387 float x1, x2, y1, y2;
391 if ( !Current_font ) {
395 gr_set_bitmap(Current_font->bitmap_id, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
397 if ( !opengl1_tcache_set( gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale, 0, -1, -1, 0 ) ) {
398 // Couldn't set texture
399 mprintf(( "WARNING: Error setting aabitmap texture!\n" ));
403 bm_get_info( gr_screen.current_bitmap, &bw, &bh );
405 fbw = 1.0f / i2fl(bw);
406 fbh = 1.0f / i2fl(bh);
408 opengl1_set_state( TEXTURE_SOURCE_NO_FILTERING, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
410 // don't want to create a super huge buffer size (i.e. credits text)
411 const int alocsize = 320; // 80 characters max per render call
412 opengl_alloc_render_buffer(alocsize);
414 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
415 gr_screen.current_color.blue, gr_screen.current_color.alpha);
417 glEnableClientState(GL_VERTEX_ARRAY);
418 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
420 glVertexPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
421 glTexCoordPointer(2, GL_FLOAT, sizeof(rb_t), &render_buffer[0].u);
425 if (sx==0x8000) { //centered
426 x = get_centered_x(s);
439 y += Current_font->h;
440 if (sx==0x8000) { //centered
441 x = get_centered_x(s);
448 letter = get_char_width(s[0],s[1],&width,&spacing);
451 //not in font, draw as space
459 // Check if this character is totally clipped
460 if ( x + width < gr_screen.clip_left ) continue;
461 if ( y + Current_font->h < gr_screen.clip_top ) continue;
462 if ( x > gr_screen.clip_right ) continue;
463 if ( y > gr_screen.clip_bottom ) continue;
466 if ( x < gr_screen.clip_left ) xd = gr_screen.clip_left - x;
467 if ( y < gr_screen.clip_top ) yd = gr_screen.clip_top - y;
471 wc = width - xd; hc = Current_font->h - yd;
472 if ( xc + wc > gr_screen.clip_right ) wc = gr_screen.clip_right - xc;
473 if ( yc + hc > gr_screen.clip_bottom ) hc = gr_screen.clip_bottom - yc;
475 if ( wc < 1 ) continue;
476 if ( hc < 1 ) continue;
478 float u = i2fl(Current_font->bm_u[letter] + xd);
479 float v = i2fl(Current_font->bm_v[letter] + yd);
481 x1 = i2fl(xc + gr_screen.offset_x);
482 y1 = i2fl(yc + gr_screen.offset_y);
486 u0 = u_scale * (u * fbw);
487 v0 = v_scale * (v * fbh);
489 u1 = u_scale * ((u+i2fl(wc)) * fbw);
490 v1 = v_scale * ((v+i2fl(hc)) * fbh);
492 // maybe go ahead and draw
493 if (rb_offset == alocsize) {
494 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
498 render_buffer[rb_offset].x = x1;
499 render_buffer[rb_offset].y = y1;
500 render_buffer[rb_offset].u = u0;
501 render_buffer[rb_offset].v = v0;
504 render_buffer[rb_offset].x = x1;
505 render_buffer[rb_offset].y = y2;
506 render_buffer[rb_offset].u = u0;
507 render_buffer[rb_offset].v = v1;
510 render_buffer[rb_offset].x = x2;
511 render_buffer[rb_offset].y = y1;
512 render_buffer[rb_offset].u = u1;
513 render_buffer[rb_offset].v = v0;
516 render_buffer[rb_offset].x = x2;
517 render_buffer[rb_offset].y = y2;
518 render_buffer[rb_offset].u = u1;
519 render_buffer[rb_offset].v = v1;
524 glDrawArrays(GL_TRIANGLE_STRIP, 0, rb_offset);
527 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
528 glDisableClientState(GL_VERTEX_ARRAY);
531 void gr_opengl1_line(int x1,int y1,int x2,int y2)
533 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
535 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
536 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),void());
541 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
542 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
543 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
544 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
546 opengl_alloc_render_buffer(2);
548 if ( x1 == x2 && y1 == y2 ) {
549 render_buffer[0].x = sx1;
550 render_buffer[0].y = sy1;
551 render_buffer[0].z = -0.99f;
553 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
554 gr_screen.current_color.blue, gr_screen.current_color.alpha);
556 glEnableClientState(GL_VERTEX_ARRAY);
557 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
559 glDrawArrays(GL_POINTS, 0, 1);
561 glDisableClientState(GL_VERTEX_ARRAY);
572 } else if ( y1 == y2 ) {
580 render_buffer[0].x = sx2;
581 render_buffer[0].y = sy2;
582 render_buffer[0].z = -0.99f;
584 render_buffer[1].x = sx1;
585 render_buffer[1].y = sy1;
586 render_buffer[1].z = -0.99f;
588 glColor4ub(gr_screen.current_color.red, gr_screen.current_color.green,
589 gr_screen.current_color.blue, gr_screen.current_color.alpha);
591 glEnableClientState(GL_VERTEX_ARRAY);
592 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
594 glDrawArrays(GL_LINES, 0, 2);
596 glDisableClientState(GL_VERTEX_ARRAY);
599 void gr_opengl1_aaline(vertex *v1, vertex *v2)
601 gr_opengl1_line( fl2i(v1->sx), fl2i(v1->sy), fl2i(v2->sx), fl2i(v2->sy) );
604 void gr_opengl1_gradient(int x1,int y1,int x2,int y2)
608 if ( !gr_screen.current_color.is_alphacolor ) {
609 gr_line( x1, y1, x2, y2 );
613 INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,
614 gr_screen.clip_right,gr_screen.clip_bottom,return,void(),swapped=1);
616 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
618 int aa = swapped ? 0 : gr_screen.current_color.alpha;
619 int ba = swapped ? gr_screen.current_color.alpha : 0;
624 sx1 = i2fl(x1 + gr_screen.offset_x)+0.5f;
625 sy1 = i2fl(y1 + gr_screen.offset_y)+0.5f;
626 sx2 = i2fl(x2 + gr_screen.offset_x)+0.5f;
627 sy2 = i2fl(y2 + gr_screen.offset_y)+0.5f;
635 } else if ( y1 == y2 ) {
643 opengl_alloc_render_buffer(2);
645 render_buffer[0].r = gr_screen.current_color.red;
646 render_buffer[0].g = gr_screen.current_color.green;
647 render_buffer[0].b = gr_screen.current_color.blue;
648 render_buffer[0].a = (ubyte)ba;
649 render_buffer[0].x = sx2;
650 render_buffer[0].y = sy2;
651 render_buffer[0].z = -0.99f;
653 render_buffer[1].r = gr_screen.current_color.red;
654 render_buffer[1].g = gr_screen.current_color.green;
655 render_buffer[1].b = gr_screen.current_color.blue;
656 render_buffer[1].a = (ubyte)aa;
657 render_buffer[1].x = sx1;
658 render_buffer[1].y = sy1;
659 render_buffer[1].z = -0.99f;
661 glEnableClientState(GL_COLOR_ARRAY);
662 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(rb_t), &render_buffer[0].r);
664 glEnableClientState(GL_VERTEX_ARRAY);
665 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
667 glDrawArrays(GL_LINES, 0, 2);
669 glDisableClientState(GL_COLOR_ARRAY);
670 glDisableClientState(GL_VERTEX_ARRAY);
673 void gr_opengl1_circle( int xc, int yc, int d )
683 if ( (xc+r) < gr_screen.clip_left ) return;
684 if ( (xc-r) > gr_screen.clip_right ) return;
685 if ( (yc+r) < gr_screen.clip_top ) return;
686 if ( (yc-r) > gr_screen.clip_bottom ) return;
689 // Draw the first octant
690 gr_opengl1_line( xc-y, yc-x, xc+y, yc-x );
691 gr_opengl1_line( xc-y, yc+x, xc+y, yc+x );
696 // Draw the second octant
697 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
698 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
706 gr_opengl1_line( xc-x, yc-y, xc+x, yc-y );
707 gr_opengl1_line( xc-x, yc+y, xc+x, yc+y );
712 void gr_opengl1_pixel(int x, int y)
714 gr_opengl1_line(x, y, x, y);
719 void gr_opengl1_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct)
721 gr_set_bitmap(bmap1, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f - pct );
724 gr_set_bitmap(bmap2, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, pct );
728 void gr_opengl1_flash(int r, int g, int b)
735 opengl1_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_ADDITIVE, ZBUFFER_TYPE_NONE );
737 float x1, x2, y1, y2;
738 x1 = i2fl(gr_screen.clip_left+gr_screen.offset_x);
739 y1 = i2fl(gr_screen.clip_top+gr_screen.offset_y);
740 x2 = i2fl(gr_screen.clip_right+gr_screen.offset_x);
741 y2 = i2fl(gr_screen.clip_bottom+gr_screen.offset_y);
743 glColor4ub((GLubyte)r, (GLubyte)g, (GLubyte)b, 255);
745 opengl_alloc_render_buffer(4);
747 render_buffer[0].x = x1;
748 render_buffer[0].y = y1;
749 render_buffer[0].z = -0.99f;
751 render_buffer[1].x = x1;
752 render_buffer[1].y = y2;
753 render_buffer[1].z = -0.99f;
755 render_buffer[2].x = x2;
756 render_buffer[2].y = y1;
757 render_buffer[2].z = -0.99f;
759 render_buffer[3].x = x2;
760 render_buffer[3].y = y2;
761 render_buffer[3].z = -0.99f;
763 glEnableClientState(GL_VERTEX_ARRAY);
764 glVertexPointer(3, GL_FLOAT, sizeof(rb_t), &render_buffer[0].x);
766 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
768 glDisableClientState(GL_VERTEX_ARRAY);
772 void gr_opengl1_tmapper( int nverts, vertex **verts, uint flags )
774 opengl1_tmapper_internal( nverts, verts, flags, 0 );
777 #define FIND_SCALED_NUM(x,x0,x1,y0,y1) (((((x)-(x0))*((y1)-(y0)))/((x1)-(x0)))+(y0))
779 void gr_opengl1_scaler(vertex *va, vertex *vb )
781 float x0, y0, x1, y1;
782 float u0, v0, u1, v1;
783 float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
784 float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
785 float xmin, xmax, ymin, ymax;
786 int dx0, dy0, dx1, dy1;
788 //============= CLIP IT =====================
790 x0 = va->sx; y0 = va->sy;
791 x1 = vb->sx; y1 = vb->sy;
793 xmin = i2fl(gr_screen.clip_left); ymin = i2fl(gr_screen.clip_top);
794 xmax = i2fl(gr_screen.clip_right); ymax = i2fl(gr_screen.clip_bottom);
796 u0 = va->u; v0 = va->v;
797 u1 = vb->u; v1 = vb->v;
799 // Check for obviously offscreen bitmaps...
800 if ( (y1<=y0) || (x1<=x0) ) return;
801 if ( (x1<xmin ) || (x0>xmax) ) return;
802 if ( (y1<ymin ) || (y0>ymax) ) return;
804 clipped_u0 = u0; clipped_v0 = v0;
805 clipped_u1 = u1; clipped_v1 = v1;
807 clipped_x0 = x0; clipped_y0 = y0;
808 clipped_x1 = x1; clipped_y1 = y1;
810 // Clip the left, moving u0 right as necessary
812 clipped_u0 = FIND_SCALED_NUM(xmin,x0,x1,u0,u1);
816 // Clip the right, moving u1 left as necessary
818 clipped_u1 = FIND_SCALED_NUM(xmax,x0,x1,u0,u1);
822 // Clip the top, moving v0 down as necessary
824 clipped_v0 = FIND_SCALED_NUM(ymin,y0,y1,v0,v1);
828 // Clip the bottom, moving v1 up as necessary
830 clipped_v1 = FIND_SCALED_NUM(ymax,y0,y1,v0,v1);
834 dx0 = fl2i(clipped_x0); dx1 = fl2i(clipped_x1);
835 dy0 = fl2i(clipped_y0); dy1 = fl2i(clipped_y1);
837 if (dx1<=dx0) return;
838 if (dy1<=dy0) return;
840 //============= DRAW IT =====================
846 v[0].sx = clipped_x0;
847 v[0].sy = clipped_y0;
854 v[1].sx = clipped_x1;
855 v[1].sy = clipped_y0;
862 v[2].sx = clipped_x1;
863 v[2].sy = clipped_y1;
870 v[3].sx = clipped_x0;
871 v[3].sy = clipped_y1;
877 opengl1_tmapper_internal( 4, vl, TMAP_FLAG_TEXTURED, 1 );