FS2_Open
Open source remastering of the Freespace 2 engine
gropengldraw.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
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 the
6  * source.
7  *
8 */
9 
10 #include <algorithm>
11 #include "bmpman/bmpman.h"
12 #include "cmdline/cmdline.h"
13 #include "freespace2/freespace.h"
14 #include "globalincs/pstypes.h"
15 #include "globalincs/systemvars.h"
16 #include "graphics/grinternal.h"
17 #include "graphics/gropengl.h"
19 #include "graphics/gropengldraw.h"
21 #include "graphics/gropengllight.h"
25 #include "graphics/gropengltnl.h"
26 #include "graphics/line.h"
27 #include "lighting/lighting.h"
28 #include "math/floating.h"
29 #include "nebula/neb.h"
30 #include "osapi/osapi.h"
31 #include "palman/palman.h"
32 #include "render/3d.h"
33 
44 
48 
51 
52 bool Deferred_lighting = false;
53 
56 
59 
64 
69 
72 
73  enum type {
80  };
81 
83 
86 
87  // used only by vertex attributes
90 };
91 
92 static opengl_vertex_bind GL_array_binding_data[] =
93 {
108 };
109 
111 {
112  opengl_vertex_bind &bind_info = GL_array_binding_data[vert_component.format_type];
113 
114  switch ( bind_info.binding_type ) {
116  {
118  GL_state.Array.VertexPointer(bind_info.size, bind_info.data_type, vert_component.stride, vert_component.data_src);
119  break;
120  }
122  {
125  GL_state.Array.TexPointer(bind_info.size, bind_info.data_type, vert_component.stride, vert_component.data_src);
126  break;
127  }
129  {
132  GL_state.Array.TexPointer(bind_info.size, bind_info.data_type, vert_component.stride, vert_component.data_src);
133  break;
134  }
136  {
138  GL_state.Array.ColorPointer(bind_info.size, bind_info.data_type, vert_component.stride, vert_component.data_src);
140  break;
141  }
143  {
145  GL_state.Array.NormalPointer(bind_info.data_type, vert_component.stride, vert_component.data_src);
146  break;
147  }
149  {
150  // grabbing a vertex attribute is dependent on what current shader has been set. i hope no one calls opengl_bind_vertex_layout before opengl_set_current_shader
151  GLint index = opengl_shader_get_attribute(bind_info.attrib_name.c_str());
152 
153  if ( index >= 0 ) {
155  GL_state.Array.VertexAttribPointer(index, bind_info.size, bind_info.data_type, bind_info.normalized, vert_component.stride, vert_component.data_src);
156  }
157 
158  break;
159  }
160  }
161 }
162 
164 {
166 
167  uint num_vertex_bindings = layout.get_num_vertex_components();
168 
169  for ( uint i = 0; i < num_vertex_bindings; ++i ) {
171  }
172 
174 }
175 
176 void gr_opengl_pixel(int x, int y, int resize_mode)
177 {
178  gr_line(x, y, x, y, resize_mode);
179 }
180 
181 void opengl_aabitmap_ex_internal(int x, int y, int w, int h, int sx, int sy, int resize_mode, bool mirror)
182 {
183  if ( (w < 1) || (h < 1) ) {
184  return;
185  }
186 
188  return;
189  }
190 
191  float u_scale, v_scale;
192 
193  GL_CHECK_FOR_ERRORS("start of aabitmap_ex_internal()");
194 
198 
199  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale) ) {
200  mprintf(("WARNING: Error setting aabitmap texture (%i)!\n", gr_screen.current_bitmap));
201  return;
202  }
203 
204  float u0, u1, v0, v1;
205  float x1, x2, y1, y2;
206  int bw, bh, do_resize;
207 
208  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
209  do_resize = 1;
210  } else {
211  do_resize = 0;
212  }
213 
215 
216  u0 = u_scale * (i2fl(sx) / i2fl(bw));
217  v0 = v_scale * (i2fl(sy) / i2fl(bh));
218 
219  u1 = u_scale * (i2fl(sx+w) / i2fl(bw));
220  v1 = v_scale * (i2fl(sy+h) / i2fl(bh));
221 
222  x1 = i2fl(x + ((do_resize) ? gr_screen.offset_x_unscaled : gr_screen.offset_x));
223  y1 = i2fl(y + ((do_resize) ? gr_screen.offset_y_unscaled : gr_screen.offset_y));
224  x2 = x1 + i2fl(w);
225  y2 = y1 + i2fl(h);
226 
227  if (do_resize) {
228  gr_resize_screen_posf(&x1, &y1, NULL, NULL, resize_mode);
229  gr_resize_screen_posf(&x2, &y2, NULL, NULL, resize_mode);
230  }
231 
233 
234  if (mirror) {
235  float temp = u0;
236  u0 = u1;
237  u1 = temp;
238  }
239 
240  GLboolean cull_face = GL_state.CullFace(GL_FALSE);
241 
242  opengl_draw_textured_quad(x1,y1,u0,v0, x2,y2,u1,v1);
243 
244  GL_state.CullFace(cull_face);
245 
246  GL_CHECK_FOR_ERRORS("end of aabitmap_ex_internal()");
247 }
248 
249 void gr_opengl_aabitmap_ex(int x, int y, int w, int h, int sx, int sy, int resize_mode, bool mirror)
250 {
251  int reclip;
252 #ifndef NDEBUG
253  int count = 0;
254 #endif
255 
256  int dx1 = x;
257  int dx2 = x + w - 1;
258  int dy1 = y;
259  int dy2 = y + h - 1;
260 
261  int bw, bh, do_resize;
262 
264 
265  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
266  do_resize = 1;
267  } else {
268  do_resize = 0;
269  }
270 
271  int clip_left = ((do_resize) ? gr_screen.clip_left_unscaled : gr_screen.clip_left);
272  int clip_right = ((do_resize) ? gr_screen.clip_right_unscaled : gr_screen.clip_right);
273  int clip_top = ((do_resize) ? gr_screen.clip_top_unscaled : gr_screen.clip_top);
274  int clip_bottom = ((do_resize) ? gr_screen.clip_bottom_unscaled : gr_screen.clip_bottom);
275 
276  do {
277  reclip = 0;
278 
279 #ifndef NDEBUG
280  if (count > 1) {
281  Int3();
282  }
283 
284  count++;
285 #endif
286 
287  if ( (dx1 > clip_right) || (dx2 < clip_left) ) {
288  return;
289  }
290 
291  if ( (dy1 > clip_bottom) || (dy2 < clip_top) ) {
292  return;
293  }
294 
295  if (dx1 < clip_left) {
296  sx += clip_left - dx1;
297  dx1 = clip_left;
298  }
299 
300  if (dy1 < clip_top) {
301  sy += clip_top - dy1;
302  dy1 = clip_top;
303  }
304 
305  if (dx2 > clip_right) {
306  dx2 = clip_right;
307  }
308 
309  if (dy2 > clip_bottom) {
310  dy2 = clip_bottom;
311  }
312 
313 
314  if ( sx < 0 ) {
315  dx1 -= sx;
316  sx = 0;
317  reclip = 1;
318  }
319 
320  if ( sy < 0 ) {
321  dy1 -= sy;
322  sy = 0;
323  reclip = 1;
324  }
325 
326  w = dx2 - dx1 + 1;
327  h = dy2 - dy1 + 1;
328 
329  if ( sx + w > bw ) {
330  w = bw - sx;
331  dx2 = dx1 + w - 1;
332  }
333 
334  if ( sy + h > bh ) {
335  h = bh - sy;
336  dy2 = dy1 + h - 1;
337  }
338 
339  if ( (w < 1) || (h < 1) ) {
340  // clipped away!
341  return;
342  }
343  } while (reclip);
344 
345  // Make sure clipping algorithm works
346 #ifndef NDEBUG
347  Assert( w > 0 );
348  Assert( h > 0 );
349  Assert( w == (dx2-dx1+1) );
350  Assert( h == (dy2-dy1+1) );
351  Assert( sx >= 0 );
352  Assert( sy >= 0 );
353  Assert( sx+w <= bw );
354  Assert( sy+h <= bh );
355  Assert( dx2 >= dx1 );
356  Assert( dy2 >= dy1 );
357  Assert( (dx1 >= clip_left) && (dx1 <= clip_right) );
358  Assert( (dx2 >= clip_left) && (dx2 <= clip_right) );
359  Assert( (dy1 >= clip_top) && (dy1 <= clip_bottom) );
360  Assert( (dy2 >= clip_top) && (dy2 <= clip_bottom) );
361 #endif
362 
363  // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions.
364  opengl_aabitmap_ex_internal(dx1, dy1, (dx2 - dx1 + 1), (dy2 - dy1 + 1), sx, sy, resize_mode, mirror);
365 }
366 
367 void gr_opengl_aabitmap(int x, int y, int resize_mode, bool mirror)
368 {
369  int w, h, do_resize;
370 
372 
373  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
374  do_resize = 1;
375  } else {
376  do_resize = 0;
377  }
378 
379  int dx1 = x;
380  int dx2 = x + w - 1;
381  int dy1 = y;
382  int dy2 = y + h - 1;
383  int sx = 0, sy = 0;
384 
385  int clip_left = ((do_resize) ? gr_screen.clip_left_unscaled : gr_screen.clip_left);
386  int clip_right = ((do_resize) ? gr_screen.clip_right_unscaled : gr_screen.clip_right);
387  int clip_top = ((do_resize) ? gr_screen.clip_top_unscaled : gr_screen.clip_top);
388  int clip_bottom = ((do_resize) ? gr_screen.clip_bottom_unscaled : gr_screen.clip_bottom);
389 
390  if ( (dx1 > clip_right) || (dx2 < clip_left) ) {
391  return;
392  }
393 
394  if ( (dy1 > clip_bottom) || (dy2 < clip_top) ) {
395  return;
396  }
397 
398  if (dx1 < clip_left) {
399  sx = clip_left - dx1;
400  dx1 = clip_left;
401  }
402 
403  if (dy1 < clip_top) {
404  sy = clip_top - dy1;
405  dy1 = clip_top;
406  }
407 
408  if (dx2 > clip_right) {
409  dx2 = clip_right;
410  }
411 
412  if (dy2 > clip_bottom) {
413  dy2 = clip_bottom;
414  }
415 
416  if ( (sx < 0) || (sy < 0) ) {
417  return;
418  }
419 
420  if ( (sx >= w) || (sy >= h) ) {
421  return;
422  }
423 
424  // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
425  opengl_aabitmap_ex_internal(dx1, dy1, (dx2 - dx1 + 1), (dy2 - dy1 + 1), sx, sy, resize_mode, mirror);
426 }
427 
428 #define MAX_VERTS_PER_DRAW 120
429 struct v4 { GLfloat x,y,u,v; };
430 static v4 GL_string_render_buff[MAX_VERTS_PER_DRAW];
431 
432 void gr_opengl_string(float sx, float sy, const char *s, int resize_mode)
433 {
434  int width, spacing, letter;
435  float x, y;
436  bool do_resize;
437  float bw, bh;
438  float u0, u1, v0, v1;
439  float x1, x2, y1, y2;
440  float u_scale, v_scale;
441 
442  if ( !Current_font || (*s == 0) ) {
443  return;
444  }
445 
446  GL_CHECK_FOR_ERRORS("start of string()");
447 
449 
453 
454  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, TCACHE_TYPE_AABITMAP, &u_scale, &v_scale) ) {
455  return;
456  }
457 
458  int buffer_offset = 0;
459 
460  int ibw, ibh;
461 
462  bm_get_info(gr_screen.current_bitmap, &ibw, &ibh);
463 
464  bw = i2fl(ibw);
465  bh = i2fl(ibh);
466 
467  // set color!
470  } else {
472  }
473 
474 // if ( (gr_screen.custom_size && resize) || (gr_screen.rendering_to_texture != -1) ) {
475  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
476  do_resize = true;
477  } else {
478  do_resize = false;
479  }
480 
481  int clip_left = ((do_resize) ? gr_screen.clip_left_unscaled : gr_screen.clip_left);
482  int clip_right = ((do_resize) ? gr_screen.clip_right_unscaled : gr_screen.clip_right);
483  int clip_top = ((do_resize) ? gr_screen.clip_top_unscaled : gr_screen.clip_top);
484  int clip_bottom = ((do_resize) ? gr_screen.clip_bottom_unscaled : gr_screen.clip_bottom);
485 
486  x = sx;
487  y = sy;
488 
489  if (sx == (float)0x8000) {
490  // centered
491  x = (float)get_centered_x(s, !do_resize);
492  } else {
493  x = sx;
494  }
495 
496  spacing = 0;
497 
498  GLboolean cull_face = GL_state.CullFace(GL_FALSE);
499 
501 
502  vertex_layout vert_def;
503 
504  vert_def.add_vertex_component(vertex_format_data::POSITION2, sizeof(v4), &GL_string_render_buff[0].x);
505  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, sizeof(v4), &GL_string_render_buff[0].u);
506 
507  opengl_bind_vertex_layout(vert_def);
508 
509  // pick out letter coords, draw it, goto next letter and do the same
510  while (*s) {
511  x += spacing;
512 
513  while (*s == '\n') {
514  s++;
515  y += Current_font->h;
516 
517  if (sx == (float)0x8000) {
518  // centered
519  x = (float)get_centered_x(s, !do_resize);
520  } else {
521  x = sx;
522  }
523  }
524 
525  if (*s == 0) {
526  break;
527  }
528 
529  letter = get_char_width(s[0], s[1], &width, &spacing);
530  s++;
531 
532  // not in font, draw as space
533  if (letter < 0) {
534  continue;
535  }
536 
537  float xd, yd, xc, yc;
538  float wc, hc;
539 
540  // Check if this character is totally clipped
541  if ( (x + width) < clip_left ) {
542  continue;
543  }
544 
545  if ( (y + Current_font->h) < clip_top ) {
546  continue;
547  }
548 
549  if (x > clip_right) {
550  continue;
551  }
552 
553  if (y > clip_bottom) {
554  continue;
555  }
556 
557  xd = yd = 0;
558 
559  if (x < clip_left) {
560  xd = clip_left - x;
561  }
562 
563  if (y < clip_top) {
564  yd = clip_top - y;
565  }
566 
567  xc = x + xd;
568  yc = y + yd;
569 
570  wc = width - xd;
571  hc = Current_font->h - yd;
572 
573  if ( (xc + wc) > clip_right ) {
574  wc = clip_right - xc;
575  }
576 
577  if ( (yc + hc) > clip_bottom ) {
578  hc = clip_bottom - yc;
579  }
580 
581  if ( (wc < 1) || (hc < 1) ) {
582  continue;
583  }
584 
585  int u = Current_font->bm_u[letter];
586  int v = Current_font->bm_v[letter];
587 
588  x1 = xc + ((do_resize) ? gr_screen.offset_x_unscaled : gr_screen.offset_x);
589  y1 = yc + ((do_resize) ? gr_screen.offset_y_unscaled : gr_screen.offset_y);
590  x2 = x1 + wc;
591  y2 = y1 + hc;
592 
593  if (do_resize) {
594  gr_resize_screen_posf( &x1, &y1, NULL, NULL, resize_mode );
595  gr_resize_screen_posf( &x2, &y2, NULL, NULL, resize_mode );
596  }
597 
598  u0 = u_scale * (i2fl(u+xd) / bw);
599  v0 = v_scale * (i2fl(v+yd) / bh);
600 
601  u1 = u_scale * (i2fl((u+xd)+wc) / bw);
602  v1 = v_scale * (i2fl((v+yd)+hc) / bh);
603 
604  if ( buffer_offset == MAX_VERTS_PER_DRAW ) {
605  glDrawArrays(GL_TRIANGLES, 0, buffer_offset);
606  buffer_offset = 0;
607  }
608 
609  GL_string_render_buff[buffer_offset].x = (GLfloat)x1;
610  GL_string_render_buff[buffer_offset].y = (GLfloat)y1;
611  GL_string_render_buff[buffer_offset].u = u0;
612  GL_string_render_buff[buffer_offset].v = v0;
613  buffer_offset++;
614 
615  GL_string_render_buff[buffer_offset].x = (GLfloat)x1;
616  GL_string_render_buff[buffer_offset].y = (GLfloat)y2;
617  GL_string_render_buff[buffer_offset].u = u0;
618  GL_string_render_buff[buffer_offset].v = v1;
619  buffer_offset++;
620 
621  GL_string_render_buff[buffer_offset].x = (GLfloat)x2;
622  GL_string_render_buff[buffer_offset].y = (GLfloat)y1;
623  GL_string_render_buff[buffer_offset].u = u1;
624  GL_string_render_buff[buffer_offset].v = v0;
625  buffer_offset++;
626 
627  GL_string_render_buff[buffer_offset].x = (GLfloat)x1;
628  GL_string_render_buff[buffer_offset].y = (GLfloat)y2;
629  GL_string_render_buff[buffer_offset].u = u0;
630  GL_string_render_buff[buffer_offset].v = v1;
631  buffer_offset++;
632 
633  GL_string_render_buff[buffer_offset].x = (GLfloat)x2;
634  GL_string_render_buff[buffer_offset].y = (GLfloat)y1;
635  GL_string_render_buff[buffer_offset].u = u1;
636  GL_string_render_buff[buffer_offset].v = v0;
637  buffer_offset++;
638 
639  GL_string_render_buff[buffer_offset].x = (GLfloat)x2;
640  GL_string_render_buff[buffer_offset].y = (GLfloat)y2;
641  GL_string_render_buff[buffer_offset].u = u1;
642  GL_string_render_buff[buffer_offset].v = v1;
643  buffer_offset++;
644  }
645 
646  if ( buffer_offset ) {
647  glDrawArrays(GL_TRIANGLES, 0, buffer_offset);
648  }
649 
650  GL_state.CullFace(cull_face);
651 
652  GL_CHECK_FOR_ERRORS("end of string()");
653 }
654 
655 void gr_opengl_string(int sx, int sy, const char *s, int resize_mode)
656 {
657  gr_opengl_string(i2fl(sx), i2fl(sy), s, resize_mode);
658 }
659 
660 void gr_opengl_line(int x1,int y1,int x2,int y2, int resize_mode)
661 {
662  int do_resize;
663  float sx1, sy1;
664  float sx2, sy2;
665 
666  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
667  do_resize = 1;
668  } else {
669  do_resize = 0;
670  }
671 
672  int clip_left = ((do_resize) ? gr_screen.clip_left_unscaled : gr_screen.clip_left);
673  int clip_right = ((do_resize) ? gr_screen.clip_right_unscaled : gr_screen.clip_right);
674  int clip_top = ((do_resize) ? gr_screen.clip_top_unscaled : gr_screen.clip_top);
675  int clip_bottom = ((do_resize) ? gr_screen.clip_bottom_unscaled : gr_screen.clip_bottom);
676  int offset_x = ((do_resize) ? gr_screen.offset_x_unscaled : gr_screen.offset_x);
677  int offset_y = ((do_resize) ? gr_screen.offset_y_unscaled : gr_screen.offset_y);
678 
679 
680  INT_CLIPLINE(x1, y1, x2, y2, clip_left, clip_top, clip_right, clip_bottom, return, ;, ;);
681 
682  sx1 = i2fl(x1 + offset_x);
683  sy1 = i2fl(y1 + offset_y);
684  sx2 = i2fl(x2 + offset_x);
685  sy2 = i2fl(y2 + offset_y);
686 
687 
688  if (do_resize) {
689  gr_resize_screen_posf(&sx1, &sy1, NULL, NULL, resize_mode);
690  gr_resize_screen_posf(&sx2, &sy2, NULL, NULL, resize_mode);
691  }
692 
696 
697  if ( (x1 == x2) && (y1 == y2) ) {
699 
700  GLfloat vert[3]= {sx1, sy1, -0.99f};
702 
703  vertex_layout vert_def;
704 
706 
707  opengl_bind_vertex_layout(vert_def);
708 
709  glDrawArrays(GL_POINTS, 0, 1);
710 
711  GL_CHECK_FOR_ERRORS("end of opengl_line()");
712 
714 
715  return;
716  }
717 
718  if (x1 == x2) {
719  if (sy1 < sy2) {
720  sy2 += 0.5f;
721  } else {
722  sy1 += 0.5f;
723  }
724  } else if (y1 == y2) {
725  if (sx1 < sx2) {
726  sx2 += 0.5f;
727  } else {
728  sx1 += 0.5f;
729  }
730  }
731 
733 
734  GLfloat line[6] = {
735  sx2, sy2, -0.99f,
736  sx1, sy1, -0.99f
737  };
738 
740 
741  vertex_layout vert_def;
742 
744 
745  opengl_bind_vertex_layout(vert_def);
746 
747  glDrawArrays(GL_LINES, 0, 2);
748 
749  GL_CHECK_FOR_ERRORS("end of opengl_line()");
750 
752 }
753 
754 void gr_opengl_line_htl(const vec3d *start, const vec3d *end)
755 {
756  if (Cmdline_nohtl) {
757  return;
758  }
759 
762  GL_state.SetZbufferType(zbuffer_state);
763 
764 
768  } else {
771  }
772 
773  GLfloat line[6] = {
774  start->xyz.x, start->xyz.y, start->xyz.z,
775  end->xyz.x, end->xyz.y, end->xyz.z
776  };
777 
780 
781  vertex_layout vert_def;
782 
784 
785  opengl_bind_vertex_layout(vert_def);
786 
787  glDrawArrays(GL_LINES, 0, 2);
788 
789  GL_CHECK_FOR_ERRORS("end of opengl_line_htl()");
790 }
791 
793 {
794 // -- AA OpenGL lines. Looks good but they are kinda slow so this is disabled until an option is implemented - taylor
795 // gr_opengl_set_state( TEXTURE_SOURCE_NONE, ALPHA_BLEND_ALPHA_BLEND_ALPHA, ZBUFFER_TYPE_NONE );
796 // glEnable( GL_LINE_SMOOTH );
797 // glHint( GL_LINE_SMOOTH_HINT, GL_FASTEST );
798 // glLineWidth( 1.0 );
799 
800  float x1 = v1->screen.xyw.x;
801  float y1 = v1->screen.xyw.y;
802  float x2 = v2->screen.xyw.x;
803  float y2 = v2->screen.xyw.y;
804  float sx1, sy1;
805  float sx2, sy2;
806 
807 
808  FL_CLIPLINE(x1, y1, x2, y2, (float)gr_screen.clip_left, (float)gr_screen.clip_top, (float)gr_screen.clip_right, (float)gr_screen.clip_bottom, return, ;, ;);
809 
810  sx1 = x1 + (float)gr_screen.offset_x;
811  sy1 = y1 + (float)gr_screen.offset_y;
812  sx2 = x2 + (float)gr_screen.offset_x;
813  sy2 = y2 + (float)gr_screen.offset_y;
814 
818 
819  if ( (x1 == x2) && (y1 == y2) ) {
821 
823 
824  GLfloat vert[3]= {sx1, sy1, -0.99f};
825 
826  vertex_layout vert_def;
827 
829 
830  opengl_bind_vertex_layout(vert_def);
831 
832  glDrawArrays(GL_POINTS, 0, 1);
833 
834  GL_CHECK_FOR_ERRORS("end of opengl_aaline()");
835 
837 
838  return;
839  }
840 
841  if (x1 == x2) {
842  if (sy1 < sy2) {
843  sy2 += 0.5f;
844  } else {
845  sy1 += 0.5f;
846  }
847  } else if (y1 == y2) {
848  if (sx1 < sx2) {
849  sx2 += 0.5f;
850  } else {
851  sx1 += 0.5f;
852  }
853  }
854 
856 
858  GLfloat line[6] = {
859  sx2, sy2, -0.99f,
860  sx1, sy1, -0.99f
861  };
862 
863  vertex_layout vert_def;
864 
866 
867  opengl_bind_vertex_layout(vert_def);
868 
869  glDrawArrays(GL_LINES, 0, 2);
870 
871  GL_CHECK_FOR_ERRORS("end of opengl_aaline()");
872 
874 
875 // glDisable( GL_LINE_SMOOTH );
876 }
877 
878 void gr_opengl_gradient(int x1, int y1, int x2, int y2, int resize_mode)
879 {
880  int swapped = 0;
881 
883  gr_opengl_line(x1, y1, x2, y2, resize_mode);
884  return;
885  }
886 
887  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
888  gr_resize_screen_pos(&x1, &y1, NULL, NULL, resize_mode);
889  gr_resize_screen_pos(&x2, &y2, NULL, NULL, resize_mode);
890  }
891 
892  INT_CLIPLINE(x1, y1, x2, y2, gr_screen.clip_left, gr_screen.clip_top, gr_screen.clip_right, gr_screen.clip_bottom, return, ;, swapped = 1);
893 
897 
898  ubyte aa = swapped ? 0 : gr_screen.current_color.alpha;
899  ubyte ba = swapped ? gr_screen.current_color.alpha : 0;
900 
901  float sx1, sy1, sx2, sy2;
902 
903  sx1 = i2fl(x1 + gr_screen.offset_x);
904  sy1 = i2fl(y1 + gr_screen.offset_y);
905  sx2 = i2fl(x2 + gr_screen.offset_x);
906  sy2 = i2fl(y2 + gr_screen.offset_y);
907 
908  if (x1 == x2) {
909  if (sy1 < sy2) {
910  sy2 += 0.5f;
911  } else {
912  sy1 += 0.5f;
913  }
914  } else if (y1 == y2) {
915  if (sx1 < sx2) {
916  sx2 += 0.5f;
917  } else {
918  sx1 += 0.5f;
919  }
920  }
921 
922  GLubyte colour[8] = {
925  };
926 
927  GLfloat verts[4] = {
928  sx2, sy2,
929  sx1, sy1
930  };
931 
932  vertex_layout vert_def;
933 
936 
937  opengl_bind_vertex_layout(vert_def);
938 
939  glDrawArrays(GL_LINES, 0, 2);
940 }
941 
942 void gr_opengl_circle(int xc, int yc, int d, int resize_mode)
943 {
944  gr_opengl_arc(xc, yc, d / 2.0f, 0.0f, 360.0f, true, resize_mode);
945 }
946 
947 void gr_opengl_unfilled_circle(int xc, int yc, int d, int resize_mode)
948 {
949  int r = d / 2;
950  int segments = 4 + (int)(r); // seems like a good approximation
951  float theta = 2 * PI / float(segments - 1);
952  float c = cosf(theta);
953  float s = sinf(theta);
954  float t;
955 
956  float x1 = 1.0f;
957  float y1 = 0.0f;
958  float x2 = x1;
959  float y2 = y1;
960 
961  float linewidth;
962  glGetFloatv(GL_LINE_WIDTH, &linewidth);
963 
964  float halflinewidth = linewidth / 2.0f;
965  float inner_rad = r - halflinewidth;
966  float outer_rad = r + halflinewidth;
967 
968  int do_resize = 0;
969 
970  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
971  gr_resize_screen_pos(&xc, &yc, NULL, NULL, resize_mode);
972  do_resize = 1;
973  }
974 
975  // Big clip
976  if ( (xc+outer_rad) < gr_screen.clip_left ) {
977  return;
978  }
979 
980  if ( (xc-outer_rad) > gr_screen.clip_right ) {
981  return;
982  }
983 
984  if ( (yc+outer_rad) < gr_screen.clip_top ) {
985  return;
986  }
987 
988  if ( (yc-outer_rad) > gr_screen.clip_bottom ) {
989  return;
990  }
991 
992  int offset_x = ((do_resize) ? gr_screen.offset_x_unscaled : gr_screen.offset_x);
993  int offset_y = ((do_resize) ? gr_screen.offset_y_unscaled : gr_screen.offset_y);
994 
998 
999  GLfloat *circle = new GLfloat[segments * 4];
1000 
1001  for (int i=0; i < segments * 4; i+=4) {
1002  circle[i] = i2fl(xc + (x2 * outer_rad) + offset_x);
1003  circle[i+1] = i2fl(yc + (y2 * outer_rad) + offset_y);
1004 
1005  circle[i+2] = i2fl(xc + (x2 * inner_rad) + offset_x);
1006  circle[i+3] = i2fl(yc + (y2 * inner_rad) + offset_y);
1007 
1008  t = x2;
1009  x2 = c * x1 - s * y1;
1010  y2 = s * t + c * y1;
1011 
1012  x1 = x2;
1013  y1 = y2;
1014  }
1015 
1017 
1019 
1020  vertex_layout vert_def;
1021 
1023 
1024  opengl_bind_vertex_layout(vert_def);
1025 
1026  glDrawArrays(GL_QUAD_STRIP, 0, segments * 2);
1027 
1028  GL_CHECK_FOR_ERRORS("end of opengl_unfilled_circle()");
1029 
1031 
1032  delete [] circle;
1033 }
1034 
1035 void gr_opengl_arc(int xc, int yc, float r, float angle_start, float angle_end, bool fill, int resize_mode)
1036 {
1037  // Ensure that angle_start < angle_end
1038  if (angle_end < angle_start) {
1039  float temp = angle_start;
1040  angle_start = angle_end;
1041  angle_end = temp;
1042  }
1043 
1044  float arc_length_ratio;
1045  arc_length_ratio = MIN(angle_end - angle_start, 360.0f) / 360.0f;
1046 
1047  int segments = 4 + (int)(r * arc_length_ratio); // seems like a good approximation
1048  float theta = 2 * PI / float(segments - 1) * arc_length_ratio;
1049  float c = cosf(theta);
1050  float s = sinf(theta);
1051  float t;
1052 
1053  float x1 = cosf(fl_radians(angle_start));
1054  float y1 = sinf(fl_radians(angle_start));
1055  float x2 = x1;
1056  float y2 = y1;
1057 
1058  float halflinewidth = 0.0f;
1059  float inner_rad = 0.0f; // only used if fill==false
1060  float outer_rad = r;
1061 
1062  if (!fill) {
1063  float linewidth;
1064  glGetFloatv(GL_LINE_WIDTH, &linewidth);
1065 
1066  halflinewidth = linewidth / 2.0f;
1067  inner_rad = r - halflinewidth;
1068  outer_rad = r + halflinewidth;
1069  }
1070 
1071  int do_resize = 0;
1072 
1073  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
1074  gr_resize_screen_pos(&xc, &yc, NULL, NULL, resize_mode);
1075  do_resize = 1;
1076  }
1077 
1078  // Big clip
1079  if ( (xc+outer_rad) < gr_screen.clip_left ) {
1080  return;
1081  }
1082 
1083  if ( (xc-outer_rad) > gr_screen.clip_right ) {
1084  return;
1085  }
1086 
1087  if ( (yc+outer_rad) < gr_screen.clip_top ) {
1088  return;
1089  }
1090 
1091  if ( (yc-outer_rad) > gr_screen.clip_bottom ) {
1092  return;
1093  }
1094 
1095  int offset_x = ((do_resize) ? gr_screen.offset_x_unscaled : gr_screen.offset_x);
1096  int offset_y = ((do_resize) ? gr_screen.offset_y_unscaled : gr_screen.offset_y);
1097 
1101 
1102  GLfloat *arc;
1103 
1106 
1107  if (fill) {
1108  arc = new GLfloat[segments * 2 + 2];
1109 
1110  arc[0] = i2fl(xc);
1111  arc[1] = i2fl(yc);
1112 
1113  for (int i=2; i < segments * 2 + 2; i+=2) {
1114  arc[i] = i2fl(xc + (x2 * outer_rad) + offset_x);
1115  arc[i+1] = i2fl(yc + (y2 * outer_rad) + offset_y);
1116 
1117  t = x2;
1118  x2 = c * x1 - s * y1;
1119  y2 = s * t + c * y1;
1120 
1121  x1 = x2;
1122  y1 = y2;
1123  }
1124 
1125  vertex_layout vert_def;
1127  opengl_bind_vertex_layout(vert_def);
1128 
1129  glDrawArrays(GL_TRIANGLE_FAN, 0, segments + 1);
1130  } else {
1131  arc = new GLfloat[segments * 4];
1132 
1133  for (int i=0; i < segments * 4; i+=4) {
1134  arc[i] = i2fl(xc + (x2 * outer_rad) + offset_x);
1135  arc[i+1] = i2fl(yc + (y2 * outer_rad) + offset_y);
1136 
1137  arc[i+2] = i2fl(xc + (x2 * inner_rad) + offset_x);
1138  arc[i+3] = i2fl(yc + (y2 * inner_rad) + offset_y);
1139 
1140  t = x2;
1141  x2 = c * x1 - s * y1;
1142  y2 = s * t + c * y1;
1143 
1144  x1 = x2;
1145  y1 = y2;
1146  }
1147 
1148  vertex_layout vert_def;
1150  opengl_bind_vertex_layout(vert_def);
1151 
1152  glDrawArrays(GL_QUAD_STRIP, 0, segments * 2);
1153  }
1154 
1155  GL_CHECK_FOR_ERRORS("end of opengl_arc()");
1156 
1158 
1159  delete [] arc;
1160 }
1161 
1162 void gr_opengl_curve(int xc, int yc, int r, int direction, int resize_mode)
1163 {
1164  int a, b, p;
1165 
1166  if (resize_mode != GR_RESIZE_NONE) {
1167  gr_resize_screen_pos(&xc, &yc, NULL, NULL, resize_mode);
1168  }
1169 
1170  if ( (xc + r) < gr_screen.clip_left ) {
1171  return;
1172  }
1173 
1174  if ( (yc + r) < gr_screen.clip_top ) {
1175  return;
1176  }
1177 
1178  p = 3 - (2 * r);
1179  a = 0;
1180  b = r;
1181 
1182  switch (direction) {
1183  case 0: {
1184  yc += r;
1185  xc += r;
1186 
1187  while (a < b) {
1188  // Draw the first octant
1189  gr_opengl_line(xc - b + 1, yc - a, xc - b, yc - a, GR_RESIZE_NONE);
1190 
1191  if (p < 0) {
1192  p += (a << 2) + 6;
1193  } else {
1194  // Draw the second octant
1195  gr_opengl_line(xc - a + 1, yc - b, xc - a, yc - b, GR_RESIZE_NONE);
1196  p += ((a - b) << 2) + 10;
1197  b--;
1198  }
1199 
1200  a++;
1201  }
1202 
1203  break;
1204  }
1205 
1206  case 1: {
1207  yc += r;
1208 
1209  while (a < b) {
1210  // Draw the first octant
1211  gr_opengl_line(xc + b - 1, yc - a, xc + b, yc - a, GR_RESIZE_NONE);
1212 
1213  if (p < 0) {
1214  p += (a << 2) + 6;
1215  } else {
1216  // Draw the second octant
1217  gr_opengl_line(xc + a - 1, yc - b, xc + a, yc - b, GR_RESIZE_NONE);
1218  p += ((a - b) << 2) + 10;
1219  b--;
1220  }
1221 
1222  a++;
1223  }
1224 
1225  break;
1226  }
1227 
1228  case 2: {
1229  xc += r;
1230 
1231  while (a < b) {
1232  // Draw the first octant
1233  gr_opengl_line(xc - b + 1, yc + a, xc - b, yc + a, GR_RESIZE_NONE);
1234 
1235  if (p < 0) {
1236  p += (a << 2) + 6;
1237  } else {
1238  // Draw the second octant
1239  gr_opengl_line(xc - a + 1, yc + b, xc - a, yc + b, GR_RESIZE_NONE);
1240  p += ((a - b) << 2) + 10;
1241  b--;
1242  }
1243 
1244  a++;
1245  }
1246 
1247  break;
1248  }
1249 
1250  case 3: {
1251  while (a < b) {
1252  // Draw the first octant
1253  gr_opengl_line(xc + b - 1, yc + a, xc + b, yc + a, GR_RESIZE_NONE);
1254 
1255  if (p < 0) {
1256  p += (a << 2) + 6;
1257  } else {
1258  // Draw the second octant
1259  gr_opengl_line(xc + a - 1, yc + b, xc + a, yc + b, GR_RESIZE_NONE);
1260  p += ((a - b) << 2) + 10;
1261  b--;
1262  }
1263 
1264  a++;
1265  }
1266 
1267  break;
1268  }
1269  }
1270 }
1271 
1272 struct v6 { GLfloat x,y,z,w,u,v; };
1273 struct c4 { GLubyte r,g,b,a; };
1274 
1275 void opengl_draw_primitive(int nv, vertex **verts, uint flags, float u_scale, float v_scale, int r, int g, int b, int a, int override_primary = 0)
1276 {
1277  GLenum gl_mode = GL_TRIANGLE_FAN;
1278  float sx, sy, sz, sw;
1279  int i,j;
1280  vertex *va;
1281  bool isNebula = false;
1282  bool isRamp = false;
1283  bool isRGB = false;
1284  ubyte alpha = (ubyte)a;
1285  struct v6 *vertPos = (struct v6*) vm_malloc(sizeof(struct v6) * nv);
1286  struct c4 *vertCol = (struct c4*) vm_malloc(sizeof(struct c4) * nv);
1287 
1288  GL_CHECK_FOR_ERRORS("start of draw_primitive()");
1289 
1290  if (flags & TMAP_FLAG_NEBULA) {
1291  isNebula = true;
1292  } else if (flags & TMAP_FLAG_GOURAUD) {
1293  if (flags & TMAP_FLAG_RAMP) {
1294  isRamp = true;
1295  } else if (flags & TMAP_FLAG_RGB) {
1296  isRGB = true;
1297  }
1298  } else {
1299  GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, alpha );
1300  }
1301 
1302  if (flags & TMAP_FLAG_TRISTRIP) {
1303  gl_mode = GL_TRIANGLE_STRIP;
1304  } else if (flags & TMAP_FLAG_TRILIST) {
1305  gl_mode = GL_TRIANGLES;
1306  } else if (flags & TMAP_FLAG_QUADLIST) {
1307  gl_mode = GL_QUADS;
1308  } else if (flags & TMAP_FLAG_QUADSTRIP) {
1309  gl_mode = GL_TRIANGLE_STRIP;
1310  Assert((nv % 2) == 0);
1311  }
1312 
1313  for (i = (nv - 1), j = 0; i >= 0; i--, j++) {
1314  va = verts[i];
1315 
1316  sw = 1.0f;
1317 
1318  if ( gr_zbuffering || (flags & TMAP_FLAG_NEBULA) ) {
1319  sz = (1.0f - 1.0f / (1.0f + va->world.xyz.z / 32768.0f));
1320 
1321  // if ( sz > 0.98f ) {
1322  // sz = 0.98f;
1323  // }
1324  } else {
1325  sz = 0.99f;
1326  }
1327 
1328  sx = va->screen.xyw.x + (float)gr_screen.offset_x;
1329  sy = va->screen.xyw.y + (float)gr_screen.offset_y;
1330 
1331  if (flags & TMAP_FLAG_CORRECT) {
1332  sx /= va->screen.xyw.w;
1333  sy /= va->screen.xyw.w;
1334  sz /= va->screen.xyw.w;
1335  sw /= va->screen.xyw.w;
1336  }
1337 
1338  if (flags & TMAP_FLAG_ALPHA) {
1339  alpha = va->a;
1340  }
1341 
1342  if (override_primary) {
1343  vertCol[j].r = va->spec_r;
1344  vertCol[j].g = va->spec_g;
1345  vertCol[j].b = va->spec_b;
1346  vertCol[j].a = 255;
1347  } else {
1348  if (isNebula) {
1349  int pal = (va->b * (NEBULA_COLORS-1)) / 255;
1350  vertCol[j].r = gr_palette[pal*3+0];
1351  vertCol[j].g = gr_palette[pal*3+1];
1352  vertCol[j].b = gr_palette[pal*3+2];
1353  vertCol[j].a = alpha;
1354  } else if (isRamp) {
1355  vertCol[j].r = va->b;
1356  vertCol[j].g = va->b;
1357  vertCol[j].b = va->b;
1358  vertCol[j].a = alpha;
1359  } else if (isRGB) {
1360  vertCol[j].r = va->r;
1361  vertCol[j].g = va->g;
1362  vertCol[j].b = va->b;
1363  vertCol[j].a = alpha;
1364  }
1365  }
1366 
1367  if (flags & TMAP_FLAG_TEXTURED) {
1368  vertPos[j].u = va->texture_position.u * u_scale;
1369  vertPos[j].v = va->texture_position.v * v_scale;
1370  }
1371 
1372  vertPos[j].x = sx;
1373  vertPos[j].y = sy;
1374  vertPos[j].z = -sz;
1375  vertPos[j].w = sw;
1376  }
1377 
1379 
1380  vertex_layout vert_def;
1381 
1382  vert_def.add_vertex_component(vertex_format_data::POSITION4, sizeof(struct v6), &vertPos[0].x);
1383 
1384  if(flags & TMAP_FLAG_TEXTURED) {
1385  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, sizeof(struct v6), &vertPos[0].u);
1386  //vert_def.add_vertex_component(vertex_format_data::TEX_COORD1, sizeof(struct v6), &vertPos[0].u);
1387  }
1388 
1389  if(flags & (TMAP_FLAG_NEBULA | TMAP_FLAG_GOURAUD)) {
1390  vert_def.add_vertex_component(vertex_format_data::COLOR4, 0, &vertCol[0].r);
1391  }
1392 
1393  opengl_bind_vertex_layout(vert_def);
1394 
1395  glDrawArrays(gl_mode, 0, nv);
1396 
1397  GL_CHECK_FOR_ERRORS("start of draw_primitive()");
1398 
1399  vm_free(vertPos);
1400  vm_free(vertCol);
1401 }
1402 
1403 void opengl_tmapper_internal(int nv, vertex **verts, uint flags, int is_scaler = 0)
1404 {
1405  int i, stage = 0;
1406  float u_scale = 1.0f, v_scale = 1.0f;
1407  int alpha,tmap_type, r, g, b;
1408 
1409  GL_CHECK_FOR_ERRORS("start of tmapper_internal()");
1410 
1411  opengl_setup_render_states(r, g, b, alpha, tmap_type, flags, is_scaler);
1412 
1413  if (flags & TMAP_FLAG_TEXTURED) {
1414  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale, &v_scale, stage) ) {
1415  return;
1416  }
1417 
1418  stage++; // bump!
1419 
1420  // glowmap
1421  if ( Cmdline_glow && (GLOWMAP > -1) ) {
1422  if ( !gr_opengl_tcache_set(GLOWMAP, tmap_type, &u_scale, &v_scale, stage) ) {
1423  return;
1424  }
1425 
1427 
1428  stage++; // bump
1429  }
1430  }
1431 
1432 
1433  if ( (flags & TMAP_FLAG_PIXEL_FOG) && (Neb2_render_mode == NEB2_RENDER_POF) ) {
1434  int nr, ng, nb;
1435  int ra, ga, ba;
1436  ra = ga = ba = 0;
1437 
1438  for (i = (nv - 1); i >= 0; i--) {
1439  vertex *va = verts[i];
1440  float sx, sy;
1441 
1443  sx = ((va->screen.xyw.x * 16.0f) + ((float)gr_screen.offset_x * 16.0f)) / 16.0f;
1444  sy = ((va->screen.xyw.y * 16.0f) + ((float)gr_screen.offset_y * 16.0f)) / 16.0f;
1445  } else {
1446  sx = va->screen.xyw.x;
1447  sy = va->screen.xyw.y;
1448  }
1449 
1450  neb2_get_pixel( (int)sx, (int)sy, &nr, &ng, &nb );
1451 
1452  ra += nr;
1453  ga += ng;
1454  ba += nb;
1455  }
1456 
1457  ra /= nv;
1458  ga /= nv;
1459  ba /= nv;
1460 
1461  gr_fog_set(GR_FOGMODE_FOG, ra, ga, ba);
1462  }
1463 
1465 
1466  opengl_draw_primitive(nv, verts, flags, u_scale, v_scale, r, g, b, alpha);
1467 
1469 
1471 
1472  GL_CHECK_FOR_ERRORS("end of tmapper_internal()");
1473 }
1474 
1475 // ok we're making some assumptions for now. mainly it must not be multitextured, lit or fogged.
1477 {
1478  int alpha, tmap_type, r, g, b;
1479  float u_scale = 1.0f, v_scale = 1.0f;
1480  GLenum gl_mode = GL_TRIANGLE_FAN;
1481  bool isRGB = false;
1482 
1483  GL_CHECK_FOR_ERRORS("start of tmapper_internal3d()");
1484 
1485  opengl_setup_render_states(r, g, b, alpha, tmap_type, flags);
1486 
1487  if (flags & TMAP_FLAG_TEXTURED) {
1488  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale, &v_scale) ) {
1489  return;
1490  }
1491  }
1492 
1494 
1495  GLboolean cull_face = GL_state.CullFace(GL_FALSE);
1496 
1497  if (flags & TMAP_FLAG_TRILIST) {
1498  gl_mode = GL_TRIANGLES;
1499  } else if (flags & TMAP_FLAG_TRISTRIP) {
1500  gl_mode = GL_TRIANGLE_STRIP;
1501  } else if (flags & TMAP_FLAG_QUADLIST) {
1502  gl_mode = GL_QUADS;
1503  } else if (flags & TMAP_FLAG_QUADSTRIP) {
1504  gl_mode = GL_QUAD_STRIP;
1505  }
1506 
1507  if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
1508  isRGB = true;
1509  }
1510 
1511  // use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
1512  if ( !isRGB ) {
1513  GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
1514  }
1515 
1516  SCP_vector<ubyte> colour;
1517  SCP_vector<float> vertvec;
1518  SCP_vector<float> uvcoords;
1519 
1520  if (isRGB)
1521  colour.reserve(nv * 4);
1522 
1523  vertvec.reserve(nv * 3);
1524  uvcoords.reserve(nv * 2);
1525 
1526  for (int i = 0; i < nv; i++) {
1527  vertex *va = verts[i];
1528 
1529  if (isRGB) {
1530  colour.push_back(va->r);
1531  colour.push_back(va->g);
1532  colour.push_back(va->b);
1533  colour.push_back((ubyte) alpha);
1534  }
1535 
1536  uvcoords.push_back(va->texture_position.u);
1537  uvcoords.push_back(va->texture_position.v);
1538 
1539  vertvec.push_back(va->world.xyz.x);
1540  vertvec.push_back(va->world.xyz.y);
1541  vertvec.push_back(va->world.xyz.z);
1542  }
1543 
1545 
1546  vertex_layout vert_def;
1547 
1548  if (isRGB) {
1549  vert_def.add_vertex_component(vertex_format_data::COLOR4, 0, &colour.front());
1550  }
1551 
1552  vert_def.add_vertex_component(vertex_format_data::POSITION3, 0, &vertvec.front());
1553  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, 0, &uvcoords.front());
1554 
1555  opengl_bind_vertex_layout(vert_def);
1556 
1557  glDrawArrays(gl_mode, 0, nv);
1558 
1559  GL_state.CullFace(cull_face);
1560 
1561  GL_CHECK_FOR_ERRORS("end of tmapper_internal3d()");
1562 }
1563 
1564 void gr_opengl_tmapper(int nverts, vertex **verts, uint flags)
1565 {
1566  if ( !Cmdline_nohtl && (flags & TMAP_HTL_3D_UNLIT) ) {
1567  opengl_tmapper_internal3d(nverts, verts, flags);
1568  } else {
1569  opengl_tmapper_internal(nverts, verts, flags);
1570  }
1571 }
1572 
1573 void opengl_render_internal(int nverts, vertex *verts, uint flags)
1574 {
1575  int alpha, tmap_type, r, g, b;
1576  float u_scale = 1.0f, v_scale = 1.0f;
1577  GLenum gl_mode = GL_TRIANGLE_FAN;
1578  bool texture_matrix_set = false;
1579 
1580  GL_CHECK_FOR_ERRORS("start of render()");
1581 
1582  opengl_setup_render_states(r, g, b, alpha, tmap_type, flags);
1583 
1584  if (flags & TMAP_FLAG_TRILIST) {
1585  gl_mode = GL_TRIANGLES;
1586  } else if (flags & TMAP_FLAG_TRISTRIP) {
1587  gl_mode = GL_TRIANGLE_STRIP;
1588  } else if (flags & TMAP_FLAG_QUADLIST) {
1589  gl_mode = GL_QUADS;
1590  } else if (flags & TMAP_FLAG_QUADSTRIP) {
1591  gl_mode = GL_QUAD_STRIP;
1592  }
1593 
1595 
1596  vertex_layout vert_def;
1597 
1598  if (flags & TMAP_FLAG_TEXTURED) {
1599  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale, &v_scale) ) {
1600  return;
1601  }
1602 
1603  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, sizeof(vertex), &verts[0].texture_position.u);
1604 
1605  // adjust texture coords if needed
1606  if ( (u_scale != 1.0f) || (v_scale != 1.0f) ) {
1608  glPushMatrix();
1609  glScalef(u_scale, v_scale, 1.0f);
1610 
1611  // switch back to the default modelview mode
1613 
1614  texture_matrix_set = true;
1615  }
1616  }
1617 
1618  if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
1619  if (flags & TMAP_FLAG_ALPHA) {
1620  vert_def.add_vertex_component(vertex_format_data::COLOR4, sizeof(vertex), &verts[0].r);
1621  } else {
1622  GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
1623  vert_def.add_vertex_component(vertex_format_data::COLOR3, sizeof(vertex), &verts[0].r);
1624  }
1625  }
1626  // use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
1627  else {
1628  GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
1629  }
1630 
1631  float offset_z = -0.99f;
1632 
1633  glPushMatrix();
1634  glTranslatef((float)gr_screen.offset_x, (float)gr_screen.offset_y, offset_z);
1635 
1636  vert_def.add_vertex_component(vertex_format_data::POSITION2, sizeof(vertex), &verts[0].screen.xyw.x);
1637 
1638  opengl_bind_vertex_layout(vert_def);
1639 
1641 
1642  glDrawArrays(gl_mode, 0, nverts);
1643 
1645 
1647 
1648  if (texture_matrix_set) {
1650  glPopMatrix();
1652  }
1653 
1654  glPopMatrix();
1655 
1656  GL_CHECK_FOR_ERRORS("end of render()");
1657 }
1658 
1659 void opengl_render_internal3d(int nverts, vertex *verts, uint flags)
1660 {
1661  int alpha, tmap_type, r, g, b;
1662  float u_scale = 1.0f, v_scale = 1.0f;
1663  GLenum gl_mode = GL_TRIANGLE_FAN;
1664 
1665  GL_CHECK_FOR_ERRORS("start of render3d()");
1666 
1667  opengl_setup_render_states(r, g, b, alpha, tmap_type, flags);
1668 
1670 
1671  vertex_layout vert_def;
1672 
1673  if (flags & TMAP_FLAG_TEXTURED) {
1674  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale, &v_scale) ) {
1675  return;
1676  }
1677 
1678  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, sizeof(vertex), &verts[0].texture_position.u);
1679  }
1680 
1681  GLboolean cull_face = GL_state.CullFace(GL_FALSE);
1682  GLboolean lighting = GL_state.Lighting(GL_FALSE);
1683 
1684  if (flags & TMAP_FLAG_TRILIST) {
1685  gl_mode = GL_TRIANGLES;
1686  } else if (flags & TMAP_FLAG_TRISTRIP) {
1687  gl_mode = GL_TRIANGLE_STRIP;
1688  } else if (flags & TMAP_FLAG_QUADLIST) {
1689  gl_mode = GL_QUADS;
1690  } else if (flags & TMAP_FLAG_QUADSTRIP) {
1691  gl_mode = GL_QUAD_STRIP;
1692  } else if (flags & TMAP_FLAG_LINES) {
1693  gl_mode = GL_LINES;
1694  }
1695 
1696  if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
1697  vert_def.add_vertex_component(vertex_format_data::COLOR4, sizeof(vertex), &verts[0].r);
1698  }
1699  // use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
1700  else {
1701  GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
1702  }
1703 
1704  vert_def.add_vertex_component(vertex_format_data::POSITION3, sizeof(vertex), &verts[0].world.xyz.x);
1705 
1706  opengl_bind_vertex_layout(vert_def);
1707 
1708  glDrawArrays(gl_mode, 0, nverts);
1709 
1710  GL_state.CullFace(cull_face);
1711  GL_state.Lighting(lighting);
1712 
1713  GL_CHECK_FOR_ERRORS("end of render3d()");
1714 }
1715 
1716 //Used by the effects batcher to determine whether to use shaders or not
1718 
1719 void gr_opengl_render_effect(int nverts, vertex *verts, float *radius_list, uint flags)
1720 {
1721  int alpha, tmap_type, r, g, b;
1722  float u_scale = 1.0f, v_scale = 1.0f;
1723  GLenum gl_mode = GL_TRIANGLE_FAN;
1724  int zbuff = ZBUFFER_TYPE_DEFAULT;
1725  GL_CHECK_FOR_ERRORS("start of render3d()");
1726 
1728 
1729  opengl_setup_render_states(r, g, b, alpha, tmap_type, flags);
1730 
1732 
1733  vertex_layout vert_def;
1734 
1735  if ( flags & TMAP_FLAG_TEXTURED ) {
1736  if ( flags & TMAP_FLAG_SOFT_QUAD ) {
1737  if( (flags & TMAP_FLAG_DISTORTION) || (flags & TMAP_FLAG_DISTORTION_THRUSTER) )
1738  {
1740 
1742 
1743  zbuff = gr_zbuffer_set(GR_ZBUFF_READ);
1744  }
1745  else
1746  {
1748  zbuff = gr_zbuffer_set(GR_ZBUFF_NONE);
1749  }
1750 
1751  vert_def.add_vertex_component(vertex_format_data::RADIUS, 0, radius_list);
1752  }
1753 
1754  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, tmap_type, &u_scale, &v_scale) ) {
1755  return;
1756  }
1757 
1758  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, sizeof(vertex), &verts[0].texture_position.u);
1759  }
1760 
1761  GLboolean cull_face = GL_state.CullFace(GL_FALSE);
1762  GLboolean lighting = GL_state.Lighting(GL_FALSE);
1763 
1764  if (flags & TMAP_FLAG_TRILIST) {
1765  gl_mode = GL_TRIANGLES;
1766  } else if (flags & TMAP_FLAG_TRISTRIP) {
1767  gl_mode = GL_TRIANGLE_STRIP;
1768  } else if (flags & TMAP_FLAG_QUADLIST) {
1769  gl_mode = GL_QUADS;
1770  } else if (flags & TMAP_FLAG_QUADSTRIP) {
1771  gl_mode = GL_QUAD_STRIP;
1772  }
1773 
1774  if ( (flags & TMAP_FLAG_RGB) && (flags & TMAP_FLAG_GOURAUD) ) {
1775  vert_def.add_vertex_component(vertex_format_data::COLOR4, sizeof(vertex), &verts[0].r);
1776  }
1777  // use what opengl_setup_render_states() gives us since this works much better for nebula and transparency
1778  else {
1779  GL_state.Color( (ubyte)r, (ubyte)g, (ubyte)b, (ubyte)alpha );
1780  }
1781 
1782  vert_def.add_vertex_component(vertex_format_data::POSITION3, sizeof(vertex), &verts[0].world.xyz.x);
1783 
1784  opengl_bind_vertex_layout(vert_def);
1785 
1786  glDrawArrays(gl_mode, 0, nverts);
1787 
1789 
1791 
1792  GL_state.CullFace(cull_face);
1793  GL_state.Lighting(lighting);
1794  gr_zbuffer_set(zbuff);
1795 
1796  GL_CHECK_FOR_ERRORS("end of render3d()");
1797 }
1798 
1799 void gr_opengl_render(int nverts, vertex *verts, uint flags)
1800 {
1801  if ( !Cmdline_nohtl && (flags & TMAP_HTL_3D_UNLIT) ) {
1802  opengl_render_internal3d(nverts, verts, flags);
1803  } else {
1804  opengl_render_internal(nverts, verts, flags);
1805  }
1806 }
1807 
1808 
1809 #define FIND_SCALED_NUM(x, x0, x1, y0, y1) ( ((((x) - (x0)) * ((y1) - (y0))) / ((x1) - (x0))) + (y0) )
1810 
1811 void gr_opengl_scaler(vertex *va, vertex *vb, bool bw_bitmap = false)
1812 {
1813  float x0, y0, x1, y1;
1814  float u0, v0, u1, v1;
1815  float clipped_x0, clipped_y0, clipped_x1, clipped_y1;
1816  float clipped_u0, clipped_v0, clipped_u1, clipped_v1;
1817  float xmin, xmax, ymin, ymax;
1818  int dx0, dy0, dx1, dy1;
1819 
1820  x0 = va->screen.xyw.x;
1821  y0 = va->screen.xyw.y;
1822  x1 = vb->screen.xyw.x;
1823  y1 = vb->screen.xyw.y;
1824 
1825  xmin = i2fl(gr_screen.clip_left);
1826  ymin = i2fl(gr_screen.clip_top);
1827  xmax = i2fl(gr_screen.clip_right);
1828  ymax = i2fl(gr_screen.clip_bottom);
1829 
1830  u0 = va->texture_position.u; v0 = va->texture_position.v;
1831  u1 = vb->texture_position.u; v1 = vb->texture_position.v;
1832 
1833  // Check for obviously offscreen bitmaps...
1834  if ( (y1 <= y0) || (x1 <= x0) ) {
1835  return;
1836  }
1837 
1838  if ( (x1 < xmin ) || (x0 > xmax) ) {
1839  return;
1840  }
1841 
1842  if ( (y1 < ymin ) || (y0 > ymax) ) {
1843  return;
1844  }
1845 
1846  clipped_u0 = u0;
1847  clipped_v0 = v0;
1848  clipped_u1 = u1;
1849  clipped_v1 = v1;
1850 
1851  clipped_x0 = x0;
1852  clipped_y0 = y0;
1853  clipped_x1 = x1;
1854  clipped_y1 = y1;
1855 
1856  // Clip the left, moving u0 right as necessary
1857  if (x0 < xmin) {
1858  clipped_u0 = FIND_SCALED_NUM(xmin, x0, x1, u0, u1);
1859  clipped_x0 = xmin;
1860  }
1861 
1862  // Clip the right, moving u1 left as necessary
1863  if (x1 > xmax) {
1864  clipped_u1 = FIND_SCALED_NUM(xmax, x0, x1, u0, u1);
1865  clipped_x1 = xmax;
1866  }
1867 
1868  // Clip the top, moving v0 down as necessary
1869  if (y0 < ymin) {
1870  clipped_v0 = FIND_SCALED_NUM(ymin, y0, y1, v0, v1);
1871  clipped_y0 = ymin;
1872  }
1873 
1874  // Clip the bottom, moving v1 up as necessary
1875  if (y1 > ymax) {
1876  clipped_v1 = FIND_SCALED_NUM(ymax, y0, y1, v0, v1);
1877  clipped_y1 = ymax;
1878  }
1879 
1880  dx0 = fl2i(clipped_x0);
1881  dx1 = fl2i(clipped_x1);
1882  dy0 = fl2i(clipped_y0);
1883  dy1 = fl2i(clipped_y1);
1884 
1885  if ( (dx1 <= dx0) || (dy1 <= dy0) ) {
1886  return;
1887  }
1888 
1889 
1890  vertex v[4];
1891  vertex *vl[4];
1892 
1893  vl[0] = &v[0];
1894  v[0].screen.xyw.x = clipped_x0;
1895  v[0].screen.xyw.y = clipped_y0;
1896  v[0].screen.xyw.w = va->screen.xyw.w;
1897  v[0].world.xyz.z = va->world.xyz.z;
1898  v[0].texture_position.u = clipped_u0;
1899  v[0].texture_position.v = clipped_v0;
1900  v[0].spec_r = 0;
1901  v[0].spec_g = 0;
1902  v[0].spec_b = 0;
1903 
1904  vl[1] = &v[1];
1905  v[1].screen.xyw.x = clipped_x1;
1906  v[1].screen.xyw.y = clipped_y0;
1907  v[1].screen.xyw.w = va->screen.xyw.w;
1908  v[1].world.xyz.z = va->world.xyz.z;
1909  v[1].texture_position.u = clipped_u1;
1910  v[1].texture_position.v = clipped_v0;
1911  v[1].spec_r = 0;
1912  v[1].spec_g = 0;
1913  v[1].spec_b = 0;
1914 
1915  vl[2] = &v[2];
1916  v[2].screen.xyw.x = clipped_x1;
1917  v[2].screen.xyw.y = clipped_y1;
1918  v[2].screen.xyw.w = va->screen.xyw.w;
1919  v[2].world.xyz.z = va->world.xyz.z;
1920  v[2].texture_position.u = clipped_u1;
1921  v[2].texture_position.v = clipped_v1;
1922  v[2].spec_r = 0;
1923  v[2].spec_g = 0;
1924  v[2].spec_b = 0;
1925 
1926  vl[3] = &v[3];
1927  v[3].screen.xyw.x = clipped_x0;
1928  v[3].screen.xyw.y = clipped_y1;
1929  v[3].screen.xyw.w = va->screen.xyw.w;
1930  v[3].world.xyz.z = va->world.xyz.z;
1931  v[3].texture_position.u = clipped_u0;
1932  v[3].texture_position.v = clipped_v1;
1933  v[3].spec_r = 0;
1934  v[3].spec_g = 0;
1935  v[3].spec_b = 0;
1936 
1937  if (!bw_bitmap)
1938  {
1940  }
1941  else
1942  {
1944  }
1945 }
1946 
1947 
1948 // cross fade
1949 void gr_opengl_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct, int resize_mode)
1950 {
1952  gr_bitmap(x1, y1, resize_mode);
1953 
1955  gr_bitmap(x2, y2, resize_mode);
1956 }
1957 
1958 void gr_opengl_shade(int x, int y, int w, int h, int resize_mode)
1959 {
1960  if (resize_mode != GR_RESIZE_NONE) {
1961  gr_resize_screen_pos(&x, &y, &w, &h, resize_mode);
1962  }
1963 
1964  int x1 = (gr_screen.offset_x + x);
1965  int y1 = (gr_screen.offset_y + y);
1966  int x2 = (gr_screen.offset_x + w);
1967  int y2 = (gr_screen.offset_y + h);
1968 
1969  if ( (x1 >= gr_screen.max_w) || (y1 >= gr_screen.max_h) ) {
1970  return;
1971  }
1972 
1973  CLAMP(x2, x1+1, gr_screen.max_w);
1974  CLAMP(y2, y1+1, gr_screen.max_h);
1975 
1979 
1981 
1984 
1985  opengl_draw_coloured_quad((GLint)x1, (GLint)y1, (GLint)x2, (GLint)y2);
1986 
1988 }
1989 
1990 void gr_opengl_flash(int r, int g, int b)
1991 {
1992  if ( !(r || g || b) ) {
1993  return;
1994  }
1995 
1996  CLAMP(r, 0, 255);
1997  CLAMP(g, 0, 255);
1998  CLAMP(b, 0, 255);
1999 
2003 
2004  int x1 = (gr_screen.clip_left + gr_screen.offset_x);
2005  int y1 = (gr_screen.clip_top + gr_screen.offset_y);
2006  int x2 = (gr_screen.clip_right + gr_screen.offset_x) + 1;
2007  int y2 = (gr_screen.clip_bottom + gr_screen.offset_y) + 1;
2008 
2009  GL_state.Color( (GLubyte)r, (GLubyte)g, (GLubyte)b, 255 );
2010 
2011  opengl_draw_coloured_quad((GLint)x1, (GLint)y1, (GLint)x2, (GLint)y2);
2012 }
2013 
2014 void gr_opengl_flash_alpha(int r, int g, int b, int a)
2015 {
2016  if ( !(r || g || b || a) ) {
2017  return;
2018  }
2019 
2020  CLAMP(r, 0, 255);
2021  CLAMP(g, 0, 255);
2022  CLAMP(b, 0, 255);
2023  CLAMP(a, 0, 255);
2024 
2028 
2029  int x1 = (gr_screen.clip_left + gr_screen.offset_x);
2030  int y1 = (gr_screen.clip_top + gr_screen.offset_y);
2031  int x2 = (gr_screen.clip_right + gr_screen.offset_x) + 1;
2032  int y2 = (gr_screen.clip_bottom + gr_screen.offset_y) + 1;
2033 
2034  GL_state.Color( (GLubyte)r, (GLubyte)g, (GLubyte)b, (GLubyte)a );
2035 
2036  opengl_draw_coloured_quad((GLint)x1, (GLint)y1, (GLint)x2, (GLint)y2);
2037 }
2038 
2039 void opengl_bitmap_ex_internal(int x, int y, int w, int h, int sx, int sy, int resize_mode)
2040 {
2041  if ( (w < 1) || (h < 1) ) {
2042  return;
2043  }
2044 
2045  float u_scale, v_scale;
2046  float u0, u1, v0, v1;
2047  float x1, x2, y1, y2;
2048  int bw, bh, do_resize;
2049 
2053 
2054  if ( !gr_opengl_tcache_set(gr_screen.current_bitmap, TCACHE_TYPE_INTERFACE, &u_scale, &v_scale) ) {
2055  return;
2056  }
2057 
2058  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
2059  do_resize = 1;
2060  } else {
2061  do_resize = 0;
2062  }
2063 
2065 
2066  u0 = u_scale * (i2fl(sx) / i2fl(bw));
2067  v0 = v_scale * (i2fl(sy) / i2fl(bh));
2068 
2069  u1 = u_scale * (i2fl(sx+w) / i2fl(bw));
2070  v1 = v_scale * (i2fl(sy+h) / i2fl(bh));
2071 
2072  x1 = i2fl(x + ((do_resize) ? gr_screen.offset_x_unscaled : gr_screen.offset_x));
2073  y1 = i2fl(y + ((do_resize) ? gr_screen.offset_y_unscaled : gr_screen.offset_y));
2074  x2 = x1 + i2fl(w);
2075  y2 = y1 + i2fl(h);
2076 
2077  if (do_resize) {
2078  gr_resize_screen_posf(&x1, &y1, NULL, NULL, resize_mode);
2079  gr_resize_screen_posf(&x2, &y2, NULL, NULL, resize_mode);
2080  }
2081 
2082  GL_state.Color(255, 255, 255, (GLubyte)(gr_screen.current_alpha * 255));
2083 
2084  opengl_draw_textured_quad(x1, y1, u0, v0, x2, y2, u1, v1);
2085 }
2086 
2087 
2088 //these are penguins bitmap functions
2089 void gr_opengl_bitmap_ex(int x, int y, int w, int h, int sx, int sy, int resize_mode)
2090 {
2091  int reclip;
2092 #ifndef NDEBUG
2093  int count = 0;
2094 #endif
2095 
2096  int dx1 = x;
2097  int dx2 = x + w - 1;
2098  int dy1 = y;
2099  int dy2 = y + h - 1;
2100 
2101  int bw, bh, do_resize;
2102 
2104 
2105  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
2106  do_resize = 1;
2107  } else {
2108  do_resize = 0;
2109  }
2110 
2111  int clip_left = ((do_resize) ? gr_screen.clip_left_unscaled : gr_screen.clip_left);
2112  int clip_right = ((do_resize) ? gr_screen.clip_right_unscaled : gr_screen.clip_right);
2113  int clip_top = ((do_resize) ? gr_screen.clip_top_unscaled : gr_screen.clip_top);
2114  int clip_bottom = ((do_resize) ? gr_screen.clip_bottom_unscaled : gr_screen.clip_bottom);
2115 
2116  do {
2117  reclip = 0;
2118 
2119 #ifndef NDEBUG
2120  if (count > 1) {
2121  Int3();
2122  }
2123 
2124  count++;
2125 #endif
2126 
2127  if ( (dx1 > clip_right) || (dx2 < clip_left) ) {
2128  return;
2129  }
2130 
2131  if ( (dy1 > clip_bottom) || (dy2 < clip_top) ) {
2132  return;
2133  }
2134 
2135  if ( dx1 < clip_left ) {
2136  sx += clip_left-dx1;
2137  dx1 = clip_left;
2138  }
2139 
2140  if ( dy1 < clip_top ) {
2141  sy += clip_top-dy1;
2142  dy1 = clip_top;
2143  }
2144 
2145  if ( dx2 > clip_right ) {
2146  dx2 = clip_right;
2147  }
2148 
2149  if ( dy2 > clip_bottom ) {
2150  dy2 = clip_bottom;
2151  }
2152 
2153  if ( sx < 0 ) {
2154  dx1 -= sx;
2155  sx = 0;
2156  reclip = 1;
2157  }
2158 
2159  if ( sy < 0 ) {
2160  dy1 -= sy;
2161  sy = 0;
2162  reclip = 1;
2163  }
2164 
2165  w = dx2 - dx1 + 1;
2166  h = dy2 - dy1 + 1;
2167 
2168  if ( (sx + w) > bw ) {
2169  w = bw - sx;
2170  dx2 = dx1 + w - 1;
2171  }
2172 
2173  if ( (sy + h) > bh ) {
2174  h = bh - sy;
2175  dy2 = dy1 + h - 1;
2176  }
2177 
2178  if ( (w < 1) || (h < 1) ) {
2179  // clipped away!
2180  return;
2181  }
2182  } while (reclip);
2183 
2184  // Make sure clipping algorithm works
2185 #ifndef NDEBUG
2186  Assert( w > 0 );
2187  Assert( h > 0 );
2188  Assert( w == (dx2 - dx1 + 1) );
2189  Assert( h == (dy2 - dy1 + 1) );
2190  Assert( sx >= 0 );
2191  Assert( sy >= 0 );
2192  Assert( (sx + w) <= bw );
2193  Assert( (sy + h) <= bh );
2194  Assert( dx2 >= dx1 );
2195  Assert( dy2 >= dy1 );
2196  Assert( (dx1 >= clip_left) && (dx1 <= clip_right) );
2197  Assert( (dx2 >= clip_left) && (dx2 <= clip_right) );
2198  Assert( (dy1 >= clip_top) && (dy1 <= clip_bottom) );
2199  Assert( (dy2 >= clip_top) && (dy2 <= clip_bottom) );
2200 #endif
2201 
2202  // We now have dx1,dy1 and dx2,dy2 and sx, sy all set validly within clip regions.
2203  opengl_bitmap_ex_internal(dx1, dy1, (dx2 - dx1 + 1), (dy2 - dy1 + 1), sx, sy, resize_mode);
2204 }
2205 
2206 /*void gr_opengl_bitmap(int x, int y, int resize_mode)
2207 {
2208  int w, h, do_resize;
2209 
2210  bm_get_info( gr_screen.current_bitmap, &w, &h, NULL );
2211 
2212  if ( resize_mode != GR_RESIZE_NONE && (gr_screen.custom_size || (gr_screen.rendering_to_texture != -1)) ) {
2213  do_resize = 1;
2214  } else {
2215  do_resize = 0;
2216  }
2217 
2218  int dx1=x, dx2=x+w-1;
2219  int dy1=y, dy2=y+h-1;
2220  int sx=0, sy=0;
2221 
2222  int clip_left = ((do_resize) ? gr_screen.clip_left_unscaled : gr_screen.clip_left);
2223  int clip_right = ((do_resize) ? gr_screen.clip_right_unscaled : gr_screen.clip_right);
2224  int clip_top = ((do_resize) ? gr_screen.clip_top_unscaled : gr_screen.clip_top);
2225  int clip_bottom = ((do_resize) ? gr_screen.clip_bottom_unscaled : gr_screen.clip_bottom);
2226 
2227  if ( (dx1 > clip_right) || (dx2 < clip_left) ) return;
2228  if ( (dy1 > clip_bottom) || (dy2 < clip_top) ) return;
2229  if ( dx1 < clip_left ) { sx = clip_left-dx1; dx1 = clip_left; }
2230  if ( dy1 < clip_top ) { sy = clip_top-dy1; dy1 = clip_top; }
2231  if ( dx2 > clip_right ) { dx2 = clip_right; }
2232  if ( dy2 > clip_bottom ) { dy2 = clip_bottom; }
2233 
2234  if ( sx < 0 ) return;
2235  if ( sy < 0 ) return;
2236  if ( sx >= w ) return;
2237  if ( sy >= h ) return;
2238 
2239  // Draw bitmap bm[sx,sy] into (dx1,dy1)-(dx2,dy2)
2240  gr_opengl_bitmap_ex(dx1, dy1, dx2-dx1+1, dy2-dy1+1, sx, sy, resize_mode);
2241 }*/
2242 
2243 void gr_opengl_sphere_htl(float rad)
2244 {
2245  if (Cmdline_nohtl) {
2246  return;
2247  }
2248 
2249  GLUquadricObj *quad = NULL;
2250 
2251  // FIXME: before this is used in anything other than FRED2 we need to make this creation/deletion
2252  // stuff global so that it's not so slow (it can be reused for multiple quadratic objects)
2253  quad = gluNewQuadric();
2254 
2255  if (quad == NULL) {
2256  Int3();
2257  return;
2258  }
2259 
2264 
2266 
2267  // FIXME: opengl_check_for_errors() needs to be modified to work with this at
2268  // some point but for now I just don't care so it does nothing
2269  gluQuadricCallback(quad, GLU_ERROR, NULL);
2270 
2271  // FIXME: maybe support fill/wireframe with a future flag?
2272  gluQuadricDrawStyle(quad, GLU_FILL);
2273 
2274  // assuming unlit spheres, otherwise use GLU_SMOOTH so that it looks better
2275  gluQuadricNormals(quad, GLU_NONE);
2276 
2277  // we could set the slices/stacks at some point in the future but just use 16 now since it looks ok
2278  gluSphere(quad, (GLdouble)rad, 16, 16);
2279 
2280  // FIXME: I just heard this scream "Globalize Me!!". It was really scary. I even cried.
2281  gluDeleteQuadric(quad);
2282 }
2283 
2284 void gr_opengl_deferred_light_sphere_init(int rings, int segments) // Generate a VBO of a sphere of radius 1.0f, based on code at http://www.ogre3d.org/tikiwiki/ManualSphereMeshes
2285 {
2286  unsigned int nVertex = (rings + 1) * (segments+1) * 3;
2287  unsigned int nIndex = deferred_light_sphere_icount = 6 * rings * (segments + 1);
2288  float *Vertices = (float*)vm_malloc(sizeof(float) * nVertex);
2289  float *pVertex = Vertices;
2290  ushort *Indices = (ushort*)vm_malloc(sizeof(ushort) * nIndex);
2291  ushort *pIndex = Indices;
2292 
2293  float fDeltaRingAngle = (PI / rings);
2294  float fDeltaSegAngle = (2.0f * PI / segments);
2295  unsigned short wVerticeIndex = 0 ;
2296 
2297  // Generate the group of rings for the sphere
2298  for( int ring = 0; ring <= rings; ring++ ) {
2299  float r0 = sinf (ring * fDeltaRingAngle);
2300  float y0 = cosf (ring * fDeltaRingAngle);
2301 
2302  // Generate the group of segments for the current ring
2303  for(int seg = 0; seg <= segments; seg++) {
2304  float x0 = r0 * sinf(seg * fDeltaSegAngle);
2305  float z0 = r0 * cosf(seg * fDeltaSegAngle);
2306 
2307  // Add one vertex to the strip which makes up the sphere
2308  *pVertex++ = x0;
2309  *pVertex++ = y0;
2310  *pVertex++ = z0;
2311 
2312  if (ring != rings) {
2313  // each vertex (except the last) has six indices pointing to it
2314  *pIndex++ = wVerticeIndex + (ushort)segments + 1;
2315  *pIndex++ = wVerticeIndex;
2316  *pIndex++ = wVerticeIndex + (ushort)segments;
2317  *pIndex++ = wVerticeIndex + (ushort)segments + 1;
2318  *pIndex++ = wVerticeIndex + 1;
2319  *pIndex++ = wVerticeIndex;
2320  wVerticeIndex ++;
2321  }
2322  }; // end for seg
2323  } // end for ring
2324 
2325  deferred_light_sphere_vcount = wVerticeIndex;
2326 
2327  glGetError();
2328 
2330 
2331  // make sure we have one
2334  vglBufferDataARB(GL_ARRAY_BUFFER_ARB, nVertex * sizeof(float), Vertices, GL_STATIC_DRAW_ARB);
2335 
2336  // just in case
2337  if ( opengl_check_for_errors() ) {
2340  return;
2341  }
2342 
2344 
2345  vm_free(Vertices);
2346  Vertices = NULL;
2347  }
2348 
2350 
2351  // make sure we have one
2355 
2356  // just in case
2357  if ( opengl_check_for_errors() ) {
2360  return;
2361  }
2362 
2364 
2365  vm_free(Indices);
2366  Indices = NULL;
2367  }
2368 
2369 }
2370 
2371 void gr_opengl_draw_deferred_light_sphere(vec3d *position, float rad, bool clearStencil = true)
2372 {
2373  if (Cmdline_nohtl) {
2374  return;
2375  }
2376 
2378 
2379  GL_state.Uniform.setUniform3f("scale", rad, rad, rad);
2380 
2383 
2384  vertex_layout vertex_declare;
2385 
2387 
2388  opengl_bind_vertex_layout(vertex_declare);
2389 
2391 
2392  g3_done_instance(true);
2393 }
2394 
2395 void gr_opengl_deferred_light_cylinder_init(int segments) // Generate a VBO of a cylinder of radius and height 1.0f, based on code at http://www.ogre3d.org/tikiwiki/ManualSphereMeshes
2396 {
2397  unsigned int nVertex = (segments + 1) * 2 * 3 + 6; // Can someone verify this?
2398  unsigned int nIndex = deferred_light_cylinder_icount = 12 * (segments + 1) - 6; //This too
2399  float *Vertices = (float*)vm_malloc(sizeof(float) * nVertex);
2400  float *pVertex = Vertices;
2401  ushort *Indices = (ushort*)vm_malloc(sizeof(ushort) * nIndex);
2402  ushort *pIndex = Indices;
2403 
2404  float fDeltaSegAngle = (2.0f * PI / segments);
2405  unsigned short wVerticeIndex = 0 ;
2406 
2407  *pVertex++ = 0.0f;
2408  *pVertex++ = 0.0f;
2409  *pVertex++ = 0.0f;
2410  wVerticeIndex ++;
2411  *pVertex++ = 0.0f;
2412  *pVertex++ = 0.0f;
2413  *pVertex++ = 1.0f;
2414  wVerticeIndex ++;
2415 
2416  for( int ring = 0; ring <= 1; ring++ ) {
2417  float z0 = (float)ring;
2418 
2419  // Generate the group of segments for the current ring
2420  for(int seg = 0; seg <= segments; seg++) {
2421  float x0 = sinf(seg * fDeltaSegAngle);
2422  float y0 = cosf(seg * fDeltaSegAngle);
2423 
2424  // Add one vertex to the strip which makes up the cylinder
2425  *pVertex++ = x0;
2426  *pVertex++ = y0;
2427  *pVertex++ = z0;
2428 
2429  if (!ring) {
2430  *pIndex++ = wVerticeIndex + (ushort)segments + 1;
2431  *pIndex++ = wVerticeIndex;
2432  *pIndex++ = wVerticeIndex + (ushort)segments;
2433  *pIndex++ = wVerticeIndex + (ushort)segments + 1;
2434  *pIndex++ = wVerticeIndex + 1;
2435  *pIndex++ = wVerticeIndex;
2436  if(seg != segments)
2437  {
2438  *pIndex++ = wVerticeIndex + 1;
2439  *pIndex++ = wVerticeIndex;
2440  *pIndex++ = 0;
2441  }
2442  wVerticeIndex ++;
2443  }
2444  else
2445  {
2446  if(seg != segments)
2447  {
2448  *pIndex++ = wVerticeIndex + 1;
2449  *pIndex++ = wVerticeIndex;
2450  *pIndex++ = 1;
2451  wVerticeIndex ++;
2452  }
2453  }
2454  }; // end for seg
2455  } // end for ring
2456 
2457  deferred_light_cylinder_vcount = wVerticeIndex;
2458 
2459  glGetError();
2460 
2462 
2463  // make sure we have one
2466  vglBufferDataARB(GL_ARRAY_BUFFER_ARB, nVertex * sizeof(float), Vertices, GL_STATIC_DRAW_ARB);
2467 
2468  // just in case
2469  if ( opengl_check_for_errors() ) {
2472  return;
2473  }
2474 
2476 
2477  vm_free(Vertices);
2478  Vertices = NULL;
2479  }
2480 
2482 
2483  // make sure we have one
2487 
2488  // just in case
2489  if ( opengl_check_for_errors() ) {
2492  return;
2493  }
2494 
2496 
2497  vm_free(Indices);
2498  Indices = NULL;
2499  }
2500 
2501 }
2502 
2503 void gr_opengl_draw_deferred_light_cylinder(vec3d *position,matrix *orient, float rad, float length, bool clearStencil = true)
2504 {
2505  if (Cmdline_nohtl) {
2506  return;
2507  }
2508 
2509  g3_start_instance_matrix(position, orient, true);
2510 
2511  GL_state.Uniform.setUniform3f("scale", rad, rad, length);
2512 
2515 
2516  vertex_layout vertex_declare;
2517 
2519 
2520  opengl_bind_vertex_layout(vertex_declare);
2521 
2523 
2524  g3_done_instance(true);
2525 }
2526 
2528 {
2529  if (Cmdline_nohtl) {
2530  return;
2531  }
2532 }
2533 extern int opengl_check_framebuffer();
2535 {
2537 
2539  Cmdline_postprocess = 0;
2542 
2543  Scene_color_texture = 0;
2545  Scene_depth_texture = 0;
2546  return;
2547  }
2548 
2549  // for ease of use we require support for non-power-of-2 textures in one
2550  // form or another:
2551  // - the NPOT extension
2552  // - GL version 2.0+ (which should work for non-reporting ATI cards since we don't use mipmaps)
2554  Cmdline_postprocess = 0;
2556 
2557  Scene_color_texture = 0;
2559  Scene_depth_texture = 0;
2560  return;
2561  }
2562 
2563  // clamp size, if needed
2566 
2569  }
2570 
2573  }
2574 
2575  // create framebuffer
2578 
2579  // setup main render texture
2581 
2585 
2591 
2593 
2595 
2596  // setup position render texture
2598 
2602 
2608 
2610 
2612 
2613  // setup normal render texture
2615 
2619 
2625 
2627 
2629 
2630  // setup specular render texture
2632 
2636 
2642 
2644 
2646 
2647  //Set up luminance texture (used as input for FXAA)
2649 
2653 
2659 
2661 
2662  // setup effect texture
2663 
2665 
2669 
2675 
2677 
2679 
2680  // setup cockpit depth texture
2682 
2686 
2693 
2698 
2699  // setup main depth texture
2701 
2705 
2713 
2716 
2717  //setup main stencil buffer
2721  //vglFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, Scene_stencil_buffer);
2722 
2724 
2725  if ( opengl_check_framebuffer() ) {
2728  Scene_framebuffer = 0;
2729 
2731 
2733  Scene_color_texture = 0;
2734 
2737 
2740 
2743 
2746 
2748  Scene_depth_texture = 0;
2749 
2752 
2753  //glDeleteTextures(1, &Scene_fxaa_output_texture);
2754  //Scene_fxaa_output_texture = 0;
2755 
2756  Cmdline_postprocess = 0;
2758  return;
2759  }
2760 
2761  //Setup thruster distortion framebuffer
2764 
2766 
2770 
2776 
2778 
2780 
2786 
2788 
2790 
2791 
2792 
2793  if ( opengl_check_framebuffer() ) {
2797 
2799 
2801  Distortion_texture[0] = 0;
2802  Distortion_texture[1] = 0;
2803  return;
2804  }
2805 
2806  if ( opengl_check_for_errors("post_init_framebuffer()") ) {
2807  Scene_color_texture = 0;
2808  Scene_depth_texture = 0;
2809 
2810  Cmdline_postprocess = 0;
2812  return;
2813  }
2814 
2816 
2819 }
2820 
2822 {
2823  if ( !Scene_texture_initialized ) {
2824  return;
2825  }
2826 
2827  if ( Scene_color_texture ) {
2829  Scene_color_texture = 0;
2830  }
2831 
2832  if ( Scene_position_texture ) {
2835  }
2836 
2837  if ( Scene_normal_texture ) {
2840 
2841  }
2842 
2843  if ( Scene_specular_texture ) {
2846  }
2847 
2848  if ( Scene_effect_texture ) {
2851  }
2852 
2853  if ( Scene_depth_texture ) {
2855  Scene_depth_texture = 0;
2856  }
2857 
2858  if ( Scene_framebuffer ) {
2860  Scene_framebuffer = 0;
2861  }
2862 
2864  Distortion_texture[0] = 0;
2865  Distortion_texture[1] = 0;
2866 
2867  if ( Distortion_framebuffer ) {
2870  }
2871 
2874 }
2875 
2877 {
2878  if ( !Scene_texture_initialized ) {
2879  return;
2880  }
2881 
2883  return;
2884  }
2885 
2887 
2889  {
2892 
2893  CLAMP(Scene_texture_u_scale, 0.0f, 1.0f);
2894  CLAMP(Scene_texture_v_scale, 0.0f, 1.0f);
2895  }
2896  else
2897  {
2898  Scene_texture_u_scale = 1.0f;
2899  Scene_texture_v_scale = 1.0f;
2900  }
2901 
2903  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2905  } else {
2907  vglDrawBuffers(4, buffers);
2908 
2909  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2911 
2913 
2915  }
2916 
2918 }
2919 
2920 float time_buffer = 0.0f;
2922 {
2923  if ( !Scene_framebuffer_in_frame ) {
2924  return;
2925  }
2926 
2928  if(time_buffer>0.03f)
2929  {
2931  time_buffer = 0.0f;
2932  }
2933 
2936  } else {
2938  GLboolean depth_mask = GL_state.DepthMask(GL_FALSE);
2939  GLboolean lighting = GL_state.Lighting(GL_FALSE);
2940  GLboolean blend = GL_state.Blend(GL_FALSE);
2942 
2944 
2948 
2949  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2951  GL_state.Color(255, 255, 255, 255);
2952 
2954 
2956  {
2957  GLfloat vertices[8] = {
2958  0.0f, (float)gr_screen.max_h,
2959  (float)gr_screen.max_w, (float)gr_screen.max_h,
2960  (float)gr_screen.max_w, 0.0f,
2961  0.0f, 0.0f
2962  };
2963 
2964  GLfloat uvcoords[8] = {
2965  Scene_texture_u_scale, 0.0f,
2966  0.0f, 0.0f,
2967  0.0f, Scene_texture_v_scale,
2969  };
2970 
2971  vertex_layout vert_def;
2972 
2973  vert_def.add_vertex_component(vertex_format_data::POSITION2, 0, vertices);
2974  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, 0, uvcoords);
2975 
2976  opengl_bind_vertex_layout(vert_def);
2977 
2978  glDrawArrays(GL_QUADS, 0, 4);
2979  }
2980  else
2981  {
2982  GLfloat vertices[8] = {
2983  0.0f, (float)gr_screen.max_h,
2984  (float)gr_screen.max_w, (float)gr_screen.max_h,
2985  (float)gr_screen.max_w, 0.0f,
2986  0.0f, 0.0f
2987  };
2988 
2989  GLfloat uvcoords[8] = {
2990  0.0f, 0.0f,
2991  Scene_texture_u_scale, 0.0f,
2993  0.0f, Scene_texture_v_scale
2994  };
2995 
2996  vertex_layout vert_def;
2997 
2998  vert_def.add_vertex_component(vertex_format_data::POSITION2, 0, vertices);
2999  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, 0, uvcoords);
3000 
3001  opengl_bind_vertex_layout(vert_def);
3002 
3003  glDrawArrays(GL_QUADS, 0, 4);
3004  }
3005 
3008 
3009  // reset state
3010  GL_state.DepthTest(depth);
3011  GL_state.DepthMask(depth_mask);
3012  GL_state.Lighting(lighting);
3013  GL_state.Blend(blend);
3014  GL_state.CullFace(cull);
3015  }
3016 
3017  // Reset the UV scale values
3018 
3019  Scene_texture_u_scale = 1.0f;
3020  Scene_texture_v_scale = 1.0f;
3021 
3023 }
3024 
3026 {
3027  if ( !Scene_framebuffer_in_frame ) {
3028  return;
3029  }
3030 
3034 }
3035 
3037 {
3039  GLboolean depth_mask = GL_state.DepthMask(GL_FALSE);
3040  GLboolean lighting = GL_state.Lighting(GL_FALSE);
3041  GLboolean blend = GL_state.Blend(GL_FALSE);
3043 
3045 
3046  opengl_draw_textured_quad(-1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f);
3047 
3049 
3050  GL_state.DepthTest(depth);
3051  GL_state.DepthMask(depth_mask);
3052  GL_state.Lighting(lighting);
3053  GL_state.Blend(blend);
3054  GL_state.CullFace(cull);
3055 }
3056 
3058 {
3060  return;
3061 
3062  Deferred_lighting = true;
3063 
3065  vglDrawBuffers(4, buffers);
3066 }
3067 
3069 {
3070  if(!Deferred_lighting)
3071  return;
3072  Deferred_lighting = false;
3074 }
3075 
3076 extern light Lights[MAX_LIGHTS];
3077 extern int Num_lights;
3078 extern float GL_light_color[];
3079 extern float static_point_factor;
3080 extern float static_light_factor;
3081 extern float static_tube_factor;
3082 
3084 {
3085  if ( GLSL_version < 120 || Cmdline_no_deferred_lighting ) {
3086  return;
3087  }
3088 
3091 
3092  //GL_state.DepthFunc(GL_GREATER);
3093  //GL_state.DepthMask(GL_FALSE);
3094 
3096 
3100 
3104 
3108 
3112 
3116 
3117  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
3119 
3120  light lights_copy[MAX_LIGHTS];
3121  memcpy(lights_copy, Lights, MAX_LIGHTS * sizeof(light));
3122 
3123  std::sort(lights_copy, lights_copy+Num_lights, light_compare_by_type);
3124 
3126  glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
3128  glStencilMask(0xFF);
3129 
3130  for(int i = 0; i < Num_lights; ++i)
3131  {
3132  light *l = &lights_copy[i];
3133  GL_state.Uniform.setUniformi( "lightType", 0 );
3134  switch(l->type)
3135  {
3136  case LT_CONE:
3137  GL_state.Uniform.setUniformi( "lightType", 2 );
3138  GL_state.Uniform.setUniformi( "dualCone", l->dual_cone );
3139  GL_state.Uniform.setUniformf( "coneAngle", l->cone_angle );
3140  GL_state.Uniform.setUniformf( "coneInnerAngle", l->cone_inner_angle );
3141  GL_state.Uniform.setUniform3f( "coneDir", l->vec2.xyz.x, l->vec2.xyz.y, l->vec2.xyz.z);
3142  case LT_POINT:
3143  GL_state.Uniform.setUniform3f( "diffuseLightColor", l->r * l->intensity * static_point_factor, l->g * l->intensity * static_point_factor, l->b * l->intensity * static_point_factor );
3145  GL_state.Uniform.setUniformf( "lightRadius", MAX(l->rada, l->radb) * 1.25f );
3146 
3147  /*float dist;
3148  vec3d a;
3149 
3150  vm_vec_sub(&a, &Eye_position, &l->vec);
3151  dist = vm_vec_mag(&a);*/
3152 
3153  gr_opengl_draw_deferred_light_sphere(&l->vec, MAX(l->rada, l->radb) * 1.28f);
3154  break;
3155  case LT_TUBE:
3156  GL_state.Uniform.setUniform3f( "diffuseLightColor", l->r * l->intensity * static_tube_factor, l->g * l->intensity * static_tube_factor, l->b * l->intensity * static_tube_factor );
3158  GL_state.Uniform.setUniformf( "lightRadius", l->radb * 1.5f );
3159  GL_state.Uniform.setUniformi( "lightType", 1 );
3160 
3161  vec3d a, b;
3162  matrix orient;
3163  float length, dist;
3164 
3165  vm_vec_sub(&a, &l->vec, &l->vec2);
3166  vm_vector_2_matrix(&orient, &a, NULL, NULL);
3167  length = vm_vec_mag(&a);
3168  int pos = vm_vec_dist_to_line(&Eye_position, &l->vec, &l->vec2, &b, &dist);
3169  if(pos == -1)
3170  {
3171  vm_vec_sub(&a, &Eye_position, &l->vec);
3172  dist = vm_vec_mag(&a);
3173  }
3174  else if (pos == 1)
3175  {
3176  vm_vec_sub(&a, &Eye_position, &l->vec2);
3177  dist = vm_vec_mag(&a);
3178  }
3179 
3181  gr_opengl_draw_deferred_light_cylinder(&l->vec2, &orient, l->radb * 1.53f, length);
3182  GL_state.Uniform.setUniformi( "lightType", 0 );
3183  gr_opengl_draw_deferred_light_sphere(&l->vec, l->radb * 1.53f, false);
3184  gr_opengl_draw_deferred_light_sphere(&l->vec2, l->radb * 1.53f, false);
3186  break;
3187  }
3188  }
3189 
3193 
3197 
3200 
3202  GLboolean depth_mask = GL_state.DepthMask(GL_FALSE);
3203  GLboolean lighting = GL_state.Lighting(GL_FALSE);
3204  GLboolean blend = GL_state.Blend(GL_FALSE);
3206 
3207  GLfloat vertices[8] = {
3208  0.0f, (float)gr_screen.max_h,
3209  (float)gr_screen.max_w, (float)gr_screen.max_h,
3210  (float)gr_screen.max_w, 0.0f,
3211  0.0f, 0.0f
3212  };
3213 
3214  GLfloat uvcoords[8] = {
3215  0.0f, 0.0f,
3216  Scene_texture_u_scale, 0.0f,
3218  0.0f, Scene_texture_v_scale
3219  };
3220 
3222 
3225 
3226  vertex_layout vert_def;
3227 
3228  vert_def.add_vertex_component(vertex_format_data::POSITION2, 0, vertices);
3229  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, 0, uvcoords);
3230 
3231  opengl_bind_vertex_layout(vert_def);
3232 
3234 
3238 
3240 
3241  glDrawArrays(GL_QUADS, 0, 4);
3242 
3245 
3247 
3248  // reset state
3249  GL_state.DepthTest(depth);
3250  GL_state.DepthMask(depth_mask);
3251  GL_state.Lighting(lighting);
3252  GL_state.Blend(blend);
3253  GL_state.CullFace(cull);
3254 
3256 
3257  gr_clear_states();
3258 }
3259 
3261 {
3263  GLboolean depth_mask = GL_state.DepthMask(GL_FALSE);
3264  GLboolean lighting = GL_state.Lighting(GL_FALSE);
3265  GLboolean blend = GL_state.Blend(GL_FALSE);
3267 
3272 
3273  glViewport(0,0,32,32);
3277  glClearColor(0.5f, 0.5f, 0.0f, 1.0f);
3279  GL_state.Color(255, 255, 255, 255);
3280 
3281  GLfloat texcoord[8] = {
3282  0.0f, 0.0f,
3283  0.96875f, 0.0f,
3284  0.96875f, 1.0f,
3285  0.0f, 1.0f
3286  };
3287 
3288  GLfloat vertices[8] = {
3289  0.03f*(float)gr_screen.max_w,(float)gr_screen.max_h,
3290  (float)gr_screen.max_w, (float)gr_screen.max_h,
3291  (float)gr_screen.max_w, 0.0f,
3292  0.03f*(float)gr_screen.max_w, 0.0f
3293  };
3294 
3296 
3297  vertex_layout vert_def;
3298 
3299  vert_def.add_vertex_component(vertex_format_data::POSITION2, 0, vertices);
3300  vert_def.add_vertex_component(vertex_format_data::TEX_COORD, 0, texcoord);
3301 
3302  opengl_bind_vertex_layout(vert_def);
3303 
3304  glDrawArrays(GL_QUADS, 0, 4);
3305 
3307 
3308  SCP_vector<ubyte> colours;
3309  SCP_vector<GLfloat> distortion_vertex;
3310  colours.reserve(33 * 4);
3311  distortion_vertex.reserve(33 * 2);
3312  for(int i = 0; i < 33; i++)
3313  {
3314  colours.push_back((ubyte) rand()%256);
3315  colours.push_back((ubyte) rand()%256);
3316  colours.push_back(255);
3317  colours.push_back(255);
3318 
3319  distortion_vertex.push_back(0.04f);
3320  distortion_vertex.push_back((float)gr_screen.max_h*0.03125f*i);
3321  }
3322 
3323  vert_def = vertex_layout();
3324 
3325  vert_def.add_vertex_component(vertex_format_data::POSITION2, 0, &distortion_vertex.front());
3326  vert_def.add_vertex_component(vertex_format_data::COLOR4, 0, &colours.front());
3327 
3328  opengl_bind_vertex_layout(vert_def);
3329 
3330  glDrawArrays(GL_POINTS, 0, 33);
3331 
3332  Distortion_switch = !Distortion_switch;
3333 
3334  // reset state
3336 
3338 
3339  GL_state.DepthTest(depth);
3340  GL_state.DepthMask(depth_mask);
3341  GL_state.Lighting(lighting);
3342  GL_state.Blend(blend);
3343  GL_state.CullFace(cull);
3344 }
3345 
3346 void opengl_draw(vertex_layout vertex_binding, GLenum prim_type, int count, int vbuffer_handle)
3347 {
3348 
3349 }
unsigned int GLuint
Definition: Gl.h:52
void gr_opengl_shade(int x, int y, int w, int h, int resize_mode)
void EnableVertexAttrib(GLuint index)
#define TMAP_FLAG_PIXEL_FOG
Definition: tmapper.h:60
#define GL_COLOR_ATTACHMENT1_EXT
Definition: Glext.h:4190
#define gr_zbuffer_set
Definition: 2d.h:817
void opengl_bind_vertex_component(vertex_format_data &vert_component)
bool gr_resize_screen_posf(float *x, float *y, float *w, float *h, int resize_mode)
Definition: 2d.cpp:430
struct screen3d::@234::@236 xyw
bool light_compare_by_type(const light &a, const light &b)
Definition: lighting.cpp:1101
int i
Definition: multi_pxo.cpp:466
#define vm_free(ptr)
Definition: pstypes.h:548
float current_alpha
Definition: 2d.h:400
#define OGL_EXT_FRAMEBUFFER_OBJECT
void gr_opengl_copy_effect_texture()
shader current_shader
Definition: 2d.h:399
#define GL_DEPTH24_STENCIL8_EXT
Definition: Glext.h:4230
void gr_opengl_aaline(vertex *v1, vertex *v2)
#define MIN(a, b)
Definition: pstypes.h:296
float Proj_fov
Definition: 3dsetup.cpp:31
ubyte spec_g
Definition: pstypes.h:176
#define TMAP_FLAG_SOFT_QUAD
Definition: tmapper.h:79
void gr_opengl_draw_deferred_light_cylinder(vec3d *position, matrix *orient, float rad, float length, bool clearStencil=true)
#define GL_ELEMENT_ARRAY_BUFFER_ARB
Definition: Glext.h:1370
WINGDIAPI void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count)
int Neb2_render_mode
Definition: neb.cpp:57
void setUniformf(const SCP_string &name, const float value)
#define TMAP_FLAG_LINES
Definition: tmapper.h:91
GLfloat GLfloat GLfloat GLfloat h
Definition: Glext.h:7280
int offset_y_unscaled
Definition: 2d.h:377
void VertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *pointer)
float v
Definition: pstypes.h:135
#define gr_post_process_end
Definition: 2d.h:917
void setUniformi(const SCP_string &name, const int value)
float vm_vec_mag(const vec3d *v)
Definition: vecmat.cpp:325
#define gr_end_view_matrix
Definition: 2d.h:896
int opengl_check_framebuffer()
#define vglBindFramebufferEXT
float flFrametime
Definition: fredstubs.cpp:22
const GLuint * buffers
Definition: Glext.h:5493
ubyte g
Definition: pstypes.h:175
GLuint index
Definition: Glext.h:5608
#define MAX_LIGHTS
Definition: globals.h:86
void opengl_tmapper_internal3d(int nv, vertex **verts, uint flags)
void opengl_setup_render_states(int &r, int &g, int &b, int &alpha, int &tmap_type, int flags, int is_scaler)
int get_char_width(ubyte c1, ubyte c2, int *width, int *spacing)
Definition: font.cpp:75
opengl_array_state Array
void Color(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha=255)
GLubyte b
void SetTextureSource(gr_texture_source ts)
GLuint Scene_luminance_texture
GLuint deferred_light_sphere_icount
GLuint deferred_light_cylinder_vbo
WINGDIAPI void APIENTRY glMatrixMode(GLenum mode)
WINGDIAPI void APIENTRY glDisable(GLenum cap)
GLfloat w
#define GR_ZBUFF_READ
Definition: 2d.h:674
void gr_opengl_set_2d_matrix()
WINGDIAPI void APIENTRY glClear(GLbitfield mask)
GLfloat x
Assert(pm!=NULL)
double GLdouble
Definition: Gl.h:55
Definition: pstypes.h:88
light Lights[MAX_LIGHTS]
Definition: lighting.cpp:28
#define mprintf(args)
Definition: pstypes.h:238
vertex_format format_type
Definition: 2d.h:1032
WINGDIAPI void APIENTRY glDeleteTextures(GLsizei n, const GLuint *textures)
GLint GLint GLsizei GLsizei GLsizei depth
Definition: Glext.h:5180
GLfloat v
int Cmdline_softparticles
Definition: cmdline.cpp:334
void opengl_draw_textured_quad(GLfloat x1, GLfloat y1, GLfloat u1, GLfloat v1, GLfloat x2, GLfloat y2, GLfloat u2, GLfloat v2)
Definition: gropengldraw.h:93
GLboolean DepthTest(GLint state=-1)
GLuint Cockpit_depth_texture
bool dual_cone
Definition: lighting.h:47
#define GL_TRIANGLES
Definition: Gl.h:109
matrix Eye_matrix
Definition: 3dsetup.cpp:26
void gr_opengl_update_distortion()
#define GL_COLOR_ATTACHMENT4_EXT
Definition: Glext.h:4193
int bm_get_info(int handle, int *w, int *h, ubyte *flags, int *nframes, int *fps)
Gets info on the bitmap indexed by handle.
Definition: bmpman.cpp:769
void opengl_clear_deferred_buffers()
#define GR_ZBUFF_FULL
Definition: 2d.h:675
GLuint opengl_get_rtt_framebuffer()
Gets the current RTT framebuffer.
WINGDIAPI void APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
ubyte r
Definition: 2d.h:84
struct vec3d::@225::@227 xyz
#define TMAP_HTL_3D_UNLIT
Definition: tmapper.h:63
bool Deferred_lighting
GLclampf f
Definition: Glext.h:7097
void SetZbufferType(gr_zbuffer_type zt)
#define GR_ZBUFF_NONE
Definition: 2d.h:672
void BindElementBuffer(GLuint id)
void gr_opengl_aabitmap(int x, int y, int resize_mode, bool mirror)
bool Cmdline_fb_explosions
Definition: cmdline.cpp:340
ubyte spec_b
Definition: pstypes.h:176
#define GL_INT
Definition: Gl.h:195
void setUniform3f(const SCP_string &name, const float x, const float y, const float z)
enum_h * u
Definition: lua.cpp:12649
void gr_opengl_deferred_light_cylinder_init(int segments)
float nr
Definition: lua.cpp:1945
int Scene_texture_height
void gr_opengl_cross_fade(int bmap1, int bmap2, int x1, int y1, int x2, int y2, float pct, int resize_mode)
#define TMAP_FLAG_QUADSTRIP
Definition: tmapper.h:70
ubyte b
Definition: 2d.h:84
opengl_texture_state Texture
ubyte blue
Definition: 2d.h:102
GLboolean CullFace(GLint state=-1)
hull_check orient
Definition: lua.cpp:5049
int Distortion_switch
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
void gr_opengl_sphere_htl(float rad)
bool PostProcessing_override
Definition: systemvars.cpp:78
void gr_opengl_deferred_light_sphere_init(int rings, int segments)
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
GLfloat GLfloat GLfloat v2
Definition: Glext.h:5640
#define Int3()
Definition: pstypes.h:292
int is_alphacolor
Definition: 2d.h:97
#define GL_UNSIGNED_BYTE
Definition: Gl.h:192
WINGDIAPI void APIENTRY glEnable(GLenum cap)
#define TMAP_FLAG_DISTORTION
Definition: tmapper.h:85
#define vglGenRenderbuffersEXT
#define TMAP_FLAG_BW_TEXTURE
Definition: tmapper.h:73
#define GR_RESIZE_NONE
Definition: 2d.h:681
#define GL_TEXTURE_WRAP_S
Definition: Gl.h:944
GLfloat u
uint get_num_vertex_components()
Definition: 2d.h:1048
GLint opengl_shader_get_attribute(const char *attribute_text)
#define gr_end_proj_matrix
Definition: 2d.h:894
#define TMAP_FLAG_NEBULA
Definition: tmapper.h:46
WINGDIAPI void APIENTRY glPopMatrix(void)
ubyte g
Definition: 2d.h:84
#define vglFramebufferRenderbufferEXT
void opengl_draw_primitive(int nv, vertex **verts, uint flags, float u_scale, float v_scale, int r, int g, int b, int a, int override_primary=0)
#define GL_STENCIL_ATTACHMENT
Definition: Glext.h:1614
#define CLAMP(x, min, max)
Definition: pstypes.h:488
GLint GLsizei width
Definition: Gl.h:1505
#define GL_BGRA
Definition: Glext.h:78
ubyte green
Definition: 2d.h:101
ubyte spec_r
Definition: pstypes.h:176
int GL_version
Definition: gropengl.cpp:57
#define vglFramebufferTexture2DEXT
void opengl_draw(vertex_layout vertex_binding, GLenum prim_type, int count, int vbuffer_handle)
float spec_b
Definition: lighting.h:42
void g3_done_instance(bool set_api=false)
Definition: 3dsetup.cpp:341
GLdouble u1
Definition: Glext.h:7779
unsigned char GLubyte
Definition: Gl.h:50
GLuint Distortion_texture[2]
float static_tube_factor
Definition: lighting.cpp:745
uv_pair texture_position
Definition: pstypes.h:174
#define GL_DEPTH_ATTACHMENT_EXT
Definition: Glext.h:4205
GLuint Scene_position_texture
#define gr_set_view_matrix
Definition: 2d.h:895
#define GL_FALSE
Definition: Gl.h:139
void gr_opengl_flash_alpha(int r, int g, int b, int a)
ubyte a
Definition: pstypes.h:175
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
void gr_opengl_line(int x1, int y1, int x2, int y2, int resize_mode)
matrix * vm_vector_2_matrix(matrix *m, const vec3d *fvec, const vec3d *uvec, const vec3d *rvec)
Definition: vecmat.cpp:850
void opengl_tnl_set_material_soft_particle(uint flags)
void opengl_tmapper_internal(int nv, vertex **verts, uint flags, int is_scaler=0)
int Cmdline_nohtl
Definition: cmdline.cpp:438
#define GR_ALPHABLEND_FILTER
Definition: 2d.h:349
GLboolean DepthMask(GLint state=-1)
#define gr_set_proj_matrix
Definition: 2d.h:893
vec3d vec2
Definition: lighting.h:35
int clip_left_unscaled
Definition: 2d.h:390
void opengl_draw_coloured_quad(GLint x1, GLint y1, GLint x2, GLint y2)
Definition: gropengldraw.h:116
float static_light_factor
Definition: lighting.cpp:744
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
#define GL_LINEAR
Definition: Gl.h:931
float time_buffer
void gr_opengl_scene_texture_begin()
float b
Definition: lighting.h:41
#define GL_LINES
Definition: Gl.h:106
unsigned int uint
Definition: pstypes.h:64
screen3d screen
Definition: pstypes.h:173
int offset_x
Definition: 2d.h:376
GLboolean GLboolean g
Definition: Glext.h:5781
void add_vertex_component(vertex_format_data::vertex_format format_type, uint stride, void *src)
Definition: 2d.h:1054
#define GL_RGBA8
Definition: Gl.h:1007
#define vglBindRenderbufferEXT
#define TMAP_FLAG_GOURAUD
Definition: tmapper.h:40
#define GL_DEPTH_ATTACHMENT
Definition: Glext.h:1613
#define vglBlitFramebufferEXT
#define GL_RENDERBUFFER
Definition: Glext.h:1616
int clip_top_unscaled
Definition: 2d.h:390
void gr_opengl_deferred_lighting_finish()
#define vglDeleteBuffersARB
int clip_right_unscaled
Definition: 2d.h:390
void gr_opengl_deferred_lighting_end()
int Num_lights
Definition: lighting.cpp:29
float clip_aspect
Definition: 2d.h:372
float g
Definition: lighting.h:41
GLboolean GLboolean GLboolean GLboolean a
Definition: Glext.h:5781
int Scene_texture_initialized
int offset_x_unscaled
Definition: 2d.h:377
font * Current_font
Definition: font.cpp:36
#define GL_REPEAT
Definition: Gl.h:957
bool GL_rendering_to_texture
int * bm_v
Definition: font.h:57
int GLOWMAP
References a map that is a fully lit version of its index -Bobboau.
Definition: bmpman.cpp:57
#define NEBULA_COLORS
Definition: grinternal.h:57
#define GL_FRAMEBUFFER_EXT
Definition: Glext.h:4207
void opengl_aabitmap_ex_internal(int x, int y, int w, int h, int sx, int sy, int resize_mode, bool mirror)
#define TCACHE_TYPE_INTERFACE
Definition: grinternal.h:53
WINGDIAPI void APIENTRY glGenTextures(GLsizei n, GLuint *textures)
#define GL_DEPTH_COMPONENT24
Definition: Glext.h:291
float Max_draw_distance
Definition: 2d.cpp:85
GLfloat v0
Definition: Glext.h:5638
int vm_vec_dist_to_line(const vec3d *p, const vec3d *l0, const vec3d *l1, vec3d *nearest, float *dist)
Definition: vecmat.cpp:2503
float rada
Definition: lighting.h:39
#define w(p)
Definition: modelsinc.h:68
float spec_r
Definition: lighting.h:42
int Cmdline_glow
Definition: cmdline.cpp:326
void SetAlphaBlendMode(gr_alpha_blend ab)
void gr_opengl_unfilled_circle(int xc, int yc, int d, int resize_mode)
GLfloat v
#define vglBindBufferARB
ubyte red
Definition: 2d.h:100
void gr_opengl_pixel(int x, int y, int resize_mode)
vertex_format_data * get_vertex_component(uint index)
Definition: 2d.h:1050
GLuint Scene_framebuffer
#define LT_TUBE
Definition: lighting.h:27
void VertexPointer(GLint size, GLenum type, GLsizei stride, GLvoid *pointer)
#define vglDrawRangeElements
#define GL_NONE
Definition: Gl.h:214
WINGDIAPI void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
GLdouble s
Definition: Glext.h:5321
float u
Definition: pstypes.h:135
float cone_angle
Definition: lighting.h:45
gr_zbuffer_type
Definition: grinternal.h:75
GLuint Scene_specular_texture
#define GL_INCR
Definition: Gl.h:884
#define NEB2_RENDER_POF
Definition: neb.h:33
void gr_opengl_string(float sx, float sy, const char *s, int resize_mode)
#define GL_TEXTURE_WRAP_R
Definition: Glext.h:68
GLfloat u
#define GL_CHECK_FOR_ERRORS(s)
Definition: gropengl.h:661
void gr_opengl_circle(int xc, int yc, int d, int resize_mode)
int clip_bottom
Definition: 2d.h:388
GLuint deferred_light_cylinder_icount
GLuint Scene_color_texture
void TexPointer(GLint size, GLenum type, GLsizei stride, GLvoid *pointer)
#define GL_TEXTURE_MAG_FILTER
Definition: Gl.h:942
GLdouble GLdouble t
Definition: Glext.h:5329
opengl_uniform_state Uniform
ubyte c
Definition: 2d.h:84
void gr_opengl_end_2d_matrix()
#define Is_Extension_Enabled(x)
void SetTarget(GLenum tex_target)
WINGDIAPI void APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
int clip_top
Definition: 2d.h:388
#define GL_COLOR_ATTACHMENT3_EXT
Definition: Glext.h:4192
#define GL_LINE_WIDTH
Definition: Gl.h:382
GLuint Distortion_framebuffer
int Cmdline_no_deferred_lighting
Definition: cmdline.cpp:345
GLint GLint GLint GLint GLint x
Definition: Glext.h:5182
ubyte alpha
Definition: 2d.h:103
unsigned char ubyte
Definition: pstypes.h:62
GLfloat y
GLuint deferred_light_cylinder_ibo
#define GL_TRIANGLE_FAN
Definition: Gl.h:111
void Enable(GLuint tex_id=0)
#define GL_ZERO
Definition: Gl.h:117
int GLSL_version
Definition: gropengl.cpp:58
int h
Definition: font.h:43
WINGDIAPI void APIENTRY glDrawBuffer(GLenum mode)
#define GL_FRAMEBUFFER
Definition: Glext.h:1615
#define GL_MODELVIEW
Definition: Gl.h:751
void gr_opengl_aabitmap_ex(int x, int y, int w, int h, int sx, int sy, int resize_mode, bool mirror)
void NormalPointer(GLenum type, GLsizei stride, GLvoid *pointer)
#define GL_CLAMP_TO_EDGE
Definition: Glext.h:81
void InvalidateColor()
GLuint deferred_light_sphere_ibo
WINGDIAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
int max_w
Definition: 2d.h:360
#define TMAP_FLAG_RGB
Definition: tmapper.h:39
int Scene_texture_width
void opengl_tnl_set_material_distortion(uint flags)
void gr_opengl_flash(int r, int g, int b)
GLuint start
Definition: Gl.h:1502
GLboolean Blend(GLint state=-1)
int get_centered_x(const char *s, bool scaled)
Definition: font.cpp:114
ubyte b
Definition: pstypes.h:175
GLfloat GLfloat v1
Definition: Glext.h:5639
#define TMAP_FLAG_CORRECT
Definition: tmapper.h:37
void ColorPointer(GLint size, GLenum type, GLsizei stride, GLvoid *pointer)
#define FIND_SCALED_NUM(x, x0, x1, y0, y1)
#define GL_DEPTH_TEXTURE_MODE
Definition: Glext.h:325
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition: Glext.h:75
GLbitfield flags
Definition: Glext.h:6722
#define GL_STATIC_DRAW_ARB
Definition: Glext.h:1392
unsigned char GLboolean
Definition: Gl.h:44
#define vm_malloc(size)
Definition: pstypes.h:547
int type
Definition: lighting.h:33
void gr_opengl_render_effect(int nverts, vertex *verts, float *radius_list, uint flags)
Definition: lighting.h:32
ubyte gr_palette[256 *3]
Definition: palman.cpp:27
void BindArrayBuffer(GLuint id)
__inline void gr_line(int x1, int y1, int x2, int y2, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:791
#define LT_POINT
Definition: lighting.h:26
GLuint deferred_light_sphere_vbo
int offset_y
Definition: 2d.h:376
bool Scene_framebuffer_in_frame
void vm_vec_sub(vec3d *dest, const vec3d *src0, const vec3d *src1)
Definition: vecmat.cpp:168
GLuint Scene_normal_texture
GLfloat Scene_texture_u_scale
void gr_opengl_tmapper(int nverts, vertex **verts, uint flags)
vec3d Eye_position
Definition: 3dsetup.cpp:27
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
#define GL_TEXTURE_2D
Definition: Gl.h:570
float GL_light_color[]
__inline void gr_fog_set(int fog_mode, int r, int g, int b, float fog_near=-1.0f, float fog_far=-1.0f)
Definition: 2d.h:833
#define vglDrawBuffers
bool gr_resize_screen_pos(int *x, int *y, int *w, int *h, int resize_mode)
Definition: 2d.cpp:212
#define LT_CONE
Definition: lighting.h:28
void opengl_set_additive_tex_env()
void opengl_setup_scene_textures()
int clip_right
Definition: 2d.h:388
#define TMAP_FLAG_TRILIST
Definition: tmapper.h:68
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()
WINGDIAPI void APIENTRY glStencilMask(GLuint mask)
#define GL_TEXTURE_WRAP_T
Definition: Gl.h:945
GLuint GLuint num
Definition: Glext.h:9089
float spec_g
Definition: lighting.h:42
void gr_opengl_deferred_lighting_begin()
WINGDIAPI void APIENTRY glGetFloatv(GLenum pname, GLfloat *params)
#define GL_ARRAY_BUFFER_ARB
Definition: Glext.h:1369
GLubyte g
int gr_opengl_maybe_create_shader(shader_type shader_t, unsigned int flags)
opengl_state GL_state
#define GL_NOTEQUAL
Definition: Gl.h:77
GLuint Scene_stencil_buffer
GLushort deferred_light_sphere_vcount
GLubyte GLubyte GLubyte GLubyte w
Definition: Glext.h:5679
#define GL_COLOR_ATTACHMENT0
Definition: Glext.h:1597
#define FL_CLIPLINE(x1, y1, x2, y2, XMIN, YMIN, XMAX, YMAX, WHEN_OUTSIDE, WHEN_CLIPPED, WHEN_SWAPPED)
Definition: line.h:103
float static_point_factor
Definition: lighting.cpp:746
#define vglGenFramebuffersEXT
#define GL_TEXTURE_COMPARE_MODE
Definition: Glext.h:299
WINGDIAPI void APIENTRY glPushMatrix(void)
int clip_bottom_unscaled
Definition: 2d.h:390
#define fl2i(fl)
Definition: floating.h:33
GLfloat Scene_texture_v_scale
#define vglRenderbufferStorageEXT
opengl_vertex_bind::type binding_type
#define vglDeleteFramebuffersEXT
int gr_zbuffering
Definition: 2d.cpp:71
#define GL_TEXTURE_MIN_FILTER
Definition: Gl.h:943
screen gr_screen
Definition: 2d.cpp:46
float Min_draw_distance
Definition: 2d.cpp:84
void gr_opengl_line_htl(const vec3d *start, const vec3d *end)
unsigned short ushort
Definition: pstypes.h:63
bool custom_size
Definition: 2d.h:402
GLfloat x
GLushort deferred_light_cylinder_vcount
#define gr_clear_states
Definition: 2d.h:946
int bitmap_id
Definition: font.h:53
unsigned short GLushort
Definition: Gl.h:51
void gr_opengl_scaler(vertex *va, vertex *vb, bool bw_bitmap=false)
GLuint Scene_depth_texture
GLuint Scene_effect_texture
GLfloat y
GLfloat GLfloat p
Definition: Glext.h:8373
#define OGL_ARB_TEXTURE_NON_POWER_OF_TWO
#define TMAP_FLAG_ALPHA
Definition: tmapper.h:53
GLfloat z
int max_h
Definition: 2d.h:360
vec3d vec
Definition: lighting.h:34
void g3_start_instance_matrix(const vec3d *pos, const matrix *orient, bool set_api=true)
Definition: 3dsetup.cpp:249
#define TMAP_FLAG_TEXTURED
Definition: tmapper.h:36
float radb
Definition: lighting.h:40
GLint GL_max_renderbuffer_size
color current_color
Definition: 2d.h:396
#define PI
Definition: pstypes.h:303
void neb2_get_pixel(int x, int y, int *r, int *g, int *b)
Definition: neb.cpp:1292
#define GL_STENCIL_TEST
Definition: Gl.h:420
void opengl_scene_texture_shutdown()
hull_check pos
Definition: lua.cpp:5050
#define GL_TEXTURE
Definition: Gl.h:753
#define GR_FOGMODE_FOG
Definition: 2d.h:356
#define vglBufferDataARB
GLenum GLuint GLenum GLsizei length
Definition: Glext.h:5156
#define TMAP_FLAG_TRISTRIP
Definition: tmapper.h:67
#define i2fl(i)
Definition: floating.h:32
int * bm_u
Definition: font.h:56
void opengl_render_internal3d(int nverts, vertex *verts, uint flags)
#define GL_POINTS
Definition: Gl.h:105
GLint GLsizei count
Definition: Gl.h:1491
void SetActiveClientUnit(GLuint id)
unsigned int GLenum
Definition: Gl.h:43
void gr_bitmap(int _x, int _y, int resize_mode)
Definition: 2d.cpp:1303
WINGDIAPI void APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)
#define GR_BITBLT_MODE_NORMAL
Definition: 2d.h:351
int gr_opengl_tcache_set(int bitmap_handle, int bitmap_type, float *u_scale, float *v_scale, int stage)
int Cmdline_no_fbo
Definition: cmdline.cpp:442
float intensity
Definition: lighting.h:38
WINGDIAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
#define GL_INTENSITY
Definition: Gl.h:992
#define TMAP_FLAG_RAMP
Definition: tmapper.h:38
void opengl_bitmap_ex_internal(int x, int y, int w, int h, int sx, int sy, int resize_mode)
#define GL_DEPTH_COMPONENT
Definition: Gl.h:779
vec3d world
Definition: pstypes.h:172
int temp
Definition: lua.cpp:4996
GLubyte r
bool is_minimum_GLSL_version()
Definition: gropengl.cpp:2064
float cone_inner_angle
Definition: lighting.h:46
#define vglGenBuffersARB
int Cmdline_postprocess
Definition: cmdline.cpp:335
#define GL_UNSIGNED_SHORT
Definition: Gl.h:194
#define GL_QUADS
Definition: Gl.h:112
#define MAX(a, b)
Definition: pstypes.h:299
int clip_left
Definition: 2d.h:388
SCP_string attrib_name
#define GL_KEEP
Definition: Gl.h:882
#define TMAP_FLAG_DISTORTION_THRUSTER
Definition: tmapper.h:82
void opengl_shader_set_current(opengl_shader_t *shader_obj)
#define GL_REPLACE
Definition: Gl.h:883
#define GL_NEAREST
Definition: Gl.h:930
WINGDIAPI void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
void gr_opengl_arc(int xc, int yc, float r, float angle_start, float angle_end, bool fill, int resize_mode)
GLclampf GLclampf GLclampf alpha
Definition: Glext.h:5177
float r
Definition: lighting.h:41
#define TMAP_FLAG_QUADLIST
Definition: tmapper.h:69
GLubyte a
int rendering_to_texture
Definition: 2d.h:403
#define INT_CLIPLINE(x1, y1, x2, y2, XMIN, YMIN, XMAX, YMAX, WHEN_OUTSIDE, WHEN_CLIPPED, WHEN_SWAPPED)
Definition: line.h:28
#define GL_COLOR_BUFFER_BIT
Definition: Gl.h:96
void gr_opengl_gradient(int x1, int y1, int x2, int y2, int resize_mode)
#define GL_COLOR_ATTACHMENT2_EXT
Definition: Glext.h:4191
#define MAX_VERTS_PER_DRAW
vertex_format_data::vertex_format format
void * data_src
Definition: 2d.h:1034
WINGDIAPI GLenum APIENTRY glGetError(void)
void opengl_bind_vertex_layout(vertex_layout &layout)
void opengl_render_internal(int nverts, vertex *verts, uint flags)
#define GL_FLOAT
Definition: Gl.h:197
const GLdouble * v
Definition: Glext.h:5322
matrix vmd_identity_matrix
Definition: vecmat.cpp:28
void gr_opengl_scene_texture_end()
#define GL_STENCIL_BUFFER_BIT
Definition: Gl.h:92
void gr_opengl_draw_deferred_light_sphere(vec3d *position, float rad, bool clearStencil=true)
void SetActiveUnit(GLuint id=0)
#define GL_COLOR_ATTACHMENT0_EXT
Definition: Glext.h:4189
const GLubyte * c
Definition: Glext.h:8376
#define GL_RGBA16F_ARB
Definition: Glext.h:1530
bool Use_Shaders_for_effect_rendering
int opengl_check_for_errors(char *err_at)
Definition: gropengl.cpp:1252
GLuint GLuint end
Definition: Gl.h:1502
ubyte r
Definition: pstypes.h:175
void gr_opengl_draw_line_list(const colored_vector *lines, int num)
#define GL_QUAD_STRIP
Definition: Gl.h:113
WINGDIAPI void APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask)
GLint y
Definition: Gl.h:1505
void gr_opengl_curve(int xc, int yc, int r, int direction, int resize_mode)
Definition: 2d.h:358
#define GL_DEPTH_BUFFER_BIT
Definition: Gl.h:90
int GLint
Definition: Gl.h:48
#define fl_radians(fl)
Definition: floating.h:42
WINGDIAPI void APIENTRY glReadBuffer(GLenum mode)
int current_bitmap
Definition: 2d.h:395
#define TCACHE_TYPE_AABITMAP
Definition: grinternal.h:50
float GLfloat
Definition: Gl.h:53
GLboolean Lighting(GLint state=-1)
#define GL_TRIANGLE_STRIP
Definition: Gl.h:110
void gr_opengl_bitmap_ex(int x, int y, int w, int h, int sx, int sy, int resize_mode)
void gr_opengl_render(int nverts, vertex *verts, uint flags)