23 static vertex **Vbuf0 = NULL;
24 static vertex **Vbuf1 = NULL;
25 static int Num_vbufs_allocated = 0;
28 static void g3_deallocate_vbufs()
41 static void g3_allocate_vbufs(
int nv)
43 static ubyte dealloc = 0;
46 Assert( nv || Num_vbufs_allocated );
49 atexit(g3_deallocate_vbufs);
53 if (nv > Num_vbufs_allocated) {
54 g3_deallocate_vbufs();
59 Num_vbufs_allocated = nv;
79 codes_or = (
unsigned char)(p0->
codes | p1->
codes);
114 #ifdef FRED_OGL_COMMENT_OUT_FOR_NOW
129 codes_or = (
unsigned char)(p0->
codes | p1->
codes);
182 vm_vec_perp(&tempv,&vertlist[0]->world,&vertlist[1]->world,&vertlist[2]->world);
184 return (
vm_vec_dot(&tempv,&vertlist[1]->world ) < 0.0);
225 bool starting =
true;
243 g3_allocate_vbufs(nv);
253 p = bufptr[
i] = pointlist[
i];
313 if(width == 0 || height == 0)
321 const int NUM_VERTICES = 4;
325 memset(v, 0,
sizeof(v));
339 for(
int i = 0;
i < NUM_VERTICES;
i++)
401 g3_allocate_vbufs(nv);
410 p = bufptr[
i] = pointlist[
i];
423 bufptr =
clip_polygon(Vbuf0, Vbuf1, &nv, &cc, tmap_flags);
528 vec3d fvec, rvec, uvec;
538 vertex *ptlist[4] = { &P[3], &P[2], &P[1], &P[0] };
594 vertex *ptlist[4] = { &P[3], &P[2], &P[1], &P[0] };
598 p[1].
xyz.x = -rad * aspect; p[1].
xyz.y = rad; p[1].
xyz.z = -
depth;
599 p[2].
xyz.x = -rad * aspect; p[2].
xyz.y = -rad; p[2].
xyz.z = -
depth;
600 p[3].
xyz.x = rad * aspect; p[3].
xyz.y = -rad; p[3].
xyz.z = -
depth;
602 for(i = 0; i<4; i++){
614 for( i = 0; i<4; i++){
637 for(
int i = 0;
i <resolution;
i++){
658 bool bw_bitmap =
false;
672 }
else if ( bw > bh ) {
676 width = height = rad*2.0f;
679 width = height = rad*2.0f;
752 }
else if ( bw > bh ) {
756 width = height = rad*2.0f;
795 else if ( angle >
PI2 )
801 vec3d fvec, rvec, uvec;
812 vertex *ptlist[4] = { &P[3], &P[2], &P[1], &P[0] };
850 vertex *vertlist[4] = { &v[3], &v[2], &v[1], &v[0] };
854 memset(v,0,
sizeof(
vertex)*4);
861 else if ( angle >
PI2 )
877 }
else if ( bw > bh ) {
881 width = height = rad;
884 width = height = rad;
915 ubyte codes_and=0xff;
919 if ( z < 0.0
f ) z = 0.0f;
922 for (i=0; i<4; i++ ) {
938 #define TRIANGLE_AREA(_p, _q, _r) do {\
941 a.xyz.x = _q->world.xyz.x - _p->world.xyz.x;\
942 a.xyz.y = _q->world.xyz.y - _p->world.xyz.y;\
945 b.xyz.x = _r->world.xyz.x - _p->world.xyz.x;\
946 b.xyz.y = _r->world.xyz.y - _p->world.xyz.y;\
949 vm_vec_cross(&cross, &a, &b);\
950 total_area += vm_vec_mag(&cross) * 0.5f;\
956 float total_area = 0.0f;
959 for(idx=1; idx<nv-1; idx++){
960 TRIANGLE_AREA(pointlist[0], pointlist[idx], pointlist[idx+1]);
980 g3_allocate_vbufs(nv);
990 p = bufptr[
i] = pointlist[
i];
1003 bufptr =
clip_polygon(Vbuf0, Vbuf1, &nv, &cc, tmap_flags);
1007 for (i=0;i<nv;i++) {
1040 for (i=0;i<nv;i++) {
1072 vertex *vertlist[4] = { &v[3], &v[2], &v[1], &v[0] };
1076 memset(v,0,
sizeof(
vertex)*4);
1081 if ( angle < 0.0
f ){
1083 }
else if ( angle >
PI2 ) {
1100 }
else if ( bw > bh ) {
1104 width = height = rad;
1107 width = height = rad;
1138 ubyte codes_and=0xff;
1142 if ( z < 0.0
f ) z = 0.0f;
1145 for (i=0; i<4; i++ ) {
1174 float up_right, down_right,down_left,up_left;
1184 up_right = horizon_vec.
xyz.x + horizon_vec.
xyz.y + horizon_vec.
xyz.z;
1185 down_right = horizon_vec.
xyz.x - horizon_vec.
xyz.y + horizon_vec.
xyz.z;
1186 down_left = -horizon_vec.
xyz.x - horizon_vec.
xyz.y + horizon_vec.
xyz.z;
1187 up_left = -horizon_vec.
xyz.x + horizon_vec.
xyz.y + horizon_vec.
xyz.z;
1190 if ( (up_right<0.0
f)&&(down_right<0.0
f)&&(down_left<0.0
f)&&(up_left<0.0
f) ) {
1194 if ( (up_right>0.0
f)&&(down_right>0.0
f)&&(down_left>0.0
f)&&(up_left>0.0
f) ) {
1202 s1 = up_left > 0.0f;
1203 s2 = down_left > 0.0f;
1205 horz_pts[cpnt].
x = 0.0f;
1207 horz_pts[cpnt].
edge = 0;
1212 s1 = up_left > 0.0f;
1213 s2 = up_right > 0.0f;
1216 horz_pts[cpnt].
y = 0.0f;
1217 horz_pts[cpnt].
edge = 1;
1222 s1 = up_right > 0.0f;
1223 s2 = down_right > 0.0f;
1227 horz_pts[cpnt].
edge = 2;
1232 s1 = down_right > 0.0f;
1233 s2 = down_left > 0.0f;
1237 horz_pts[cpnt].
edge = 3;
1242 mprintf((
"HORZ: Wrong number of points (%d)\n", cpnt ));
1247 if ( horz_pts[0].
x > horz_pts[1].
x ) {
1250 horz_pts[0] = horz_pts[1];
1264 vec3d uvec, fvec, rvec, center;
1287 vertex *ptlist[4] = { &pts[3], &pts[2], &pts[1], &pts[0] };
1294 for (i=0; i<4; i++ ) {
1334 #define MAX_ROD_VECS 100
1337 vec3d uvec, fvec, rvec;
1343 Assert( num_points >= 2 );
1346 for (i = 0; i < num_points; i++) {
1356 }
else if (i == num_points-1) {
1360 vm_vec_sub(&rvec, &pvecs[first], &pvecs[second]);
1373 ptlist[nv] = &pts[nv];
1374 ptlist[nv+1] = &pts[nv+1];
1402 Assert( (nv >= 4) && !(nv % 2) );
1411 { { { -1.0f, -1.0f, 20.0f } } },
1412 { { { -1.0f, 1.0f, 20.0f } } },
1413 { { { 1.0f, 1.0f, 20.0f } } },
1414 { { { 1.0f, -1.0f, 20.0f } } }
1417 #define MAX_PERSPECTIVE_DIVISIONS 5 // should never even come close to this limit
1422 float b =
PI2 * theta;
1423 float sin_a = sinf(a);
1426 pnt->
xyz.z = rho * sin_a * cosf(b);
1427 pnt->
xyz.y = rho * sin_a * sinf(b);
1428 pnt->
xyz.x = rho * cosf(a);
1442 int saved_zbuffer_mode;
1452 ui = 1.0f / (
float)div_x;
1453 vi = 1.0f / (
float)div_y;
1458 float s_phi = 0.5f + (((p_phi * scale_x) / 360.0
f) / 2.0f);
1459 float s_theta = (((p_theta * scale_y) / 360.0
f) / 2.0f);
1460 float d_phi = -(((p_phi * scale_x) / 360.0
f) / (
float)(div_x));
1461 float d_theta = -(((p_theta * scale_y) / 360.0
f) / (
float)(div_y));
1464 bank_first.
p = 0.0f;
1465 bank_first.
b = a->
b;
1466 bank_first.
h = 0.0f;
1475 for(idx=0; idx<=div_x; idx++){
1476 for(s_idx=0; s_idx<=div_y; s_idx++){
1481 vm_vec_rotate(&t_points[idx][s_idx], &s_points[idx][s_idx], &m_bank);
1484 vm_vec_rotate(&s_points[idx][s_idx], &t_points[idx][s_idx], &m);
1496 for(idx=0; idx<div_x; idx++){
1497 for(s_idx=0; s_idx<div_y; s_idx++){
1555 vertex *verts[6] = {&v[0], &v[1], &v[2], &v[3], &v[4], &v[5]};
1557 memset(v,0,
sizeof(
vertex)*6);
1655 vertex *verts[4] = {&v[0], &v[1], &v[2], &v[3]};
1657 memset(v,0,
sizeof(
vertex)*4);
1731 int saved_zbuffer_mode;
1733 vertex *vertlist[4] = { &v[0], &v[1], &v[2], &v[3] };
1734 memset(v,0,
sizeof(
vertex)*4);
1797 int saved_zbuffer_mode;
1798 if(n_bm>bitmap_2d_poly_list_size){
1801 bitmap_2d_poly_list =
new vertex[6* n_bm];
1802 bitmap_2d_poly_vertlist =
new vertex*[6*n_bm];
1803 for(
int i = 0;
i<6*n_bm;
i++)bitmap_2d_poly_vertlist[
i] = &bitmap_2d_poly_list[
i];
1804 memset(bitmap_2d_poly_list,0,
sizeof(
vertex)*6*n_bm);
1813 for(
int i = 0;
i<n_bm;
i++){
1817 vertex *V = &bitmap_2d_poly_list[
i*6];
1888 int saved_zbuffer_mode;
1889 if(n_bm>bitmap_2d_poly_list_size){
1892 bitmap_2d_poly_list =
new vertex[6* n_bm];
1893 bitmap_2d_poly_vertlist =
new vertex*[6*n_bm];
1894 for(
int i = 0;
i<6*n_bm;
i++)bitmap_2d_poly_vertlist[
i] = &bitmap_2d_poly_list[
i];
1903 for(
int i = 0;
i<n_bm;
i++){
1909 vertex *V = &bitmap_2d_poly_list[
i*6];
2000 void flash_ball::initialize(
int number,
float min_ray_width,
float max_ray_width,
const vec3d* dir,
const vec3d* pcenter,
float outer,
float inner,
ubyte max_r,
ubyte max_g,
ubyte max_b,
ubyte min_r,
ubyte min_g,
ubyte min_b)
2007 if(n_rays < number){
2014 for(i = 0; i<n_rays; i++){
2017 ray[
i].
start.
r = (rand()%(max_r-min_r))+min_r;
2022 ray[
i].
start.
g = (rand()%(max_g-min_g))+min_g;
2027 ray[
i].
start.
b = (rand()%(max_b-min_b))+min_b;
2052 if(max_ray_width == 0.0
f)ray[
i].
width=min_ray_width;
2059 #define uw(p) (*((uint *) (p)))
2060 #define w(p) (*((int *) (p)))
2061 #define wp(p) ((int *) (p))
2062 #define vp(p) ((vec3d *) (p))
2063 #define fl(p) (*((float *) (p)))
2065 void flash_ball::defpoint(
int off,
ubyte *bsp_data)
2068 int nverts =
w(off+bsp_data+8);
2069 int offset =
w(off+bsp_data+16);
2070 ubyte * normcount = off+bsp_data+20;
2073 if(n_rays < nverts){
2081 for (n=0; n<nverts; n++ ) {
2096 #define OP_DEFPOINTS 1
2097 #define OP_FLATPOLY 2
2098 #define OP_TMAPPOLY 3
2099 #define OP_SORTNORM 4
2100 #define OP_BOUNDBOX 5
2103 void flash_ball::parse_bsp(
int offset,
ubyte *bsp_data){
2106 memcpy(&ID, &bsp_data[offset],
sizeof(
int));
2107 memcpy(&SIZE, &bsp_data[offset+
sizeof(
int)],
sizeof(
int));
2128 memcpy(&ID, &bsp_data[offset],
sizeof(
int));
2129 memcpy(&SIZE, &bsp_data[offset+
sizeof(
int)],
sizeof(
int));
2136 void flash_ball::initialize(
ubyte *bsp_data,
float min_ray_width,
float max_ray_width,
const vec3d* dir,
const vec3d* pcenter,
float outer,
float inner,
ubyte max_r,
ubyte max_g,
ubyte max_b,
ubyte min_r,
ubyte min_g,
ubyte min_b)
2140 parse_bsp(0,bsp_data);
2144 for(i = 0; i<n_rays; i++){
2147 ray[
i].
start.
r = (rand()%(max_r-min_r))+min_r;
2152 ray[
i].
start.
g = (rand()%(max_g-min_g))+min_g;
2157 ray[
i].
start.
b = (rand()%(max_b-min_b))+min_b;
2178 if(max_ray_width == 0.0
f)ray[
i].
width=min_ray_width;
2187 flash_ball::batcher.
allocate(n_rays);
2188 for(
int i = 0;
i<n_rays;
i++){
2193 flash_ball::batcher.
draw_beam(¢er, &end, ray[i].
width*rad, intinsity);
2199 flash_ball::batcher.
allocate(n_rays);
2200 for(
int i = 0;
i<n_rays;
i++){
int g3_draw_rotated_bitmap_3d(vertex *pnt, float angle, float rad, uint tmap_flags, float depth)
int g3_draw_sphere_ez(const vec3d *pnt, float rad)
void initialize(int number, float min_ray_width, float max_ray_width=0, const vec3d *dir=&vmd_zero_vector, const vec3d *pcenter=&vmd_zero_vector, float outer=PI2, float inner=0.0f, ubyte max_r=255, ubyte max_g=255, ubyte max_b=255, ubyte min_r=255, ubyte min_g=255, ubyte min_b=255)
struct screen3d::@234::@236 xyw
void render(float rad, float intinsity, float life)
#define TMAP_FLAG_XPARENT
int g3_draw_poly_if_facing(int nv, vertex **pointlist, uint tmap_flags, const vec3d *norm, const vec3d *pnt)
float g3_draw_rotated_bitmap_area(vertex *pnt, float angle, float rad, uint tmap_flags, float area)
GLfloat GLfloat GLfloat GLfloat h
void vm_vec_scale_add(vec3d *dest, const vec3d *src1, const vec3d *src2, float k)
float frand_range(float min, float max)
Return a floating point number in the range min..max.
int batch_add_beam(int texture, int tmap_flags, vec3d *start, vec3d *end, float width, float intensity)
int g3_draw_polygon(const vec3d *pos, const matrix *ori, float width, float height, int tmap_flags)
int g3_check_normal_facing(const vec3d *v, const vec3d *norm)
matrix * vm_angles_2_matrix(matrix *m, const angles *a)
float g3_get_poly_area(int nv, vertex **pointlist)
__inline void gr_circle(int xc, int yc, int d, int resize_mode=GR_RESIZE_FULL)
int g3_get_bitmap_dims(int bitmap, vertex *pnt, float rad, int *x, int *y, int *w, int *h, int *size)
ubyte g3_transfer_vertex(vertex *dest, const vec3d *src)
void g3_draw_2d_rect(int x, int y, int w, int h, int r, int g, int b, int a)
void _cdecl void void _cdecl void _cdecl Warning(char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
bitmap_2d_list screen_rect
GLint GLint GLsizei GLsizei GLsizei depth
int g3_draw_bitmap_3d_volume(vertex *pnt, int orient, float rad, uint tmap_flags, float depth, int resolution)
int g3_draw_bitmap_3d(vertex *pnt, int orient, float rad, uint tmap_flags, float depth)
int bm_get_info(int handle, int *w, int *h, ubyte *flags, int *nframes, int *fps)
Gets info on the bitmap indexed by handle.
struct vec3d::@225::@227 xyz
#define TMAP_HTL_3D_UNLIT
void free_temp_point(vertex *p)
vec3d * vm_vec_rotate(vec3d *dest, const vec3d *src, const matrix *m)
vertex * bitmap_2d_poly_list
ubyte g3_code_vertex(vertex *point)
void vm_vec_random_cone(vec3d *out, const vec3d *in, float max_angle, const matrix *orient)
int g3_draw_rotated_bitmap(vertex *pnt, float angle, float rad, uint tmap_flags, float depth)
int g3_draw_2d_poly_bitmap_rect_list(bitmap_rect_list *b_list, int n_bm, uint additional_tmap_flags)
int g3_draw_2d_poly_bitmap(float x, float y, float w, float h, uint additional_tmap_flags)
#define MAX_PERSPECTIVE_DIVISIONS
#define TMAP_FLAG_BW_TEXTURE
int g3_draw_2d_poly_bitmap_list(bitmap_2d_list *b_list, int n_bm, uint additional_tmap_flags)
vertex * free_points[TMAP_MAX_VERTS]
int g3_draw_bitmap_3d_v(vertex *pnt, int orient, float rad, uint tmap_flags, float depth, float c)
void g3_done_instance(bool set_api=false)
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
matrix * vm_vector_2_matrix(matrix *m, const vec3d *fvec, const vec3d *uvec, const vec3d *rvec)
void vm_vec_add2(vec3d *dest, const vec3d *src)
GLdouble GLdouble GLdouble r
struct matrix::@228::@230 vec
void vm_vec_scale(vec3d *dest, float s)
#define TMAP_FLAG_GOURAUD
int g3_draw_line(vertex *p0, vertex *p1)
GLboolean GLboolean GLboolean GLboolean a
int g3_draw_bitmap(vertex *pnt, int orient, float rad, uint tmap_flags, float depth)
void vm_vec_sub2(vec3d *dest, const vec3d *src)
int must_clip_line(vertex *p0, vertex *p1, ubyte codes_or, uint flags)
void vm_rot_point_around_line(vec3d *out, const vec3d *in, float angle, const vec3d *line_point, const vec3d *line_dir)
float g3_draw_poly_constant_sw_area(int nv, vertex **pointlist, uint tmap_flags, float constant_sw, float area)
ubyte g3_rotate_vertex(vertex *dest, const vec3d *src)
int g3_draw_rod(const vec3d *p0, float width1, const vec3d *p1, float width2, vertex *verts, uint tmap_flags)
float vm_vec_normalize_safe(vec3d *v)
int g3_project_vertex(vertex *point)
vec3d * vm_vec_unrotate(vec3d *dest, const vec3d *src, const matrix *m)
void g3_draw_htl_line(const vec3d *start, const vec3d *end)
GLint GLint GLint GLint GLint x
int g3_draw_poly_constant_sw(int nv, vertex **pointlist, uint tmap_flags, float constant_sw)
void vm_vec_interp_constant(vec3d *out, const vec3d *v0, const vec3d *v1, float t)
vertex ** clip_polygon(vertex **src, vertex **dest, int *nv, ccodes *cc, uint flags)
Clips a polygon to the viewing pyramid.
void stars_project_2d_onto_sphere(vec3d *pnt, float rho, float phi, float theta)
int do_facing_check(const vec3d *norm, vertex **vertlist, const vec3d *p)
#define TMAP_FLAG_CORRECT
void vm_vec_rand_vec_quick(vec3d *rvec)
void allocate(int quad, int n_tri=0)
__inline void gr_line(int x1, int y1, int x2, int y2, int resize_mode=GR_RESIZE_FULL)
void vm_vec_sub(vec3d *dest, const vec3d *src0, const vec3d *src1)
int g3_draw_sphere(vertex *pnt, float rad)
void g3_draw_2d_shield_icon(const coord2d coords[6], const int r, const int g, const int b, const int a)
GLboolean GLboolean GLboolean b
#define TRIANGLE_AREA(_p, _q, _r)
#define TMAP_FLAG_TRILIST
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()
void g3_draw_horizon_line()
ubyte g3_rotate_faraway_vertex(vertex *dest, const vec3d *src)
int g3_draw_poly(int nv, vertex **pointlist, uint tmap_flags)
GLint GLsizei GLsizei height
GLubyte GLubyte GLubyte GLubyte w
int g3_draw_perspective_bitmap(const angles *a, float scale_x, float scale_y, int div_x, int div_y, uint tmap_flags)
float Physics_viewer_bank
vertex ** bitmap_2d_poly_vertlist
vec3d * vm_vec_avg(vec3d *dest, const vec3d *src0, const vec3d *src1)
void g3_start_instance_matrix(const vec3d *pos, const matrix *orient, bool set_api=true)
#define TMAP_FLAG_TEXTURED
void draw_beam(vec3d *start, vec3d *end, float width, float intensity=1.0f, float offset=0.0f)
float vm_vec_dot(const vec3d *v0, const vec3d *v1)
#define TMAP_FLAG_TRISTRIP
vec3d * vm_vec_perp(vec3d *dest, const vec3d *p0, const vec3d *p1, const vec3d *p2)
void render(int flags, float radius=0.0f)
vec3d * vm_vec_cross(vec3d *dest, const vec3d *src0, const vec3d *src1)
texture_rect_list texture_rect
void g3_draw_htl_sphere(const vec3d *position, float radius)
void clip_line(vertex **p0, vertex **p1, ubyte codes_or, uint flags)
Clips a line to the viewing pyramid.
matrix vmd_identity_matrix
#define g3_start_frame(zbuffer_flag)
float vm_vec_normalize(vec3d *v)
int bitmap_2d_poly_list_size