From 5d4cb94ab10adfaddd6997b573963ec12c332c9d Mon Sep 17 00:00:00 2001 From: Param Date: Fri, 26 Jun 2026 20:08:29 +0530 Subject: [PATCH 1/5] fix: implement GLU tessellation for proper concave area filling across wsgl functions (Fixes #7) --- src/include/phigs/private/wsgl_tessP.h | 28 +++ src/libphigs/CMakeLists.txt | 1 + src/libphigs/wsgl/wsgl_fasd3clear.c | 86 +++----- src/libphigs/wsgl/wsgl_fasd3fill.c | 254 +++++++++-------------- src/libphigs/wsgl/wsgl_fasdclear.c | 121 +++-------- src/libphigs/wsgl/wsgl_fasdfill.c | 255 +++++++++-------------- src/libphigs/wsgl/wsgl_fill.c | 68 ++---- src/libphigs/wsgl/wsgl_sofas3clear.c | 123 +++-------- src/libphigs/wsgl/wsgl_sofas3fill.c | 276 ++++++++++--------------- src/libphigs/wsgl/wsgl_tess.c | 117 +++++++++++ 10 files changed, 569 insertions(+), 760 deletions(-) create mode 100644 src/include/phigs/private/wsgl_tessP.h create mode 100644 src/libphigs/wsgl/wsgl_tess.c diff --git a/src/include/phigs/private/wsgl_tessP.h b/src/include/phigs/private/wsgl_tessP.h new file mode 100644 index 0000000..e9dc22b --- /dev/null +++ b/src/include/phigs/private/wsgl_tessP.h @@ -0,0 +1,28 @@ +#ifndef _wsgl_tessP_h +#define _wsgl_tessP_h + +#include +#include +#include "phg.h" + +typedef struct { + GLdouble pos[3]; + + /* Callback for applying per-vertex attributes (like color/normal) */ + void (*apply_cb)(void *data); + void *cb_data; + + /* Variables to avoid dynamic allocation for cb_data in simple cases */ + Ws *ws; + Pint colr_type; + Pcoval colr; + Ws_attr_st *ast; + + int has_norm; + Pfloat norm[3]; + +} Wsgl_tess_vertex; + +void wsgl_draw_tess_polygon(Wsgl_tess_vertex *vertices, int num_vertices, int record_geom_flag); + +#endif diff --git a/src/libphigs/CMakeLists.txt b/src/libphigs/CMakeLists.txt index 7ffb86d..76dd891 100644 --- a/src/libphigs/CMakeLists.txt +++ b/src/libphigs/CMakeLists.txt @@ -77,6 +77,7 @@ SET(P_WSGL_SRCS wsgl/wsgl_fasdfill.c wsgl/wsgl_fasedge.c wsgl/wsgl_fill.c + wsgl/wsgl_tess.c wsgl/wsgl_hatch.c wsgl/wsgl_light.c wsgl/wsgl_line.c diff --git a/src/libphigs/wsgl/wsgl_fasd3clear.c b/src/libphigs/wsgl/wsgl_fasd3clear.c index 2376d7c..d6c863c 100644 --- a/src/libphigs/wsgl/wsgl_fasd3clear.c +++ b/src/libphigs/wsgl/wsgl_fasd3clear.c @@ -42,31 +42,17 @@ static void priv_clear_area3_points( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(points[i].x, - points[i].y, - points[i].z); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(points[i].x, - points[i].y, - points[i].z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = points[i].x; + t_verts[i].pos[1] = points[i].y; + t_verts[i].pos[2] = points[i].z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom); + free(t_verts); } /******************************************************************************* @@ -82,31 +68,17 @@ static void priv_clear_area3_ptcolrs( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(ptcolrs[i].point.x, - ptcolrs[i].point.y, - ptcolrs[i].point.z); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x, - ptcolrs[i].point.y, - ptcolrs[i].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptcolrs[i].point.x; + t_verts[i].pos[1] = ptcolrs[i].point.y; + t_verts[i].pos[2] = ptcolrs[i].point.z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom); + free(t_verts); } /******************************************************************************* @@ -122,14 +94,17 @@ static void priv_clear_area3_ptnorms( ) { Pint i; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(ptnorms[i].point.x, - ptnorms[i].point.y, - ptnorms[i].point.z); + t_verts[i].pos[0] = ptnorms[i].point.x; + t_verts[i].pos[1] = ptnorms[i].point.y; + t_verts[i].pos[2] = ptnorms[i].point.z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, 0); + free(t_verts); } /******************************************************************************* @@ -146,14 +121,17 @@ static void priv_clear_area3_ptconorms( ) { Pint i; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(ptconorms[i].point.x, - ptconorms[i].point.y, - ptconorms[i].point.z); + t_verts[i].pos[0] = ptconorms[i].point.x; + t_verts[i].pos[1] = ptconorms[i].point.y; + t_verts[i].pos[2] = ptconorms[i].point.z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, 0); + free(t_verts); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl_fasd3fill.c b/src/libphigs/wsgl/wsgl_fasd3fill.c index b8853a3..28a490a 100644 --- a/src/libphigs/wsgl/wsgl_fasd3fill.c +++ b/src/libphigs/wsgl/wsgl_fasd3fill.c @@ -45,31 +45,17 @@ static void priv_fill_area3_points( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(points[i].x, - points[i].y, - points[i].z); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(points[i].x, - points[i].y, - points[i].z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = points[i].x; + t_verts[i].pos[1] = points[i].y; + t_verts[i].pos[2] = points[i].z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -79,6 +65,11 @@ static void priv_fill_area3_points( * RETURNS: N/A */ +static void cb_ptcolrs(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_fill_area3_ptcolrs( Ws *ws, Pint colr_type, @@ -88,32 +79,22 @@ static void priv_fill_area3_ptcolrs( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_int_colr(ws, colr_type, &ptcolrs[i].colr, ast); - glVertex3f(ptcolrs[i].point.x, - ptcolrs[i].point.y, - ptcolrs[i].point.z); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x, - ptcolrs[i].point.y, - ptcolrs[i].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } + t_verts[i].pos[0] = ptcolrs[i].point.x; + t_verts[i].pos[1] = ptcolrs[i].point.y; + t_verts[i].pos[2] = ptcolrs[i].point.z; + t_verts[i].apply_cb = cb_ptcolrs; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptcolrs[i].colr; + t_verts[i].ast = ast; } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); - } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -123,6 +104,11 @@ static void priv_fill_area3_ptcolrs( * RETURNS: N/A */ +static void cb_back_ptcolrs(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_back_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_back_area3_ptcolrs( Ws *ws, Pint colr_type, @@ -132,32 +118,22 @@ static void priv_back_area3_ptcolrs( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_back_int_colr(ws, colr_type, &ptcolrs[i].colr, ast); - glVertex3f(ptcolrs[i].point.x, - ptcolrs[i].point.y, - ptcolrs[i].point.z); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x, - ptcolrs[i].point.y, - ptcolrs[i].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptcolrs[i].point.x; + t_verts[i].pos[1] = ptcolrs[i].point.y; + t_verts[i].pos[2] = ptcolrs[i].point.z; + t_verts[i].apply_cb = cb_back_ptcolrs; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptcolrs[i].colr; + t_verts[i].ast = ast; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -173,37 +149,21 @@ static void priv_fill_area3_ptnorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glNormal3f(ptnorms[i].norm.delta_x, - ptnorms[i].norm.delta_y, - ptnorms[i].norm.delta_z); - wsgl_set_current_normal(ptnorms[i].norm.delta_x, - ptnorms[i].norm.delta_y, - ptnorms[i].norm.delta_z); - glVertex3f(ptnorms[i].point.x, - ptnorms[i].point.y, - ptnorms[i].point.z); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptnorms[i].point.x, - ptnorms[i].point.y, - ptnorms[i].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptnorms[i].point.x; + t_verts[i].pos[1] = ptnorms[i].point.y; + t_verts[i].pos[2] = ptnorms[i].point.z; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptnorms[i].norm.delta_x; + t_verts[i].norm[1] = ptnorms[i].norm.delta_y; + t_verts[i].norm[2] = ptnorms[i].norm.delta_z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -214,6 +174,11 @@ static void priv_fill_area3_ptnorms( * RETURNS: N/A */ +static void cb_ptconorms(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_fill_area3_ptconorms( Ws *ws, Pint colr_type, @@ -223,38 +188,26 @@ static void priv_fill_area3_ptconorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_int_colr(ws, colr_type, &ptconorms[i].colr, ast); - glNormal3f(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - ptconorms[i].norm.delta_z); - wsgl_set_current_normal(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - ptconorms[i].norm.delta_z); - glVertex3f(ptconorms[i].point.x, - ptconorms[i].point.y, - ptconorms[i].point.z); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x, - ptconorms[i].point.y, - ptconorms[i].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } + t_verts[i].pos[0] = ptconorms[i].point.x; + t_verts[i].pos[1] = ptconorms[i].point.y; + t_verts[i].pos[2] = ptconorms[i].point.z; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptconorms[i].norm.delta_x; + t_verts[i].norm[1] = ptconorms[i].norm.delta_y; + t_verts[i].norm[2] = ptconorms[i].norm.delta_z; + t_verts[i].apply_cb = cb_ptconorms; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptconorms[i].colr; + t_verts[i].ast = ast; } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); - } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -265,6 +218,11 @@ static void priv_fill_area3_ptconorms( * RETURNS: N/A */ +static void cb_back_ptconorms(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_back_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_back_area3_ptconorms( Ws *ws, Pint colr_type, @@ -274,38 +232,26 @@ static void priv_back_area3_ptconorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_back_int_colr(ws, colr_type, &ptconorms[i].colr, ast); - glNormal3f(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - ptconorms[i].norm.delta_z); - wsgl_set_current_normal(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - ptconorms[i].norm.delta_z); - glVertex3f(ptconorms[i].point.x, - ptconorms[i].point.y, - ptconorms[i].point.z); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x, - ptconorms[i].point.y, - ptconorms[i].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptconorms[i].point.x; + t_verts[i].pos[1] = ptconorms[i].point.y; + t_verts[i].pos[2] = ptconorms[i].point.z; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptconorms[i].norm.delta_x; + t_verts[i].norm[1] = ptconorms[i].norm.delta_y; + t_verts[i].norm[2] = ptconorms[i].norm.delta_z; + t_verts[i].apply_cb = cb_back_ptconorms; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptconorms[i].colr; + t_verts[i].ast = ast; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl_fasdclear.c b/src/libphigs/wsgl/wsgl_fasdclear.c index 74d8dc0..78758cd 100644 --- a/src/libphigs/wsgl/wsgl_fasdclear.c +++ b/src/libphigs/wsgl/wsgl_fasdclear.c @@ -32,6 +32,7 @@ #include "private/phgP.h" #include "ws.h" #include "private/wsglP.h" +#include "private/wsgl_tessP.h" #include "private/fasd3P.h" /******************************************************************************* @@ -47,31 +48,17 @@ static void priv_clear_area_points( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(points[i].x, - points[i].y, - 0.); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(points[i].x, - points[i].y, - 0.); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = points[i].x; + t_verts[i].pos[1] = points[i].y; + t_verts[i].pos[2] = 0.; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom); + free(t_verts); } /******************************************************************************* @@ -87,31 +74,17 @@ static void priv_clear_area_ptcolrs( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(ptcolrs[i].point.x, - ptcolrs[i].point.y, - 0.0); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x, - ptcolrs[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptcolrs[i].point.x; + t_verts[i].pos[1] = ptcolrs[i].point.y; + t_verts[i].pos[2] = 0.0; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom); + free(t_verts); } /******************************************************************************* @@ -127,31 +100,17 @@ static void priv_clear_area_ptnorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(ptnorms[i].point.x, - ptnorms[i].point.y, - 0.0); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptnorms[i].point.x, - ptnorms[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptnorms[i].point.x; + t_verts[i].pos[1] = ptnorms[i].point.y; + t_verts[i].pos[2] = 0.0; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom); + free(t_verts); } /******************************************************************************* @@ -168,31 +127,17 @@ static void priv_clear_area_ptconorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(ptconorms[i].point.x, - ptconorms[i].point.y, - 0.0); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x, - ptconorms[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptconorms[i].point.x; + t_verts[i].pos[1] = ptconorms[i].point.y; + t_verts[i].pos[2] = 0.0; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom); + free(t_verts); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl_fasdfill.c b/src/libphigs/wsgl/wsgl_fasdfill.c index 73371ee..451f88d 100644 --- a/src/libphigs/wsgl/wsgl_fasdfill.c +++ b/src/libphigs/wsgl/wsgl_fasdfill.c @@ -32,6 +32,7 @@ #include "private/phgP.h" #include "ws.h" #include "private/wsglP.h" +#include "private/wsgl_tessP.h" #include "private/fasd3P.h" /******************************************************************************* @@ -47,31 +48,17 @@ static void priv_fill_area_points( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glVertex3f(points[i].x, - points[i].y, - 0.0); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(points[i].x, - points[i].y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = points[i].x; + t_verts[i].pos[1] = points[i].y; + t_verts[i].pos[2] = 0.0; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -81,6 +68,11 @@ static void priv_fill_area_points( * RETURNS: N/A */ +static void cb_ptcolrs(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_fill_area_ptcolrs( Ws *ws, Pint colr_type, @@ -90,32 +82,22 @@ static void priv_fill_area_ptcolrs( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_int_colr(ws, colr_type, &ptcolrs[i].colr, ast); - glVertex3f(ptcolrs[i].point.x, - ptcolrs[i].point.y, - 0.0); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x, - ptcolrs[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } + t_verts[i].pos[0] = ptcolrs[i].point.x; + t_verts[i].pos[1] = ptcolrs[i].point.y; + t_verts[i].pos[2] = 0.0; + t_verts[i].apply_cb = cb_ptcolrs; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptcolrs[i].colr; + t_verts[i].ast = ast; } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); - } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -125,6 +107,11 @@ static void priv_fill_area_ptcolrs( * RETURNS: N/A */ +static void cb_back_ptcolrs(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_back_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_back_area_ptcolrs( Ws *ws, Pint colr_type, @@ -134,32 +121,22 @@ static void priv_back_area_ptcolrs( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_back_int_colr(ws, colr_type, &ptcolrs[i].colr, ast); - glVertex3f(ptcolrs[i].point.x, - ptcolrs[i].point.y, - 0.0); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x, - ptcolrs[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptcolrs[i].point.x; + t_verts[i].pos[1] = ptcolrs[i].point.y; + t_verts[i].pos[2] = 0.0; + t_verts[i].apply_cb = cb_back_ptcolrs; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptcolrs[i].colr; + t_verts[i].ast = ast; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -175,37 +152,21 @@ static void priv_fill_area_ptnorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - glNormal3f(ptnorms[i].norm.delta_x, - ptnorms[i].norm.delta_y, - 0.0); - wsgl_set_current_normal(ptnorms[i].norm.delta_x, - ptnorms[i].norm.delta_y, - 0.0); - glVertex3f(ptnorms[i].point.x, - ptnorms[i].point.y, - 0.0); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptnorms[i].point.x, - ptnorms[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptnorms[i].point.x; + t_verts[i].pos[1] = ptnorms[i].point.y; + t_verts[i].pos[2] = 0.0; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptnorms[i].norm.delta_x; + t_verts[i].norm[1] = ptnorms[i].norm.delta_y; + t_verts[i].norm[2] = 0.0; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -216,6 +177,11 @@ static void priv_fill_area_ptnorms( * RETURNS: N/A */ +static void cb_ptconorms(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_fill_area_ptconorms( Ws *ws, Pint colr_type, @@ -225,38 +191,26 @@ static void priv_fill_area_ptconorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_int_colr(ws, colr_type, &ptconorms[i].colr, ast); - glNormal3f(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - 0.0); - wsgl_set_current_normal(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - 0.0); - glVertex3f(ptconorms[i].point.x, - ptconorms[i].point.y, - 0.0); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x, - ptconorms[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } + t_verts[i].pos[0] = ptconorms[i].point.x; + t_verts[i].pos[1] = ptconorms[i].point.y; + t_verts[i].pos[2] = 0.0; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptconorms[i].norm.delta_x; + t_verts[i].norm[1] = ptconorms[i].norm.delta_y; + t_verts[i].norm[2] = 0.0; + t_verts[i].apply_cb = cb_ptconorms; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptconorms[i].colr; + t_verts[i].ast = ast; } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); - } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -267,6 +221,11 @@ static void priv_fill_area_ptconorms( * RETURNS: N/A */ +static void cb_back_ptconorms(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_back_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_back_area_ptconorms( Ws *ws, Pint colr_type, @@ -276,38 +235,26 @@ static void priv_back_area_ptconorms( ) { Pint i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(num_vertices * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, num_vertices * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < num_vertices; i++) { - wsgl_setup_back_int_colr(ws, colr_type, &ptconorms[i].colr, ast); - glNormal3f(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - 0.0); - wsgl_set_current_normal(ptconorms[i].norm.delta_x, - ptconorms[i].norm.delta_y, - 0.0); - glVertex3f(ptconorms[i].point.x, - ptconorms[i].point.y, - 0.0); - if (record_geom && record_geom_fill){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x, - ptconorms[i].point.y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptconorms[i].point.x; + t_verts[i].pos[1] = ptconorms[i].point.y; + t_verts[i].pos[2] = 0.0; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptconorms[i].norm.delta_x; + t_verts[i].norm[1] = ptconorms[i].norm.delta_y; + t_verts[i].norm[2] = 0.0; + t_verts[i].apply_cb = cb_back_ptconorms; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptconorms[i].colr; + t_verts[i].ast = ast; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, num_vertices, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl_fill.c b/src/libphigs/wsgl/wsgl_fill.c index 13da10c..cfe18f9 100644 --- a/src/libphigs/wsgl/wsgl_fill.c +++ b/src/libphigs/wsgl/wsgl_fill.c @@ -27,6 +27,7 @@ #include "private/phgP.h" #include "ws.h" #include "private/wsglP.h" +#include "private/wsgl_tessP.h" /******************************************************************************* * priv_fill_area @@ -40,33 +41,18 @@ void priv_fill_area( ) { int i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(point_list->num_points * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, point_list->num_points * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < point_list->num_points; i++) { - glVertex2f(point_list->points[i].x, - point_list->points[i].y); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_fill: priv_fill_area called\n"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(point_list->points[i].x, - point_list->points[i].y, - 0.0); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } + t_verts[i].pos[0] = point_list->points[i].x; + t_verts[i].pos[1] = point_list->points[i].y; + t_verts[i].pos[2] = 0.0; } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); - } - glEnd(); + + wsgl_draw_tess_polygon(t_verts, point_list->num_points, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -113,34 +99,18 @@ void priv_fill_area3( ) { int i; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(point_list->num_points * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, point_list->num_points * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < point_list->num_points; i++) { - glVertex3f(point_list->points[i].x, - point_list->points[i].y, - point_list->points[i].z); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_fill: priv_fill_area3 called\n"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(point_list->points[i].x, - point_list->points[i].y, - point_list->points[i].z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = point_list->points[i].x; + t_verts[i].pos[1] = point_list->points[i].y; + t_verts[i].pos[2] = point_list->points[i].z; } - glEnd(); + + wsgl_draw_tess_polygon(t_verts, point_list->num_points, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl_sofas3clear.c b/src/libphigs/wsgl/wsgl_sofas3clear.c index c512ec6..026a713 100644 --- a/src/libphigs/wsgl/wsgl_sofas3clear.c +++ b/src/libphigs/wsgl/wsgl_sofas3clear.c @@ -27,6 +27,7 @@ #include "private/phgP.h" #include "ws.h" #include "private/wsglP.h" +#include "private/wsgl_tessP.h" #include "private/sofas3P.h" /******************************************************************************* @@ -42,32 +43,18 @@ static void priv_clear_area3_points( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - glVertex3f(points[vert].x, - points[vert].y, - points[vert].z); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(points[vert].x, - points[vert].y, - points[vert].z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = points[vert].x; + t_verts[i].pos[1] = points[vert].y; + t_verts[i].pos[2] = points[vert].z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom); + free(t_verts); } /******************************************************************************* @@ -83,32 +70,18 @@ static void priv_clear_area3_ptcolrs( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; - - glBegin(GL_POLYGON); + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); + for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - glVertex3f(ptcolrs[vert].point.x, - ptcolrs[vert].point.y, - ptcolrs[vert].point.z); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[vert].point.x, - ptcolrs[vert].point.y, - ptcolrs[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptcolrs[vert].point.x; + t_verts[i].pos[1] = ptcolrs[vert].point.y; + t_verts[i].pos[2] = ptcolrs[vert].point.z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom); + free(t_verts); } /******************************************************************************* @@ -124,32 +97,18 @@ static void priv_clear_area3_ptnorms( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - glVertex3f(ptnorms[vert].point.x, - ptnorms[vert].point.y, - ptnorms[vert].point.z); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptnorms[vert].point.x, - ptnorms[vert].point.y, - ptnorms[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptnorms[vert].point.x; + t_verts[i].pos[1] = ptnorms[vert].point.y; + t_verts[i].pos[2] = ptnorms[vert].point.z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom); + free(t_verts); } /******************************************************************************* @@ -166,32 +125,18 @@ static void priv_clear_area3_ptconorms( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - glVertex3f(ptconorms[vert].point.x, - ptconorms[vert].point.y, - ptconorms[vert].point.z); - if (record_geom){ - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[vert].point.x, - ptconorms[vert].point.y, - ptconorms[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptconorms[vert].point.x; + t_verts[i].pos[1] = ptconorms[vert].point.y; + t_verts[i].pos[2] = ptconorms[vert].point.z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom); + free(t_verts); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl_sofas3fill.c b/src/libphigs/wsgl/wsgl_sofas3fill.c index 2ecfbf3..a1792cc 100644 --- a/src/libphigs/wsgl/wsgl_sofas3fill.c +++ b/src/libphigs/wsgl/wsgl_sofas3fill.c @@ -29,6 +29,7 @@ #include "private/phgP.h" #include "ws.h" #include "private/wsglP.h" +#include "private/wsgl_tessP.h" #include "private/sofas3P.h" /******************************************************************************* @@ -44,35 +45,19 @@ static void priv_fill_area3_points( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - glVertex3f(points[vert].x, - points[vert].y, - points[vert].z); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_sofas3fill: priv_fill_area3_points called"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(points[vert].x, - points[vert].y, - points[vert].z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = points[vert].x; + t_verts[i].pos[1] = points[vert].y; + t_verts[i].pos[2] = points[vert].z; } - glEnd(); + + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -82,6 +67,11 @@ static void priv_fill_area3_points( * RETURNS: N/A */ +static void cb_ptcolrs(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_fill_area3_ptcolrs( Ws *ws, Pint colr_type, @@ -91,36 +81,24 @@ static void priv_fill_area3_ptcolrs( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - wsgl_setup_int_colr(ws, colr_type, &ptcolrs[vert].colr, ast); - glVertex3f(ptcolrs[vert].point.x, - ptcolrs[vert].point.y, - ptcolrs[vert].point.z); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_sofas3fill: priv_fill_area3_ptcolrs called"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[vert].point.x, - ptcolrs[vert].point.y, - ptcolrs[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } + t_verts[i].pos[0] = ptcolrs[vert].point.x; + t_verts[i].pos[1] = ptcolrs[vert].point.y; + t_verts[i].pos[2] = ptcolrs[vert].point.z; + t_verts[i].apply_cb = cb_ptcolrs; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptcolrs[vert].colr; + t_verts[i].ast = ast; } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); - } - glEnd(); + + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -130,6 +108,11 @@ static void priv_fill_area3_ptcolrs( * RETURNS: N/A */ +static void cb_back_ptcolrs(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_back_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_back_area3_ptcolrs( Ws *ws, Pint colr_type, @@ -139,36 +122,24 @@ static void priv_back_area3_ptcolrs( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - wsgl_setup_back_int_colr(ws, colr_type, &ptcolrs[vert].colr, ast); - glVertex3f(ptcolrs[vert].point.x, - ptcolrs[vert].point.y, - ptcolrs[vert].point.z); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_sofas3fill: priv_back_area3_ptcolrs called"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[vert].point.x, - ptcolrs[vert].point.y, - ptcolrs[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptcolrs[vert].point.x; + t_verts[i].pos[1] = ptcolrs[vert].point.y; + t_verts[i].pos[2] = ptcolrs[vert].point.z; + t_verts[i].apply_cb = cb_back_ptcolrs; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptcolrs[vert].colr; + t_verts[i].ast = ast; } - glEnd(); + + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -184,41 +155,22 @@ static void priv_fill_area3_ptnorms( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - glNormal3f(ptnorms[vert].norm.delta_x, - ptnorms[vert].norm.delta_y, - ptnorms[vert].norm.delta_z); - wsgl_set_current_normal(ptnorms[vert].norm.delta_x, - ptnorms[vert].norm.delta_y, - ptnorms[vert].norm.delta_z); - glVertex3f(ptnorms[vert].point.x, - ptnorms[vert].point.y, - ptnorms[vert].point.z); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_sofas3fill: priv_fill_area3_ptnorms called"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(ptnorms[vert].point.x, - ptnorms[vert].point.y, - ptnorms[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptnorms[vert].point.x; + t_verts[i].pos[1] = ptnorms[vert].point.y; + t_verts[i].pos[2] = ptnorms[vert].point.z; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptnorms[vert].norm.delta_x; + t_verts[i].norm[1] = ptnorms[vert].norm.delta_y; + t_verts[i].norm[2] = ptnorms[vert].norm.delta_z; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -229,6 +181,11 @@ static void priv_fill_area3_ptnorms( * RETURNS: N/A */ +static void cb_ptconorms(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_fill_area3_ptconorms( Ws *ws, Pint colr_type, @@ -238,42 +195,27 @@ static void priv_fill_area3_ptconorms( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - wsgl_setup_int_colr(ws, colr_type, &ptconorms[vert].colr, ast); - glNormal3f(ptconorms[vert].norm.delta_x, - ptconorms[vert].norm.delta_y, - ptconorms[vert].norm.delta_z); - wsgl_set_current_normal(ptconorms[vert].norm.delta_x, - ptconorms[vert].norm.delta_y, - ptconorms[vert].norm.delta_z); - glVertex3f(ptconorms[vert].point.x, - ptconorms[vert].point.y, - ptconorms[vert].point.z); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_sofas3fill: priv_fill_area3_ptconorms called"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[vert].point.x, - ptconorms[vert].point.y, - ptconorms[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } + t_verts[i].pos[0] = ptconorms[vert].point.x; + t_verts[i].pos[1] = ptconorms[vert].point.y; + t_verts[i].pos[2] = ptconorms[vert].point.z; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptconorms[vert].norm.delta_x; + t_verts[i].norm[1] = ptconorms[vert].norm.delta_y; + t_verts[i].norm[2] = ptconorms[vert].norm.delta_z; + t_verts[i].apply_cb = cb_ptconorms; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptconorms[vert].colr; + t_verts[i].ast = ast; } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); - } - glEnd(); + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* @@ -284,6 +226,11 @@ static void priv_fill_area3_ptconorms( * RETURNS: N/A */ +static void cb_back_ptconorms(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + wsgl_setup_back_int_colr(v->ws, v->colr_type, &v->colr, v->ast); +} + static void priv_back_area3_ptconorms( Ws *ws, Pint colr_type, @@ -293,42 +240,27 @@ static void priv_back_area3_ptconorms( ) { Pint i, vert; - int vertex_indices[MAX_VERTICES]; - int n_vertices = 0; - int normal_indices[MAX_VERTICES]; - int n_normals = 0; + Wsgl_tess_vertex *t_verts = (Wsgl_tess_vertex *)malloc(vlist->num_ints * sizeof(Wsgl_tess_vertex)); + if (!t_verts) return; + memset(t_verts, 0, vlist->num_ints * sizeof(Wsgl_tess_vertex)); - glBegin(GL_POLYGON); for (i = 0; i < vlist->num_ints; i++) { vert = vlist->ints[i]; - wsgl_setup_back_int_colr(ws, colr_type, &ptconorms[vert].colr, ast); - glNormal3f(ptconorms[vert].norm.delta_x, - ptconorms[vert].norm.delta_y, - ptconorms[vert].norm.delta_z); - wsgl_set_current_normal(ptconorms[vert].norm.delta_x, - ptconorms[vert].norm.delta_y, - ptconorms[vert].norm.delta_z); - glVertex3f(ptconorms[vert].point.x, - ptconorms[vert].point.y, - ptconorms[vert].point.z); - if (record_geom && record_geom_fill){ -#ifdef DEBUG_OBJ - printf("wsgl_sofas3fill: priv_back_area3_ptconorms called"); -#endif - vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[vert].point.x, - ptconorms[vert].point.y, - ptconorms[vert].point.z); - n_vertices ++; - normal_indices[n_normals] = wsgl_add_normal(current_normal.x, - current_normal.y, - current_normal.z); - n_normals ++; - } - } - if (record_geom && record_geom_fill){ - wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + t_verts[i].pos[0] = ptconorms[vert].point.x; + t_verts[i].pos[1] = ptconorms[vert].point.y; + t_verts[i].pos[2] = ptconorms[vert].point.z; + t_verts[i].has_norm = 1; + t_verts[i].norm[0] = ptconorms[vert].norm.delta_x; + t_verts[i].norm[1] = ptconorms[vert].norm.delta_y; + t_verts[i].norm[2] = ptconorms[vert].norm.delta_z; + t_verts[i].apply_cb = cb_back_ptconorms; + t_verts[i].ws = ws; + t_verts[i].colr_type = colr_type; + t_verts[i].colr = ptconorms[vert].colr; + t_verts[i].ast = ast; } - glEnd(); + wsgl_draw_tess_polygon(t_verts, vlist->num_ints, record_geom && record_geom_fill); + free(t_verts); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl_tess.c b/src/libphigs/wsgl/wsgl_tess.c new file mode 100644 index 0000000..e627925 --- /dev/null +++ b/src/libphigs/wsgl/wsgl_tess.c @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include + +#include "phg.h" +#include "private/phgP.h" +#include "ws.h" +#include "private/wsglP.h" +#include "private/wsgl_tessP.h" + +#ifndef CALLBACK +#if defined(_WIN32) +#define CALLBACK __stdcall +#else +#define CALLBACK +#endif +#endif + +static void CALLBACK tessBeginCB(GLenum which) { + glBegin(which); +} + +static void CALLBACK tessEndCB() { + glEnd(); +} + +static void CALLBACK tessVertexCB(void *data) { + Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + if (v->apply_cb) { + v->apply_cb(v); + } + glVertex3dv(v->pos); +} + +static void CALLBACK tessCombineCB(GLdouble coords[3], + void *vertex_data[4], + GLfloat weight[4], + void **outData) { + /* Basic combine callback to prevent crashing on self-intersecting polygons */ + Wsgl_tess_vertex *new_vert = (Wsgl_tess_vertex *)malloc(sizeof(Wsgl_tess_vertex)); + if (new_vert) { + memset(new_vert, 0, sizeof(Wsgl_tess_vertex)); + new_vert->pos[0] = coords[0]; + new_vert->pos[1] = coords[1]; + new_vert->pos[2] = coords[2]; + if (vertex_data[0]) { + Wsgl_tess_vertex *v0 = (Wsgl_tess_vertex *)vertex_data[0]; + new_vert->apply_cb = v0->apply_cb; + new_vert->ws = v0->ws; + new_vert->colr_type = v0->colr_type; + new_vert->colr = v0->colr; + new_vert->ast = v0->ast; + new_vert->has_norm = v0->has_norm; + if (new_vert->has_norm) { + new_vert->norm[0] = v0->norm[0]; + new_vert->norm[1] = v0->norm[1]; + new_vert->norm[2] = v0->norm[2]; + } + } + *outData = new_vert; + } else { + *outData = vertex_data[0]; + } +} + +static void CALLBACK tessErrorCB(GLenum errorCode) { + const GLubyte *errorStr; + errorStr = gluErrorString(errorCode); + /* fprintf(stderr, "OpenPHIGS GLU Tessellation Error: %s\n", errorStr); */ +} + +void wsgl_draw_tess_polygon(Wsgl_tess_vertex *vertices, int num_vertices, int record_geom_flag) +{ + GLUtesselator *tess; + int i; + int vertex_indices[MAX_VERTICES]; + int normal_indices[MAX_VERTICES]; + int n_vertices = 0; + int n_normals = 0; + + tess = gluNewTess(); + if (!tess) return; + + gluTessCallback(tess, GLU_TESS_BEGIN, (void (CALLBACK *)())tessBeginCB); + gluTessCallback(tess, GLU_TESS_END, (void (CALLBACK *)())tessEndCB); + gluTessCallback(tess, GLU_TESS_VERTEX, (void (CALLBACK *)())tessVertexCB); + gluTessCallback(tess, GLU_TESS_ERROR, (void (CALLBACK *)())tessErrorCB); + gluTessCallback(tess, GLU_TESS_COMBINE, (void (CALLBACK *)())tessCombineCB); + + gluTessBeginPolygon(tess, NULL); + gluTessBeginContour(tess); + + for (i = 0; i < num_vertices; i++) { + gluTessVertex(tess, vertices[i].pos, (void *)&vertices[i]); + + if (record_geom_flag) { + vertex_indices[n_vertices] = wsgl_add_vertex((float)vertices[i].pos[0], + (float)vertices[i].pos[1], + (float)vertices[i].pos[2]); + n_vertices++; + normal_indices[n_normals] = wsgl_add_normal(current_normal.x, + current_normal.y, + current_normal.z); + n_normals++; + } + } + + gluTessEndContour(tess); + gluTessEndPolygon(tess); + gluDeleteTess(tess); + + if (record_geom_flag && n_vertices > 0) { + wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices); + } +} From 6d09fc0731edbce71a86fd715b53cb159c3dbd09 Mon Sep 17 00:00:00 2001 From: Param Date: Sat, 27 Jun 2026 13:21:29 +0530 Subject: [PATCH 2/5] fix: resolve missing wsgl_tessP.h includes and fix dolphin interior style --- src/libphigs/wsgl/wsgl_fasd3clear.c | 1 + src/libphigs/wsgl/wsgl_fasd3fill.c | 1 + src/test_f/test_f3.f | 1 + 3 files changed, 3 insertions(+) diff --git a/src/libphigs/wsgl/wsgl_fasd3clear.c b/src/libphigs/wsgl/wsgl_fasd3clear.c index d6c863c..e97bf65 100644 --- a/src/libphigs/wsgl/wsgl_fasd3clear.c +++ b/src/libphigs/wsgl/wsgl_fasd3clear.c @@ -28,6 +28,7 @@ #include "ws.h" #include "private/wsglP.h" #include "private/fasd3P.h" +#include "private/wsgl_tessP.h" /******************************************************************************* * priv_clear_area3_points diff --git a/src/libphigs/wsgl/wsgl_fasd3fill.c b/src/libphigs/wsgl/wsgl_fasd3fill.c index 28a490a..57d6104 100644 --- a/src/libphigs/wsgl/wsgl_fasd3fill.c +++ b/src/libphigs/wsgl/wsgl_fasd3fill.c @@ -31,6 +31,7 @@ #include "ws.h" #include "private/wsglP.h" #include "private/fasd3P.h" +#include "private/wsgl_tessP.h" /******************************************************************************* * priv_fill_area3_points diff --git a/src/test_f/test_f3.f b/src/test_f/test_f3.f index 236dda7..934343b 100644 --- a/src/test_f/test_f3.f +++ b/src/test_f/test_f3.f @@ -432,6 +432,7 @@ SUBROUTINE KYDELP (XORG, YORG, SCAL) END IF * * Draw the Dolphin + CALL PSIS(PSOLID) CALL PSEDCI (IBLUE) CALL PSICI (153) CALL VFILL (VCOLI, NPT1, IBLUE) From 3acdda512bbbaa0d405be81e8cf55f9aa952f6eb Mon Sep 17 00:00:00 2001 From: Param Date: Sat, 27 Jun 2026 13:38:06 +0530 Subject: [PATCH 3/5] fix: resolve color and normal issues in tessellated polygons --- src/libphigs/wsgl/wsgl_fasdfill.c | 18 ++++++++++++------ src/libphigs/wsgl/wsgl_tess.c | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libphigs/wsgl/wsgl_fasdfill.c b/src/libphigs/wsgl/wsgl_fasdfill.c index 451f88d..99cfe20 100644 --- a/src/libphigs/wsgl/wsgl_fasdfill.c +++ b/src/libphigs/wsgl/wsgl_fasdfill.c @@ -305,8 +305,9 @@ void wsgl_fill_area_set_data_front( } } else if (fasd3.fflag == PFACET_NORMAL) { + Pint colr_type = wsgl_get_int_colr(ast)->type; wsgl_colr_from_gcolr(&colr, wsgl_get_int_colr(ast), ws->current_colour_model); - wsgl_setup_int_colr(ws, fasd3.colr_type, &colr, ast); + wsgl_setup_int_colr(ws, colr_type, &colr, ast); glNormal3f(fasd3.fdata.norm.delta_x, fasd3.fdata.norm.delta_y, fasd3.fdata.norm.delta_z); @@ -340,8 +341,9 @@ void wsgl_fill_area_set_data_front( } } else { + Pint colr_type = wsgl_get_int_colr(ast)->type; wsgl_colr_from_gcolr(&colr, wsgl_get_int_colr(ast), ws->current_colour_model); - wsgl_setup_int_colr(ws, fasd3.colr_type, &colr, ast); + wsgl_setup_int_colr(ws, colr_type, &colr, ast); fasd3_normal3(&norm, &fasd3); glNormal3f(norm.delta_x, norm.delta_y, norm.delta_z); for (i = 0; i < fasd3.nfa; i++) { @@ -413,8 +415,9 @@ void wsgl_fill_area_set_data_front( } } else { + Pint colr_type = wsgl_get_int_colr(ast)->type; wsgl_colr_from_gcolr(&colr, wsgl_get_int_colr(ast), ws->current_colour_model); - wsgl_setup_int_colr(ws, fasd3.colr_type, &colr, ast); + wsgl_setup_int_colr(ws, colr_type, &colr, ast); for (i = 0; i < fasd3.nfa; i++) { priv_fill_area_ptnorms(fasd3.vdata->num_vertices, fasd3.vdata->vertex_data.ptnorms); @@ -506,8 +509,9 @@ void wsgl_fill_area_set_data_back( } } else if (fasd3.fflag == PFACET_NORMAL) { + Pint colr_type = wsgl_get_back_int_colr(ast)->type; wsgl_colr_from_gcolr(&colr, wsgl_get_back_int_colr(ast), ws->current_colour_model); - wsgl_setup_back_int_colr(ws, fasd3.colr_type, &colr, ast); + wsgl_setup_back_int_colr(ws, colr_type, &colr, ast); glNormal3f(fasd3.fdata.norm.delta_x, fasd3.fdata.norm.delta_y, fasd3.fdata.norm.delta_z); @@ -545,8 +549,9 @@ void wsgl_fill_area_set_data_back( } } else { + Pint colr_type = wsgl_get_back_int_colr(ast)->type; wsgl_colr_from_gcolr(&colr, wsgl_get_back_int_colr(ast), ws->current_colour_model); - wsgl_setup_back_int_colr(ws, fasd3.colr_type, &colr, ast); + wsgl_setup_back_int_colr(ws, colr_type, &colr, ast); fasd3_normal3(&norm, &fasd3); glNormal3f(norm.delta_x, norm.delta_y, norm.delta_z); wsgl_set_current_normal(norm.delta_x, norm.delta_y, norm.delta_z); @@ -623,8 +628,9 @@ void wsgl_fill_area_set_data_back( } } else { + Pint colr_type = wsgl_get_back_int_colr(ast)->type; wsgl_colr_from_gcolr(&colr, wsgl_get_back_int_colr(ast), ws->current_colour_model); - wsgl_setup_back_int_colr(ws, fasd3.colr_type, &colr, ast); + wsgl_setup_back_int_colr(ws, colr_type, &colr, ast); for (i = 0; i < fasd3.nfa; i++) { priv_fill_area_ptnorms(fasd3.vdata->num_vertices, fasd3.vdata->vertex_data.ptnorms); diff --git a/src/libphigs/wsgl/wsgl_tess.c b/src/libphigs/wsgl/wsgl_tess.c index e627925..b78b21d 100644 --- a/src/libphigs/wsgl/wsgl_tess.c +++ b/src/libphigs/wsgl/wsgl_tess.c @@ -28,6 +28,10 @@ static void CALLBACK tessEndCB() { static void CALLBACK tessVertexCB(void *data) { Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; + if (v->has_norm) { + glNormal3dv(v->norm); + wsgl_set_current_normal((float)v->norm[0], (float)v->norm[1], (float)v->norm[2]); + } if (v->apply_cb) { v->apply_cb(v); } From 1d89b148595fc35a54bc6442558cb754d20b582d Mon Sep 17 00:00:00 2001 From: Param Date: Sat, 27 Jun 2026 13:48:43 +0530 Subject: [PATCH 4/5] fix: compile error for glNormal3dv incompatible pointer type --- src/libphigs/wsgl/wsgl_tess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libphigs/wsgl/wsgl_tess.c b/src/libphigs/wsgl/wsgl_tess.c index b78b21d..a1455a5 100644 --- a/src/libphigs/wsgl/wsgl_tess.c +++ b/src/libphigs/wsgl/wsgl_tess.c @@ -29,7 +29,7 @@ static void CALLBACK tessEndCB() { static void CALLBACK tessVertexCB(void *data) { Wsgl_tess_vertex *v = (Wsgl_tess_vertex *)data; if (v->has_norm) { - glNormal3dv(v->norm); + glNormal3fv(v->norm); wsgl_set_current_normal((float)v->norm[0], (float)v->norm[1], (float)v->norm[2]); } if (v->apply_cb) { From 2cfb9e762da7040c4e35ffdda6090fb5316d5351 Mon Sep 17 00:00:00 2001 From: Param Date: Sat, 27 Jun 2026 15:42:55 +0530 Subject: [PATCH 5/5] test: set interior color ASF to INDIVIDUAL in test_f3.f so PSICI works as expected --- src/test_f/test_f3.f | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test_f/test_f3.f b/src/test_f/test_f3.f index 934343b..a5352e8 100644 --- a/src/test_f/test_f3.f +++ b/src/test_f/test_f3.f @@ -507,6 +507,7 @@ PROGRAM DRAWLINE C Open structure CALL POPST(0) + CALL PSIASF(13, 1) CALL KYDELP(0.3, 0.5, 1.) C C Close structure