Skip to content
Snippets Groups Projects
Commit b91408a0 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

*** empty log message ***

parent 66b7414b
No related branches found
No related tags found
No related merge requests found
/* /*
* GL2PS, an OpenGL to Postscript Printing Library, version 0.32 * GL2PS, an OpenGL to Postscript Printing Library
* Copyright (C) 1999-2001 Christophe Geuzaine * Copyright (C) 1999-2001 Christophe Geuzaine
* *
* $Id: gl2ps.cpp,v 1.13 2001-05-23 19:06:41 geuzaine Exp $ * $Id: gl2ps.cpp,v 1.14 2001-06-11 11:21:56 geuzaine Exp $
* *
* E-mail: Christophe.Geuzaine@AdValvas.be * E-mail: Christophe.Geuzaine@AdValvas.be
* URL: http://www.geuz.org/gl2ps/ * URL: http://www.geuz.org/gl2ps/
...@@ -34,8 +34,13 @@ ...@@ -34,8 +34,13 @@
#include "gl2ps.h" #include "gl2ps.h"
/* The static gl2ps structure. gl2ps is not thread safe (we should
allocate this structure when doing gl2psBeginPage). */
static GL2PScontext gl2ps; static GL2PScontext gl2ps;
/* Some 'system' utility routines */
GLvoid gl2psMsg(GLint level, char *fmt, ...){ GLvoid gl2psMsg(GLint level, char *fmt, ...){
va_list args; va_list args;
...@@ -74,6 +79,8 @@ GLvoid gl2psFree(GLvoid *ptr){ ...@@ -74,6 +79,8 @@ GLvoid gl2psFree(GLvoid *ptr){
free(ptr); free(ptr);
} }
/* The list handling routines */
GLvoid gl2psListRealloc(GL2PSlist *list, GLint n){ GLvoid gl2psListRealloc(GL2PSlist *list, GLint n){
if(n <= 0) return; if(n <= 0) return;
if(!list->array){ if(!list->array){
...@@ -145,6 +152,8 @@ GLvoid gl2psListActionInverse(GL2PSlist *list, ...@@ -145,6 +152,8 @@ GLvoid gl2psListActionInverse(GL2PSlist *list,
(*action)(gl2psListPointer(list, i-1), &dummy); (*action)(gl2psListPointer(list, i-1), &dummy);
} }
/* The 3D sorting routines */
GLfloat gl2psComparePointPlane(GL2PSxyz point, GL2PSplane plane){ GLfloat gl2psComparePointPlane(GL2PSxyz point, GL2PSplane plane){
return(plane[0] * point[0] + return(plane[0] * point[0] +
plane[1] * point[1] + plane[1] * point[1] +
...@@ -284,6 +293,7 @@ GLvoid gl2psCreateSplittedPrimitive(GL2PSprimitive *parent, GL2PSplane plane, ...@@ -284,6 +293,7 @@ GLvoid gl2psCreateSplittedPrimitive(GL2PSprimitive *parent, GL2PSplane plane,
} }
(*child)->boundary = 0; /* not done! */ (*child)->boundary = 0; /* not done! */
(*child)->dash = parent->dash; (*child)->dash = parent->dash;
(*child)->width = parent->width;
(*child)->numverts = numverts; (*child)->numverts = numverts;
(*child)->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex)); (*child)->verts = (GL2PSvertex *)gl2psMalloc(numverts * sizeof(GL2PSvertex));
...@@ -409,6 +419,7 @@ GLvoid gl2psDivideQuad(GL2PSprimitive *quad, ...@@ -409,6 +419,7 @@ GLvoid gl2psDivideQuad(GL2PSprimitive *quad,
(*t1)->numverts = (*t2)->numverts = 3; (*t1)->numverts = (*t2)->numverts = 3;
(*t1)->depth = (*t2)->depth = quad->depth; (*t1)->depth = (*t2)->depth = quad->depth;
(*t1)->dash = (*t2)->dash = quad->dash; (*t1)->dash = (*t2)->dash = quad->dash;
(*t1)->width = (*t2)->width = quad->width;
(*t1)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex)); (*t1)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex));
(*t2)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex)); (*t2)->verts = (GL2PSvertex *)gl2psMalloc(3 * sizeof(GL2PSvertex));
(*t1)->verts[0] = quad->verts[0]; (*t1)->verts[0] = quad->verts[0];
...@@ -494,6 +505,31 @@ GLvoid gl2psAddPrimitiveInList(GL2PSprimitive *prim, GL2PSlist *list){ ...@@ -494,6 +505,31 @@ GLvoid gl2psAddPrimitiveInList(GL2PSprimitive *prim, GL2PSlist *list){
} }
GLvoid gl2psFreeBspTree(GL2PSbsptree *tree){
if(tree->back){
gl2psFreeBspTree(tree->back);
gl2psFree(tree->back);
}
if(tree->primitives){
gl2psListAction(tree->primitives, gl2psFreePrimitive);
gl2psListDelete(tree->primitives);
}
if(tree->front){
gl2psFreeBspTree(tree->front);
gl2psFree(tree->front);
}
}
GLboolean gl2psGreater(GLfloat f1, GLfloat f2){
if(f1 > f2) return 1;
else return 0;
}
GLboolean gl2psLess(GLfloat f1, GLfloat f2){
if(f1 < f2) return 1;
else return 0;
}
GLvoid gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives){ GLvoid gl2psBuildBspTree(GL2PSbsptree *tree, GL2PSlist *primitives){
GL2PSprimitive *prim, *frontprim, *backprim; GL2PSprimitive *prim, *frontprim, *backprim;
GL2PSlist *frontlist, *backlist; GL2PSlist *frontlist, *backlist;
...@@ -578,6 +614,8 @@ GLvoid gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon, ...@@ -578,6 +614,8 @@ GLvoid gl2psTraverseBspTree(GL2PSbsptree *tree, GL2PSxyz eye, GLfloat epsilon,
} }
} }
/* The 2D sorting routines (for occlusion culling). These routines do
_not_ work as expected at the moment... */
GLint gl2psSplit2d(GL2PSxyz a, GL2PSxyz b, GL2PSxy tc, GL2PSxy td){ GLint gl2psSplit2d(GL2PSxyz a, GL2PSxyz b, GL2PSxy tc, GL2PSxy td){
GLfloat line[3], n, d[2]; GLfloat line[3], n, d[2];
...@@ -732,6 +770,7 @@ GLvoid gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list){ ...@@ -732,6 +770,7 @@ GLvoid gl2psAddBoundaryInList(GL2PSprimitive *prim, GL2PSlist *list){
b = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive)); b = (GL2PSprimitive*)gl2psMalloc(sizeof(GL2PSprimitive));
b->type = GL2PS_LINE; b->type = GL2PS_LINE;
b->dash = prim->dash; b->dash = prim->dash;
b->width = prim->width;
b->boundary = 0; b->boundary = 0;
b->numverts = 2; b->numverts = 2;
b->verts = (GL2PSvertex *)gl2psMalloc(2 * sizeof(GL2PSvertex)); b->verts = (GL2PSvertex *)gl2psMalloc(2 * sizeof(GL2PSvertex));
...@@ -791,80 +830,11 @@ GLvoid gl2psBuildPolygonBoundary(GL2PSbsptree *tree){ ...@@ -791,80 +830,11 @@ GLvoid gl2psBuildPolygonBoundary(GL2PSbsptree *tree){
gl2psBuildPolygonBoundary(tree->front); gl2psBuildPolygonBoundary(tree->front);
} }
GLvoid gl2psPrintPrimitive(GLvoid *a, GLvoid *b){ /* The feedback buffer parser */
GL2PSprimitive *prim;
prim = *(GL2PSprimitive**) a;
if(gl2ps.options & GL2PS_OCCLUSION_CULL && prim->depth >= 0.) return;
switch(prim->type){
case GL2PS_TEXT :
fprintf(gl2ps.stream, "(%s) %g %g %g %g %g %d /%s S\n",
prim->text->str, prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2], prim->text->fontsize,
prim->text->fontname);
break;
case GL2PS_POINT :
fprintf(gl2ps.stream, "%g %g %g %g %g P\n", prim->verts[0].xyz[0],
prim->verts[0].xyz[1], prim->verts[0].rgba[0],
prim->verts[0].rgba[1], prim->verts[0].rgba[2]);
break;
case GL2PS_LINE :
if(prim->dash)
fprintf(gl2ps.stream, "[%d] 0 setdash\n", prim->dash);
if(gl2ps.shade){
fprintf(gl2ps.stream, "%g %g %g %g %g %g %g %g %g %g SL\n",
prim->verts[1].xyz[0], prim->verts[1].xyz[1],
prim->verts[1].rgba[0], prim->verts[1].rgba[1],
prim->verts[1].rgba[2], prim->verts[0].xyz[0],
prim->verts[0].xyz[1], prim->verts[0].rgba[0],
prim->verts[0].rgba[1], prim->verts[0].rgba[2]);
}
else{
fprintf(gl2ps.stream, "%g %g %g %g %g %g %g L\n",
prim->verts[1].xyz[0], prim->verts[1].xyz[1],
prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2]);
}
if(prim->dash)
fprintf(gl2ps.stream, "[] 0 setdash\n");
break;
case GL2PS_TRIANGLE :
if(gl2ps.shade){
fprintf(gl2ps.stream, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n",
prim->verts[2].xyz[0], prim->verts[2].xyz[1],
prim->verts[2].rgba[0], prim->verts[2].rgba[1],
prim->verts[2].rgba[2], prim->verts[1].xyz[0],
prim->verts[1].xyz[1], prim->verts[1].rgba[0],
prim->verts[1].rgba[1], prim->verts[1].rgba[2],
prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2]);
}
else{
fprintf(gl2ps.stream, "%g %g %g %g %g %g %g %g %g T\n",
prim->verts[2].xyz[0], prim->verts[2].xyz[1],
prim->verts[1].xyz[0], prim->verts[1].xyz[1],
prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2]);
}
break;
case GL2PS_QUADRANGLE :
gl2psMsg(GL2PS_WARNING, "There should not be any quad left to print");
break;
default :
gl2psMsg(GL2PS_ERROR, "Unknown type of primitive to print");
break;
}
}
GLvoid gl2psAddPolyPrimitive(GLshort type, GLshort numverts, GLvoid gl2psAddPolyPrimitive(GLshort type, GLshort numverts,
GL2PSvertex *verts, GLint offset, GLint dash, GL2PSvertex *verts, GLint offset,
GLint dash, GLint width,
GLshort boundary){ GLshort boundary){
GLshort i; GLshort i;
GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ; GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ;
...@@ -929,6 +899,7 @@ GLvoid gl2psAddPolyPrimitive(GLshort type, GLshort numverts, ...@@ -929,6 +899,7 @@ GLvoid gl2psAddPolyPrimitive(GLshort type, GLshort numverts,
prim->depth = 0.; prim->depth = 0.;
prim->dash = dash; prim->dash = dash;
prim->width = width;
if(gl2ps.sort == GL2PS_SIMPLE_SORT){ if(gl2ps.sort == GL2PS_SIMPLE_SORT){
for(i = 0; i < numverts; i++) for(i = 0; i < numverts; i++)
...@@ -964,7 +935,7 @@ GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p){ ...@@ -964,7 +935,7 @@ GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p){
} }
GLint gl2psParseFeedbackBuffer(GLvoid){ GLint gl2psParseFeedbackBuffer(GLvoid){
GLint i, used, count, v, vtot, offset=0, dash=0; GLint i, used, count, v, vtot, offset=0, dash=0, psize=1, lwidth=1;
GLshort boundary, flag; GLshort boundary, flag;
GLfloat *current; GLfloat *current;
GL2PSvertex vertices[3]; GL2PSvertex vertices[3];
...@@ -995,7 +966,7 @@ GLint gl2psParseFeedbackBuffer(GLvoid){ ...@@ -995,7 +966,7 @@ GLint gl2psParseFeedbackBuffer(GLvoid){
i = gl2psGetVertex(&vertices[0], current); i = gl2psGetVertex(&vertices[0], current);
current += i; current += i;
used -= i; used -= i;
gl2psAddPolyPrimitive(GL2PS_POINT, 1, vertices, 0, dash, 0); gl2psAddPolyPrimitive(GL2PS_POINT, 1, vertices, 0, dash, psize, 0);
break; break;
case GL_LINE_TOKEN : case GL_LINE_TOKEN :
case GL_LINE_RESET_TOKEN : case GL_LINE_RESET_TOKEN :
...@@ -1007,7 +978,7 @@ GLint gl2psParseFeedbackBuffer(GLvoid){ ...@@ -1007,7 +978,7 @@ GLint gl2psParseFeedbackBuffer(GLvoid){
i = gl2psGetVertex(&vertices[1], current); i = gl2psGetVertex(&vertices[1], current);
current += i; current += i;
used -= i; used -= i;
gl2psAddPolyPrimitive(GL2PS_LINE, 2, vertices, 0, dash, 0); gl2psAddPolyPrimitive(GL2PS_LINE, 2, vertices, 0, dash, lwidth, 0);
break; break;
case GL_POLYGON_TOKEN : case GL_POLYGON_TOKEN :
count = (GLint)current[1]; count = (GLint)current[1];
...@@ -1030,7 +1001,7 @@ GLint gl2psParseFeedbackBuffer(GLvoid){ ...@@ -1030,7 +1001,7 @@ GLint gl2psParseFeedbackBuffer(GLvoid){
else else
flag = 0; flag = 0;
gl2psAddPolyPrimitive(GL2PS_TRIANGLE, 3, vertices, gl2psAddPolyPrimitive(GL2PS_TRIANGLE, 3, vertices,
offset, dash, flag); offset, dash, 1, flag);
vertices[1] = vertices[2]; vertices[1] = vertices[2];
} }
else else
...@@ -1054,6 +1025,8 @@ GLint gl2psParseFeedbackBuffer(GLvoid){ ...@@ -1054,6 +1025,8 @@ GLint gl2psParseFeedbackBuffer(GLvoid){
case GL2PS_END_POLYGON_BOUNDARY : boundary=0; break; case GL2PS_END_POLYGON_BOUNDARY : boundary=0; break;
case GL2PS_BEGIN_LINE_STIPPLE : dash=4; break; case GL2PS_BEGIN_LINE_STIPPLE : dash=4; break;
case GL2PS_END_LINE_STIPPLE : dash=0; break; case GL2PS_END_LINE_STIPPLE : dash=0; break;
case GL2PS_SET_POINT_SIZE : current++; used--; psize=(GLint)*current; break;
case GL2PS_SET_LINE_WIDTH : current++; used--; lwidth=(GLint)*current; break;
} }
current += 2; current += 2;
used -= 2; used -= 2;
...@@ -1069,6 +1042,10 @@ GLint gl2psParseFeedbackBuffer(GLvoid){ ...@@ -1069,6 +1042,10 @@ GLint gl2psParseFeedbackBuffer(GLvoid){
return GL2PS_SUCCESS; return GL2PS_SUCCESS;
} }
/* The postscript routines. Other (vector) image formats should be
easy to generate by creating the three corresponding routines for
the new format. */
GLvoid gl2psPrintPostscriptHeader(GLvoid){ GLvoid gl2psPrintPostscriptHeader(GLvoid){
GLint viewport[4], index; GLint viewport[4], index;
GLfloat rgba[4]; GLfloat rgba[4];
...@@ -1083,17 +1060,17 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){ ...@@ -1083,17 +1060,17 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){
RGB color: r g b C RGB color: r g b C
Font choose: size fontname FC Font choose: size fontname FC
String primitive: (string) x y r g b size fontname S String primitive: (string) x y r g b size fontname S
Point primitive: x y r g b P Point primitive: x y size r g b P
Flat-shaded line: x2 y2 x1 y1 r g b L Flat-shaded line: x2 y2 x1 y1 r g b width L
Flat-shaded triangle: x3 y3 x2 y2 x1 y1 r g b T Flat-shaded triangle: x3 y3 x2 y2 x1 y1 r g b T
Smooth-shaded line: x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 SL Smooth-shaded line: x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 width SL
Smooth-shaded triangle: x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 ST Smooth-shaded triangle: x3 y3 r3 g3 b3 x2 y2 r2 g2 b2 x1 y1 r1 g1 b1 ST
*/ */
fprintf(gl2ps.stream, fprintf(gl2ps.stream,
"%%!PS-Adobe-3.0\n" "%%!PS-Adobe-3.0\n"
"%%%%Title: %s\n" "%%%%Title: %s\n"
"%%%%Creator: GL2PS, an OpenGL to Postscript Printing Library, V. 0.32\n" "%%%%Creator: GL2PS, an OpenGL to Postscript Printing Library, v. %g\n"
"%%%%For: %s\n" "%%%%For: %s\n"
"%%%%CreationDate: %s" "%%%%CreationDate: %s"
"%%%%LanguageLevel: 2\n" "%%%%LanguageLevel: 2\n"
...@@ -1107,19 +1084,19 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){ ...@@ -1107,19 +1084,19 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){
"%%%%EndComments\n" "%%%%EndComments\n"
"%%%%BeginProlog\n" "%%%%BeginProlog\n"
"/gl2psdict 64 dict def gl2psdict begin\n" "/gl2psdict 64 dict def gl2psdict begin\n"
"1 setlinecap 1 setlinejoin 0.2 setlinewidth /bd {bind def} bind def\n" "1 setlinecap 1 setlinejoin /bd {bind def} bind def\n"
"/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add\n" "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add\n"
"setgray } bd /C { setrgbcolor } bd /FC { findfont exch scalefont\n" "setgray } bd /C { setrgbcolor } bd /FC { findfont exch scalefont\n"
"setfont } bd /S { FC C moveto show } bd /P { C newpath 0.5 0.0 360.0\n" "setfont } bd /S { FC C moveto show } bd /P { C newpath 0.0 360.0\n"
"arc closepath fill } bd /L { C newpath moveto lineto stroke } bd\n" "arc closepath fill } bd /L { setlinewidth C newpath moveto lineto stroke } bd\n"
"/T { C newpath moveto lineto lineto closepath fill } bd /SL { /b1\n" "/T { C newpath moveto lineto lineto closepath fill } bd /SL { /lw exch def /b1\n"
"exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n" "exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n"
"/b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n" "/b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n"
"b2 b1 sub abs 0.01 gt g2 g1 sub abs 0.005 gt r2 r1 sub abs 0.008 gt\n" "b2 b1 sub abs 0.01 gt g2 g1 sub abs 0.005 gt r2 r1 sub abs 0.008 gt\n"
"or or { /bm b1 b2 add 0.5 mul def /gm g1 g2 add 0.5 mul def\n" "or or { /bm b1 b2 add 0.5 mul def /gm g1 g2 add 0.5 mul def\n"
"/rm r1 r2 add 0.5 mul def /ym y1 y2 add 0.5 mul def /xm x1 x2 add\n" "/rm r1 r2 add 0.5 mul def /ym y1 y2 add 0.5 mul def /xm x1 x2 add\n"
"0.5 mul def x1 y1 r1 g1 b1 xm ym rm gm bm SL xm ym rm gm bm x2 y2 r2\n" "0.5 mul def x1 y1 r1 g1 b1 xm ym rm gm bm lw SL xm ym rm gm bm x2 y2 r2\n"
"g2 b2 SL } { x1 y1 x2 y2 r1 g1 b1 L } ifelse } bd /ST {/b1 exch\n" "g2 b2 lw SL } { x1 y1 x2 y2 r1 g1 b1 lw L } ifelse } bd /ST {/b1 exch\n"
"def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n" "def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n"
"/b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n" "/b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n"
"/b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n" "/b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n"
...@@ -1149,8 +1126,8 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){ ...@@ -1149,8 +1126,8 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){
"mark\n" "mark\n"
"gsave\n" "gsave\n"
"1.0 1.0 scale\n", "1.0 1.0 scale\n",
gl2ps.title, gl2ps.producer, ctime(&now), viewport[2], viewport[3], gl2ps.title, GL2PS_VERSION, gl2ps.producer, ctime(&now),
viewport[0], viewport[1], viewport[2], viewport[3]); viewport[2], viewport[3], viewport[0], viewport[1], viewport[2], viewport[3]);
if(gl2ps.options & GL2PS_DRAW_BACKGROUND){ if(gl2ps.options & GL2PS_DRAW_BACKGROUND){
if(gl2ps.colormode == GL_RGBA || gl2ps.colorsize == 0) if(gl2ps.colormode == GL_RGBA || gl2ps.colorsize == 0)
...@@ -1172,35 +1149,97 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){ ...@@ -1172,35 +1149,97 @@ GLvoid gl2psPrintPostscriptHeader(GLvoid){
} }
} }
GLvoid gl2psFreeBspTree(GL2PSbsptree *tree){ GLvoid gl2psPrintPostscriptPrimitive(GLvoid *a, GLvoid *b){
if(tree->back){ GL2PSprimitive *prim;
gl2psFreeBspTree(tree->back);
gl2psFree(tree->back); prim = *(GL2PSprimitive**) a;
if(gl2ps.options & GL2PS_OCCLUSION_CULL && prim->depth >= 0.) return;
switch(prim->type){
case GL2PS_TEXT :
fprintf(gl2ps.stream, "(%s) %g %g %g %g %g %d /%s S\n",
prim->text->str, prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2], prim->text->fontsize,
prim->text->fontname);
break;
case GL2PS_POINT :
fprintf(gl2ps.stream, "%g %g %g %g %g %g P\n",
prim->verts[0].xyz[0], prim->verts[0].xyz[1], 1.0*prim->width,
prim->verts[0].rgba[0], prim->verts[0].rgba[1], prim->verts[0].rgba[2]);
break;
case GL2PS_LINE :
if(prim->dash)
fprintf(gl2ps.stream, "[%d] 0 setdash\n", prim->dash);
if(gl2ps.shade){
fprintf(gl2ps.stream, "%g %g %g %g %g %g %g %g %g %g %g SL\n",
prim->verts[1].xyz[0], prim->verts[1].xyz[1],
prim->verts[1].rgba[0], prim->verts[1].rgba[1],
prim->verts[1].rgba[2], prim->verts[0].xyz[0],
prim->verts[0].xyz[1], prim->verts[0].rgba[0],
prim->verts[0].rgba[1], prim->verts[0].rgba[2],
0.2*prim->width);
} }
if(tree->primitives){ else{
gl2psListAction(tree->primitives, gl2psFreePrimitive); fprintf(gl2ps.stream, "%g %g %g %g %g %g %g %g L\n",
gl2psListDelete(tree->primitives); prim->verts[1].xyz[0], prim->verts[1].xyz[1],
prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2], 0.2*prim->width);
} }
if(tree->front){ if(prim->dash)
gl2psFreeBspTree(tree->front); fprintf(gl2ps.stream, "[] 0 setdash\n");
gl2psFree(tree->front); break;
case GL2PS_TRIANGLE :
if(gl2ps.shade){
fprintf(gl2ps.stream, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n",
prim->verts[2].xyz[0], prim->verts[2].xyz[1],
prim->verts[2].rgba[0], prim->verts[2].rgba[1],
prim->verts[2].rgba[2], prim->verts[1].xyz[0],
prim->verts[1].xyz[1], prim->verts[1].rgba[0],
prim->verts[1].rgba[1], prim->verts[1].rgba[2],
prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2]);
}
else{
fprintf(gl2ps.stream, "%g %g %g %g %g %g %g %g %g T\n",
prim->verts[2].xyz[0], prim->verts[2].xyz[1],
prim->verts[1].xyz[0], prim->verts[1].xyz[1],
prim->verts[0].xyz[0], prim->verts[0].xyz[1],
prim->verts[0].rgba[0], prim->verts[0].rgba[1],
prim->verts[0].rgba[2]);
} }
break;
case GL2PS_QUADRANGLE :
gl2psMsg(GL2PS_WARNING, "There should not be any quad left to print");
break;
default :
gl2psMsg(GL2PS_ERROR, "Unknown type of primitive to print");
break;
} }
GLboolean gl2psGreater(GLfloat f1, GLfloat f2){
if(f1 > f2) return 1;
else return 0;
} }
GLboolean gl2psLess(GLfloat f1, GLfloat f2){ void gl2psPrintPostscriptFooter(GLvoid){
if(f1 < f2) return 1; fprintf(gl2ps.stream,
else return 0; "grestore\n"
"showpage\n"
"cleartomark\n"
"%%%%PageTrailer\n"
"%%%%Trailer\n"
"end\n"
"%%%%EOF\n");
} }
/* The public routines */
GLvoid gl2psBeginPage(char *title, char *producer, GLint sort, GLint options, GLvoid gl2psBeginPage(char *title, char *producer, GLint sort, GLint options,
GLint colormode, GLint colorsize, GL2PSrgba *colormap, GLint colormode, GLint colorsize, GL2PSrgba *colormap,
GLint buffersize, FILE *stream){ GLint buffersize, FILE *stream){
gl2ps.format = GL2PS_EPS;
gl2ps.title = title; gl2ps.title = title;
gl2ps.producer = producer; gl2ps.producer = producer;
gl2ps.sort = sort; gl2ps.sort = sort;
...@@ -1240,6 +1279,10 @@ GLint gl2psEndPage(GLvoid){ ...@@ -1240,6 +1279,10 @@ GLint gl2psEndPage(GLvoid){
GL2PSxyz eye={0., 0., 100000.}; GL2PSxyz eye={0., 0., 100000.};
GLint shademodel, res; GLint shademodel, res;
void (*phead)(GLvoid);
void (*pprim)(GLvoid *a, GLvoid *b);
void (*pfoot)(GLvoid);
glGetIntegerv(GL_SHADE_MODEL, &shademodel); glGetIntegerv(GL_SHADE_MODEL, &shademodel);
gl2ps.shade = (shademodel == GL_SMOOTH); gl2ps.shade = (shademodel == GL_SMOOTH);
...@@ -1248,17 +1291,27 @@ GLint gl2psEndPage(GLvoid){ ...@@ -1248,17 +1291,27 @@ GLint gl2psEndPage(GLvoid){
if(gl2ps.feedback) gl2psFree(gl2ps.feedback); if(gl2ps.feedback) gl2psFree(gl2ps.feedback);
if(res == GL2PS_SUCCESS){ if(res == GL2PS_SUCCESS){
gl2psPrintPostscriptHeader();
switch(gl2ps.format){
case GL2PS_EPS :
default :
phead = gl2psPrintPostscriptHeader;
pprim = gl2psPrintPostscriptPrimitive;
pfoot = gl2psPrintPostscriptFooter;
break;
}
phead();
switch(gl2ps.sort){ switch(gl2ps.sort){
case GL2PS_NO_SORT : case GL2PS_NO_SORT :
gl2psListAction(gl2ps.primitives, gl2psPrintPrimitive); gl2psListAction(gl2ps.primitives, pprim);
gl2psListAction(gl2ps.primitives, gl2psFreePrimitive); gl2psListAction(gl2ps.primitives, gl2psFreePrimitive);
gl2psListDelete(gl2ps.primitives); gl2psListDelete(gl2ps.primitives);
res = GL2PS_SUCCESS; res = GL2PS_SUCCESS;
break; break;
case GL2PS_SIMPLE_SORT : case GL2PS_SIMPLE_SORT :
gl2psListSort(gl2ps.primitives, gl2psCompareDepth); gl2psListSort(gl2ps.primitives, gl2psCompareDepth);
gl2psListActionInverse(gl2ps.primitives, gl2psPrintPrimitive); gl2psListActionInverse(gl2ps.primitives, pprim);
gl2psListAction(gl2ps.primitives, gl2psFreePrimitive); gl2psListAction(gl2ps.primitives, gl2psFreePrimitive);
gl2psListDelete(gl2ps.primitives); gl2psListDelete(gl2ps.primitives);
res = GL2PS_SUCCESS; res = GL2PS_SUCCESS;
...@@ -1272,22 +1325,16 @@ GLint gl2psEndPage(GLvoid){ ...@@ -1272,22 +1325,16 @@ GLint gl2psEndPage(GLvoid){
gl2psAddInImage); gl2psAddInImage);
} }
gl2psTraverseBspTree(root, eye, GL2PS_EPSILON, gl2psGreater, gl2psTraverseBspTree(root, eye, GL2PS_EPSILON, gl2psGreater,
gl2psPrintPrimitive); pprim);
gl2psFreeBspTree(root); gl2psFreeBspTree(root);
res = GL2PS_SUCCESS; res = GL2PS_SUCCESS;
break; break;
default : default :
gl2psMsg(GL2PS_ERROR, "Unknown sorting algorithm"); gl2psMsg(GL2PS_ERROR, "Unknown sorting algorithm");
} }
fprintf(gl2ps.stream, pfoot();
"grestore\n"
"showpage\n"
"cleartomark\n"
"%%%%PageTrailer\n"
"%%%%Trailer\n"
"end\n"
"%%%%EOF\n");
fflush(gl2ps.stream); fflush(gl2ps.stream);
} }
if(gl2ps.colormap) gl2psFree(gl2ps.colormap); if(gl2ps.colormap) gl2psFree(gl2ps.colormap);
...@@ -1311,6 +1358,7 @@ GLvoid gl2psText(char *str, char *fontname, GLint fontsize){ ...@@ -1311,6 +1358,7 @@ GLvoid gl2psText(char *str, char *fontname, GLint fontsize){
prim->verts[0].xyz[2] = pos[2]; prim->verts[0].xyz[2] = pos[2];
prim->depth = pos[2]; prim->depth = pos[2];
prim->dash = 0; prim->dash = 0;
prim->width = 1;
glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba); glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba);
prim->text = (GL2PSstring*)gl2psMalloc(sizeof(GL2PSstring)); prim->text = (GL2PSstring*)gl2psMalloc(sizeof(GL2PSstring));
if((len = strlen(str))){ if((len = strlen(str))){
...@@ -1360,3 +1408,12 @@ GLvoid gl2psDisable(GLint mode){ ...@@ -1360,3 +1408,12 @@ GLvoid gl2psDisable(GLint mode){
} }
} }
GLvoid gl2psPointSize(GLint value){
glPassThrough(GL2PS_SET_POINT_SIZE);
glPassThrough(value);
}
GLvoid gl2psLineWidth(GLint value){
glPassThrough(GL2PS_SET_LINE_WIDTH);
glPassThrough(value);
}
/* /*
* GL2PS, an OpenGL to Postscript Printing Library, version 0.32 * GL2PS, an OpenGL to Postscript Printing Library
* Copyright (C) 1999-2001 Christophe Geuzaine * Copyright (C) 1999-2001 Christophe Geuzaine
* *
* $Id: gl2ps.h,v 1.8 2001-05-23 19:06:41 geuzaine Exp $ * $Id: gl2ps.h,v 1.9 2001-06-11 11:22:04 geuzaine Exp $
* *
* E-mail: Christophe.Geuzaine@AdValvas.be * E-mail: Christophe.Geuzaine@AdValvas.be
* URL: http://www.geuz.org/gl2ps/ * URL: http://www.geuz.org/gl2ps/
...@@ -30,8 +30,13 @@ ...@@ -30,8 +30,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <GL/gl.h> #include <GL/gl.h>
#define GL2PS_VERSION 0.33
#define GL2PS_NONE 0 #define GL2PS_NONE 0
/* Output file format */
#define GL2PS_EPS 1
/* Sorting algorithms */ /* Sorting algorithms */
#define GL2PS_NO_SORT 1 #define GL2PS_NO_SORT 1
...@@ -91,6 +96,8 @@ ...@@ -91,6 +96,8 @@
#define GL2PS_END_POLYGON_BOUNDARY 4 #define GL2PS_END_POLYGON_BOUNDARY 4
#define GL2PS_BEGIN_LINE_STIPPLE 5 #define GL2PS_BEGIN_LINE_STIPPLE 5
#define GL2PS_END_LINE_STIPPLE 6 #define GL2PS_END_LINE_STIPPLE 6
#define GL2PS_SET_POINT_SIZE 7
#define GL2PS_SET_LINE_WIDTH 8
typedef GLfloat GL2PSrgba[4]; typedef GLfloat GL2PSrgba[4];
typedef GLfloat GL2PSxyz[3]; typedef GLfloat GL2PSxyz[3];
...@@ -131,13 +138,13 @@ typedef struct { ...@@ -131,13 +138,13 @@ typedef struct {
typedef struct { typedef struct {
GLshort type, numverts, boundary; GLshort type, numverts, boundary;
GLfloat depth; GLfloat depth;
GLint dash; GLint dash, width;
GL2PSvertex *verts; GL2PSvertex *verts;
GL2PSstring *text; GL2PSstring *text;
} GL2PSprimitive; } GL2PSprimitive;
typedef struct { typedef struct {
GLint sort, options, colorsize, colormode, buffersize; GLint format, sort, options, colorsize, colormode, buffersize;
char *title, *producer; char *title, *producer;
GLboolean shade, boundary; GLboolean shade, boundary;
GLfloat *feedback, offset[2]; GLfloat *feedback, offset[2];
...@@ -156,5 +163,7 @@ GLint gl2psEndPage(GLvoid); ...@@ -156,5 +163,7 @@ GLint gl2psEndPage(GLvoid);
GLvoid gl2psText(char *str, char *fontname, GLint size); GLvoid gl2psText(char *str, char *fontname, GLint size);
GLvoid gl2psEnable(GLint mode); GLvoid gl2psEnable(GLint mode);
GLvoid gl2psDisable(GLint mode); GLvoid gl2psDisable(GLint mode);
GLvoid gl2psPointSize(GLint value);
GLvoid gl2psLineWidth(GLint value);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment