26 #ifdef G4VIS_BUILD_OPENGL_DRIVER
27 #define G4VIS_BUILD_OPENGL_GL2PS
29 #ifdef G4VIS_BUILD_OI_DRIVER
30 #define G4VIS_BUILD_OPENGL_GL2PS
33 #ifdef G4VIS_BUILD_OPENGL_GL2PS
74 #include <sys/types.h>
79 #define GL2PS_HAVE_ZLIB
82 #if defined(GL2PS_HAVE_LIBPNG)
95 #define GL2PS_EPSILON 5.0e-3F
96 #define GL2PS_ZSCALE 1000.0F
97 #define GL2PS_ZOFFSET 5.0e-2F
98 #define GL2PS_ZOFFSET_LARGE 20.0F
99 #define GL2PS_ZERO(arg) (std::fabs(arg) < 1.e-20)
103 #define GL2PS_COINCIDENT 1
104 #define GL2PS_IN_FRONT_OF 2
105 #define GL2PS_IN_BACK_OF 3
106 #define GL2PS_SPANNING 4
110 #define GL2PS_POINT_COINCIDENT 0
111 #define GL2PS_POINT_INFRONT 1
112 #define GL2PS_POINT_BACK 2
116 #define GL2PS_BEGIN_OFFSET_TOKEN 1
117 #define GL2PS_END_OFFSET_TOKEN 2
118 #define GL2PS_BEGIN_BOUNDARY_TOKEN 3
119 #define GL2PS_END_BOUNDARY_TOKEN 4
120 #define GL2PS_BEGIN_STIPPLE_TOKEN 5
121 #define GL2PS_END_STIPPLE_TOKEN 6
122 #define GL2PS_POINT_SIZE_TOKEN 7
123 #define GL2PS_LINE_CAP_TOKEN 8
124 #define GL2PS_LINE_JOIN_TOKEN 9
125 #define GL2PS_LINE_WIDTH_TOKEN 10
126 #define GL2PS_BEGIN_BLEND_TOKEN 11
127 #define GL2PS_END_BLEND_TOKEN 12
128 #define GL2PS_SRC_BLEND_TOKEN 13
129 #define GL2PS_DST_BLEND_TOKEN 14
130 #define GL2PS_IMAGEMAP_TOKEN 15
131 #define GL2PS_DRAW_PIXELS_TOKEN 16
132 #define GL2PS_TEXT_TOKEN 17
139 T_ALPHA_LESS_1 = 1<<3,
141 } GL2PS_TRIANGLE_PROPERTY;
143 typedef GLfloat GL2PSplane[4];
145 typedef struct _GL2PSbsptree2d GL2PSbsptree2d;
147 struct _GL2PSbsptree2d {
149 GL2PSbsptree2d *front, *back;
153 GLint
nmax, size, incr,
n;
157 typedef struct _GL2PSbsptree GL2PSbsptree;
159 struct _GL2PSbsptree {
161 GL2PSlist *primitives;
162 GL2PSbsptree *front, *back;
172 char *str, *fontname;
180 GLsizei
width, height;
185 GLfloat zoom_x, zoom_y;
189 typedef struct _GL2PSimagemap GL2PSimagemap;
191 struct _GL2PSimagemap {
197 GLshort type, numverts;
199 char boundary,
offset, culled;
200 GLint factor, linecap, linejoin;
201 GLfloat
width, ofactor, ounits;
210 #if defined(GL2PS_HAVE_ZLIB)
211 Bytef *dest, *src, *
start;
212 uLongf destLen, srcLen;
220 int gsno, fontno, imno, shno, maskshno, trgroupno;
221 int gsobjno, fontobjno, imobjno, shobjno, maskshobjno, trgroupobjno;
226 GLint format, sort, options, colorsize, colormode, buffersize;
227 GLint lastlinecap, lastlinejoin;
229 GLboolean boundary, blending;
230 GLfloat *feedback, lastlinewidth;
231 GLint viewport[4], blendfunc[2], lastfactor;
232 GL2PSrgba *colormap, lastrgba, threshold, bgcolor;
233 GLushort lastpattern;
235 GL2PSlist *primitives, *auxprimitives;
240 GLboolean forcerasterpos;
246 GLboolean zerosurfacearea;
247 GL2PSbsptree2d *imagetree;
248 GL2PSprimitive *primitivetoadd;
252 GL2PSlist *pdfprimlist, *pdfgrouplist;
258 int trgroupobjects_stack;
263 GL2PSimagemap *imagemap_head;
264 GL2PSimagemap *imagemap_tail;
270 void (*beginViewport)(GLint viewport[4]);
271 GLint (*endViewport)(
void);
274 const char *file_extension;
275 const char *description;
281 static GL2PScontext *
gl2ps = NULL;
293 static void gl2psMsg(GLint level,
const char *fmt, ...)
299 case GL2PS_INFO : fprintf(stderr,
"GL2PS info: ");
break;
300 case GL2PS_WARNING : fprintf(stderr,
"GL2PS warning: ");
break;
301 case GL2PS_ERROR : fprintf(stderr,
"GL2PS error: ");
break;
304 vfprintf(stderr, fmt, args);
306 fprintf(stderr,
"\n");
315 if(!size)
return NULL;
327 if(!size)
return NULL;
328 ptr = realloc(orig, size);
346 int size =
sizeof(
unsigned long);
347 for(i = 1; i <= bytes; ++i){
348 fputc(0xff & (data >> (size - i) * 8),
gl2ps->stream);
355 #if defined(GL2PS_HAVE_ZLIB)
360 gl2ps->compress->src = NULL;
361 gl2ps->compress->start = NULL;
362 gl2ps->compress->dest = NULL;
363 gl2ps->compress->srcLen = 0;
364 gl2ps->compress->destLen = 0;
373 gl2ps->compress->src = NULL;
374 gl2ps->compress->start = NULL;
375 gl2ps->compress->dest = NULL;
376 gl2ps->compress->srcLen = 0;
377 gl2ps->compress->destLen = 0;
384 if(!
gl2ps->compress || !srcsize)
387 gl2ps->compress->srcLen = srcsize;
388 gl2ps->compress->destLen = (
int)ceil(1.001 *
gl2ps->compress->srcLen + 12);
390 gl2ps->compress->start =
gl2ps->compress->src;
398 if(!
gl2ps->compress || !srcsize)
401 if(srcsize < gl2ps->
compress->srcLen)
402 return gl2ps->compress->start;
404 gl2ps->compress->srcLen = srcsize;
405 gl2ps->compress->destLen = (
int)ceil(1.001 *
gl2ps->compress->srcLen + 12);
407 gl2ps->compress->srcLen);
408 gl2ps->compress->start =
gl2ps->compress->src;
410 gl2ps->compress->destLen);
412 return gl2ps->compress->start;
418 int size =
sizeof(
unsigned long);
419 for(i = 1; i <= bytes; ++i){
420 *
gl2ps->compress->src = (Bytef)(0xff & (data >> (size-i) * 8));
421 ++
gl2ps->compress->src;
431 gl2ps->compress->start,
gl2ps->compress->srcLen);
441 #if defined(GL2PS_HAVE_ZLIB)
442 static char buf[1024];
444 GLboolean freebuf = GL_FALSE;
445 unsigned int oldsize = 0;
446 #if !defined(GL2PS_HAVE_NO_VSNPRINTF)
449 int bufsize =
sizeof(buf);
453 #if defined(GL2PS_HAVE_NO_VSNPRINTF)
454 ret = vsprintf(buf, fmt, args);
456 ret = vsnprintf(bufptr, bufsize, fmt, args);
459 #if !defined(GL2PS_HAVE_NO_VSNPRINTF)
460 while(ret >= (bufsize - 1) || ret < 0){
463 if(freebuf == GL_TRUE)
gl2psFree(bufptr);
467 ret = vsnprintf(bufptr, bufsize, fmt, args);
471 oldsize =
gl2ps->compress->srcLen;
473 memcpy(
gl2ps->compress->start + oldsize, bufptr, ret);
474 if(freebuf == GL_TRUE)
gl2psFree(bufptr);
480 ret = vfprintf(
gl2ps->stream, fmt, args);
482 #if defined(GL2PS_HAVE_ZLIB)
490 #if defined(GL2PS_HAVE_ZLIB)
491 char tmp[10] = {
'\x1f',
'\x8b',
501 fwrite(tmp, 10, 1,
gl2ps->stream);
508 #if defined(GL2PS_HAVE_ZLIB)
520 if(
gl2ps->compress->dest[1] & (1<<5)){
524 fwrite(
gl2ps->compress->dest+n,
gl2ps->compress->destLen-(n+4),
528 for(n = 0; n < 4; ++
n){
529 tmp[
n] = (char)(crc & 0xff);
532 len =
gl2ps->compress->srcLen;
533 for(n = 4; n < 8; ++
n){
534 tmp[
n] = (char)(len & 0xff);
537 fwrite(tmp, 8, 1,
gl2ps->stream);
541 gl2ps->compress = NULL;
557 list->array = (
char*)
gl2psMalloc(list->nmax * list->size);
561 list->nmax = ((n - 1) / list->incr + 1) * list->incr;
563 list->nmax * list->size);
573 if(incr <= 0) incr = 1;
605 memcpy(&list->array[(list->n - 1) * list->size], data, list->size);
621 if((idx < 0) || (idx >= list->n)){
625 return &list->array[idx * list->size];
629 int (*fcmp)(
const void *
a,
const void *
b))
633 qsort(list->array, list->n, list->size, fcmp);
636 static void gl2psListAction(GL2PSlist *list,
void (*action)(
void *data))
654 #if defined(GL2PS_HAVE_LIBPNG)
656 static void gl2psListRead(GL2PSlist *list,
int index,
void *data)
658 if((index < 0) || (index >= list->n))
660 memcpy(data, &list->array[index * list->size], list->size);
665 static const char cb64[] =
666 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
668 out[0] = cb64[ in[0] >> 2 ];
669 out[1] = cb64[ ((in[0] & 0x03) << 4) | ((
in[1] & 0xf0) >> 4) ];
670 out[2] = (len > 1) ? cb64[ ((
in[1] & 0x0f) << 2) | ((
in[2] & 0xc0) >> 6) ] :
'=';
671 out[3] = (len > 2) ? cb64[
in[2] & 0x3f ] :
'=';
676 unsigned char *
buffer,
in[3], out[4];
677 int i,
n, index,
len;
679 n = list->n * list->size;
680 buffer = (
unsigned char*)
gl2psMalloc(n *
sizeof(
unsigned char));
681 memcpy(buffer, list->array, n *
sizeof(
unsigned char));
687 for(i = 0; i < 3; i++) {
689 in[i] = buffer[index];
699 for(i = 0; i < 4; i++)
712 if(!GL2PS_ZERO(rgba1[0] - rgba2[0]) ||
713 !GL2PS_ZERO(rgba1[1] - rgba2[1]) ||
714 !GL2PS_ZERO(rgba1[2] - rgba2[2]))
723 for(i = 1; i < prim->numverts; i++){
736 if(n < 2)
return GL_TRUE;
738 for(i = 1; i <
n; i++){
739 if(std::fabs(rgba[0][0] - rgba[i][0]) > threshold[0] ||
740 std::fabs(rgba[0][1] - rgba[i][1]) > threshold[1] ||
741 std::fabs(rgba[0][2] - rgba[i][2]) > threshold[2])
751 for(i = 0; i < 3; ++i){
752 gl2ps->lastrgba[i] = rgba[i];
756 static GLfloat
gl2psGetRGB(GL2PSimage *im, GLuint
x, GLuint
y,
757 GLfloat *red, GLfloat *green, GLfloat *blue)
760 GLsizei
width = im->width;
761 GLsizei height = im->height;
762 GLfloat *pixels = im->pixels;
768 pimag = pixels + 4 * (width * (height - 1 -
y) + x);
772 pimag = pixels + 3 * (width * (height - 1 -
y) + x);
775 *red = *pimag; pimag++;
776 *green = *pimag; pimag++;
777 *blue = *pimag; pimag++;
779 return (im->format == GL_RGBA) ? *pimag : 1.0F;
787 GL2PSimage *image = (GL2PSimage*)
gl2psMalloc(
sizeof(GL2PSimage));
789 image->width = im->width;
790 image->height = im->height;
791 image->format = im->format;
792 image->type = im->type;
793 image->zoom_x = im->zoom_x;
794 image->zoom_y = im->zoom_y;
796 switch(image->format){
798 size = image->height * image->width * 4 *
sizeof(GLfloat);
802 size = image->height * image->width * 3 *
sizeof(GLfloat);
807 memcpy(image->pixels, im->pixels, size);
820 #if defined(GL2PS_HAVE_LIBPNG)
822 #if !defined(png_jmpbuf)
823 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
829 GL2PSlist *png = (GL2PSlist*)png_get_io_ptr(png_ptr);
830 for(i = 0; i <
length; i++)
843 unsigned char *row_data;
847 if(!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
850 if(!(info_ptr = png_create_info_struct(png_ptr))){
851 png_destroy_write_struct(&png_ptr, NULL);
855 if(setjmp(png_jmpbuf(png_ptr))) {
856 png_destroy_write_struct(&png_ptr, &info_ptr);
862 png_set_IHDR(png_ptr, info_ptr, pixmap->width, pixmap->height, 8,
863 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
864 PNG_FILTER_TYPE_BASE);
865 png_write_info(png_ptr, info_ptr);
867 row_data = (
unsigned char*)
gl2psMalloc(3 * pixmap->width *
sizeof(
unsigned char));
868 for(row = 0; row < pixmap->height; row++){
869 for(col = 0; col < pixmap->width; col++){
871 row_data[3*
col] = (
unsigned char)(255. * dr);
872 row_data[3*col+1] = (
unsigned char)(255. * dg);
873 row_data[3*col+2] = (
unsigned char)(255. * db);
875 png_write_row(png_ptr, (png_bytep)row_data);
879 png_write_end(png_ptr, info_ptr);
880 png_destroy_write_struct(&png_ptr, &info_ptr);
887 static GLint
gl2psAddText(GLint type,
const char *str,
const char *fontname,
888 GLshort fontsize, GLint alignment, GLfloat
angle,
892 GL2PSprimitive *prim;
899 if (
gl2ps->forcerasterpos) {
900 pos[0] =
gl2ps->rasterpos.xyz[0];
901 pos[1] =
gl2ps->rasterpos.xyz[1];
902 pos[2] =
gl2ps->rasterpos.xyz[2];
906 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
908 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
911 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
912 prim->type = (GLshort)type;
916 prim->verts[0].xyz[0] = pos[0];
917 prim->verts[0].xyz[1] = pos[1];
918 prim->verts[0].xyz[2] = pos[2];
930 memcpy(prim->verts[0].rgba, color, 4 *
sizeof(
float));
933 if (
gl2ps->forcerasterpos) {
934 prim->verts[0].rgba[0] =
gl2ps->rasterpos.rgba[0];
935 prim->verts[0].rgba[1] =
gl2ps->rasterpos.rgba[1];
936 prim->verts[0].rgba[2] =
gl2ps->rasterpos.rgba[2];
937 prim->verts[0].rgba[3] =
gl2ps->rasterpos.rgba[3];
940 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba);
943 prim->data.text = (GL2PSstring*)
gl2psMalloc(
sizeof(GL2PSstring));
944 prim->data.text->str = (
char*)
gl2psMalloc((strlen(str)+1)*
sizeof(
char));
945 strcpy(prim->data.text->str, str);
946 prim->data.text->fontname = (
char*)
gl2psMalloc((strlen(fontname)+1)*
sizeof(char));
947 strcpy(prim->data.text->fontname, fontname);
948 prim->data.text->fontsize = fontsize;
949 prim->data.text->alignment = alignment;
950 prim->data.text->angle =
angle;
952 gl2ps->forcerasterpos = GL_FALSE;
960 glPassThrough(GL2PS_TEXT_TOKEN);
968 GL2PSstring *text = (GL2PSstring*)
gl2psMalloc(
sizeof(GL2PSstring));
969 text->str = (
char*)
gl2psMalloc((strlen(t->str)+1)*
sizeof(
char));
970 strcpy(text->str, t->str);
971 text->fontname = (
char*)
gl2psMalloc((strlen(t->fontname)+1)*
sizeof(char));
972 strcpy(text->fontname, t->fontname);
973 text->fontsize = t->fontsize;
974 text->alignment = t->alignment;
975 text->angle = t->angle;
996 if( (sfactor == GL_SRC_ALPHA && dfactor == GL_ONE_MINUS_SRC_ALPHA) ||
997 (sfactor == GL_ONE && dfactor == GL_ZERO) )
1017 switch(
gl2ps->blendfunc[0]){
1030 t->prop = T_VAR_COLOR;
1047 if(!GL2PS_ZERO(t->vertex[0].rgba[3] - t->vertex[1].rgba[3]) ||
1048 !GL2PS_ZERO(t->vertex[1].rgba[3] - t->vertex[2].rgba[3])){
1049 t->prop |= T_VAR_ALPHA;
1052 if(t->vertex[0].rgba[3] < 1)
1053 t->prop |= T_ALPHA_LESS_1;
1055 t->prop |= T_ALPHA_1;
1060 GLboolean assignprops)
1062 t->vertex[0] = p->verts[0];
1063 t->vertex[1] = p->verts[1];
1064 t->vertex[2] = p->verts[2];
1065 if(GL_TRUE == assignprops)
1072 GL2PSvertex vertex = { {-1.0F, -1.0F, -1.0F}, {-1.0F, -1.0F, -1.0F, -1.0F} };
1073 for(i = 0; i < 3; i++)
1074 t->vertex[i] = vertex;
1075 t->prop = T_UNDEFINED;
1080 static void gl2psResetLineProperties(
void)
1082 gl2ps->lastlinewidth = 0.;
1083 gl2ps->lastlinecap =
gl2ps->lastlinejoin = 0;
1088 GL2PSprimitive *prim;
1095 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1097 prim->type = p->type;
1098 prim->numverts = p->numverts;
1099 prim->boundary = p->boundary;
1100 prim->offset = p->offset;
1101 prim->ofactor = p->ofactor;
1102 prim->ounits = p->ounits;
1103 prim->pattern = p->pattern;
1104 prim->factor = p->factor;
1105 prim->culled = p->culled;
1106 prim->width = p->width;
1107 prim->linecap = p->linecap;
1108 prim->linejoin = p->linejoin;
1110 memcpy(prim->verts, p->verts, p->numverts *
sizeof(
GL2PSvertex));
1129 if(!GL2PS_ZERO(p1[0] - p2[0]) ||
1130 !GL2PS_ZERO(p1[1] - p2[1]) ||
1131 !GL2PS_ZERO(p1[2] - p2[2]))
1144 return (plane[0] * point[0] +
1145 plane[1] * point[1] +
1146 plane[2] * point[2] +
1150 static GLfloat
gl2psPsca(GLfloat *a, GLfloat *b)
1152 return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
1155 static void gl2psPvec(GLfloat *a, GLfloat *b, GLfloat *
c)
1157 c[0] = a[1]*b[2] - a[2]*b[1];
1158 c[1] = a[2]*b[0] - a[0]*b[2];
1159 c[2] = a[0]*b[1] - a[1]*b[0];
1164 return (GLfloat)sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
1186 static void gl2psGetPlane(GL2PSprimitive *prim, GL2PSplane plane)
1188 GL2PSxyz v = {0.0F, 0.0F, 0.0F},
w = {0.0F, 0.0F, 0.0F};
1193 v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0];
1194 v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1];
1195 v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2];
1196 w[0] = prim->verts[2].xyz[0] - prim->verts[0].xyz[0];
1197 w[1] = prim->verts[2].xyz[1] - prim->verts[0].xyz[1];
1198 w[2] = prim->verts[2].xyz[2] - prim->verts[0].xyz[2];
1199 if((GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])) ||
1200 (GL2PS_ZERO(
w[0]) && GL2PS_ZERO(
w[1]) && GL2PS_ZERO(
w[2]))){
1201 plane[0] = plane[1] = 0.0F;
1203 plane[3] = -prim->verts[0].xyz[2];
1208 - plane[0] * prim->verts[0].xyz[0]
1209 - plane[1] * prim->verts[0].xyz[1]
1210 - plane[2] * prim->verts[0].xyz[2];
1214 v[0] = prim->verts[1].xyz[0] - prim->verts[0].xyz[0];
1215 v[1] = prim->verts[1].xyz[1] - prim->verts[0].xyz[1];
1216 v[2] = prim->verts[1].xyz[2] - prim->verts[0].xyz[2];
1217 if(GL2PS_ZERO(v[0]) && GL2PS_ZERO(v[1]) && GL2PS_ZERO(v[2])){
1218 plane[0] = plane[1] = 0.0F;
1220 plane[3] = -prim->verts[0].xyz[2];
1223 if(GL2PS_ZERO(v[0]))
w[0] = 1.0F;
1224 else if(GL2PS_ZERO(v[1]))
w[1] = 1.0F;
1228 - plane[0] * prim->verts[0].xyz[0]
1229 - plane[1] * prim->verts[0].xyz[1]
1230 - plane[2] * prim->verts[0].xyz[2];
1238 plane[0] = plane[1] = 0.0F;
1240 plane[3] = -prim->verts[0].xyz[2];
1244 plane[0] = plane[1] = plane[3] = 0.0F;
1256 v[0] = b->
xyz[0] - a->
xyz[0];
1257 v[1] = b->
xyz[1] - a->
xyz[1];
1258 v[2] = b->
xyz[2] - a->
xyz[2];
1260 if(!GL2PS_ZERO(psca =
gl2psPsca(plane, v)))
1265 c->
xyz[0] = a->
xyz[0] + v[0] * sect;
1266 c->
xyz[1] = a->
xyz[1] + v[1] * sect;
1267 c->
xyz[2] = a->
xyz[2] + v[2] * sect;
1269 c->
rgba[0] = (1 - sect) * a->
rgba[0] + sect * b->
rgba[0];
1270 c->
rgba[1] = (1 - sect) * a->
rgba[1] + sect * b->
rgba[1];
1271 c->
rgba[2] = (1 - sect) * a->
rgba[2] + sect * b->
rgba[2];
1272 c->
rgba[3] = (1 - sect) * a->
rgba[3] + sect * b->
rgba[3];
1276 GL2PSprimitive *child, GLshort numverts,
1283 child->data.image = parent->data.image;
1299 child->boundary = 0;
1300 child->culled = parent->culled;
1301 child->offset = parent->offset;
1302 child->ofactor = parent->ofactor;
1303 child->ounits = parent->ounits;
1304 child->pattern = parent->pattern;
1305 child->factor = parent->factor;
1306 child->width = parent->width;
1307 child->linecap = parent->linecap;
1308 child->linejoin = parent->linejoin;
1309 child->numverts = numverts;
1312 for(i = 0; i < numverts; i++){
1314 child->verts[i] = parent->verts[index0[i]];
1317 gl2psCutEdge(&parent->verts[index0[i]], &parent->verts[index1[i]],
1318 plane, &child->verts[i]);
1323 static void gl2psAddIndex(GLshort *index0, GLshort *index1, GLshort *nb,
1324 GLshort i, GLshort j)
1328 for(k = 0; k < *nb; k++){
1329 if((index0[k] == i && index1[k] == j) ||
1330 (index1[k] == i && index0[k] == j))
return;
1339 return (i < num - 1) ? i + 1 : 0;
1344 GLint type = GL2PS_COINCIDENT;
1348 for(i = 0; i < prim->numverts; i++){
1352 if(prim->numverts < 2){
1356 for(i = 0; i < prim->numverts; i++){
1358 if(d[j] > GL2PS_EPSILON){
1359 if(type == GL2PS_COINCIDENT) type = GL2PS_IN_BACK_OF;
1360 else if(type != GL2PS_IN_BACK_OF)
return 1;
1361 if(d[i] < -GL2PS_EPSILON)
return 1;
1363 else if(d[j] < -GL2PS_EPSILON){
1364 if(type == GL2PS_COINCIDENT) type = GL2PS_IN_FRONT_OF;
1365 else if(type != GL2PS_IN_FRONT_OF)
return 1;
1366 if(d[i] > GL2PS_EPSILON)
return 1;
1374 GL2PSprimitive **front, GL2PSprimitive **back)
1376 GLshort i, j, in = 0, out = 0, in0[5], in1[5], out0[5], out1[5];
1380 type = GL2PS_COINCIDENT;
1382 for(i = 0; i < prim->numverts; i++){
1388 if(d[0] > GL2PS_EPSILON) type = GL2PS_IN_BACK_OF;
1389 else if(d[0] < -GL2PS_EPSILON) type = GL2PS_IN_FRONT_OF;
1390 else type = GL2PS_COINCIDENT;
1393 for(i = 0; i < prim->numverts; i++){
1395 if(d[j] > GL2PS_EPSILON){
1396 if(type == GL2PS_COINCIDENT) type = GL2PS_IN_BACK_OF;
1397 else if(type != GL2PS_IN_BACK_OF) type = GL2PS_SPANNING;
1398 if(d[i] < -GL2PS_EPSILON){
1401 type = GL2PS_SPANNING;
1405 else if(d[j] < -GL2PS_EPSILON){
1406 if(type == GL2PS_COINCIDENT) type = GL2PS_IN_FRONT_OF;
1407 else if(type != GL2PS_IN_FRONT_OF) type = GL2PS_SPANNING;
1408 if(d[i] > GL2PS_EPSILON){
1411 type = GL2PS_SPANNING;
1423 if(type == GL2PS_SPANNING){
1424 *back = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1425 *front = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1434 GL2PSprimitive **
t1, GL2PSprimitive **
t2)
1436 *t1 = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1437 *t2 = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1439 (*t1)->numverts = (*t2)->numverts = 3;
1440 (*t1)->culled = (*t2)->culled = quad->culled;
1441 (*t1)->offset = (*t2)->offset = quad->offset;
1442 (*t1)->ofactor = (*t2)->ofactor = quad->ofactor;
1443 (*t1)->ounits = (*t2)->ounits = quad->ounits;
1444 (*t1)->pattern = (*t2)->pattern = quad->pattern;
1445 (*t1)->factor = (*t2)->factor = quad->factor;
1446 (*t1)->width = (*t2)->width = quad->width;
1447 (*t1)->linecap = (*t2)->linecap = quad->linecap;
1448 (*t1)->linejoin = (*t2)->linejoin = quad->linejoin;
1451 (*t1)->verts[0] = quad->verts[0];
1452 (*t1)->verts[1] = quad->verts[1];
1453 (*t1)->verts[2] = quad->verts[2];
1454 (*t1)->boundary = ((quad->boundary & 1) ? 1 : 0) | ((quad->boundary & 2) ? 2 : 0);
1455 (*t2)->verts[0] = quad->verts[0];
1456 (*t2)->verts[1] = quad->verts[2];
1457 (*t2)->verts[2] = quad->verts[3];
1458 (*t2)->boundary = ((quad->boundary & 4) ? 2 : 0) | ((quad->boundary & 8) ? 4 : 0);
1463 const GL2PSprimitive *q, *
w;
1464 GLfloat dq = 0.0F, dw = 0.0F, diff;
1467 q = *(
const GL2PSprimitive*
const*)a;
1468 w = *(
const GL2PSprimitive*
const*)b;
1470 for(i = 0; i < q->numverts; i++){
1471 dq += q->verts[i].xyz[2];
1473 dq /= (GLfloat)q->numverts;
1475 for(i = 0; i < w->numverts; i++){
1476 dw += w->verts[i].xyz[2];
1478 dw /= (GLfloat)w->numverts;
1494 const GL2PSprimitive *q, *
w;
1496 q = *(
const GL2PSprimitive*
const*)a;
1497 w = *(
const GL2PSprimitive*
const*)b;
1498 return (q->type < w->type ? 1 : -1);
1501 static GLint
gl2psFindRoot(GL2PSlist *primitives, GL2PSprimitive **root)
1503 GLint i, j, count, best = 1000000, idx = 0;
1504 GL2PSprimitive *prim1, *prim2;
1517 if(maxp >
gl2ps->maxbestroot){
1518 maxp =
gl2ps->maxbestroot;
1520 for(i = 0; i < maxp; i++){
1529 if(count > best)
break;
1535 if(!count)
return idx;
1548 GL2PSimagemap *next;
1549 while(list != NULL){
1562 q = *(GL2PSprimitive**)data;
1575 GL2PSprimitive *
t1, *
t2;
1593 if((*tree)->primitives){
1605 if(f1 > f2)
return GL_TRUE;
1606 else return GL_FALSE;
1609 static GLboolean
gl2psLess(GLfloat f1, GLfloat f2)
1611 if(f1 < f2)
return GL_TRUE;
1612 else return GL_FALSE;
1617 GL2PSprimitive *prim = NULL, *frontprim = NULL, *backprim = NULL;
1618 GL2PSlist *frontlist, *backlist;
1635 case GL2PS_COINCIDENT:
1638 case GL2PS_IN_BACK_OF:
1641 case GL2PS_IN_FRONT_OF:
1644 case GL2PS_SPANNING:
1659 tree->front = (GL2PSbsptree*)
gl2psMalloc(
sizeof(GL2PSbsptree));
1668 tree->back = (GL2PSbsptree*)
gl2psMalloc(
sizeof(GL2PSbsptree));
1679 GLboolean (*
compare)(GLfloat f1, GLfloat f2),
1680 void (*action)(
void *data),
int inverse)
1688 if(GL_TRUE ==
compare(result, epsilon)){
1698 else if(GL_TRUE ==
compare(-epsilon, result)){
1716 GL2PSprimitive *prim;
1717 GLfloat minZ,
maxZ, rangeZ, scaleZ;
1718 GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ;
1726 minZ = maxZ = prim->verts[0].xyz[2];
1727 for(i = 1; i < prim->numverts; i++){
1728 if(prim->verts[i].xyz[2] < minZ) minZ = prim->verts[i].xyz[2];
1729 if(prim->verts[i].xyz[2] > maxZ) maxZ = prim->verts[i].xyz[2];
1733 for(j = 0; j < prim->numverts; j++){
1734 if(prim->verts[j].xyz[2] < minZ) minZ = prim->verts[j].xyz[2];
1735 if(prim->verts[j].xyz[2] > maxZ) maxZ = prim->verts[j].xyz[2];
1738 rangeZ = (maxZ - minZ);
1742 scaleZ = GL2PS_ZERO(rangeZ) ? GL2PS_ZSCALE : (GL2PS_ZSCALE / rangeZ);
1744 if(scaleZ > 100000.F) scaleZ = 100000.F;
1749 for(j = 0; j < prim->numverts; j++){
1750 prim->verts[j].xyz[2] = (prim->verts[j].xyz[2] - minZ) * scaleZ;
1755 prim->verts[0].xyz[2] -= GL2PS_ZOFFSET_LARGE;
1756 prim->verts[1].xyz[2] -= GL2PS_ZOFFSET_LARGE;
1759 prim->verts[0].xyz[2] -= GL2PS_ZOFFSET;
1760 prim->verts[1].xyz[2] -= GL2PS_ZOFFSET;
1764 factor = prim->ofactor;
1765 units = prim->ounits;
1767 (prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) *
1768 (prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) -
1769 (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) *
1770 (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]);
1771 if(!GL2PS_ZERO(area)){
1773 ((prim->verts[2].xyz[1] - prim->verts[1].xyz[1]) *
1774 (prim->verts[1].xyz[2] - prim->verts[0].xyz[2]) -
1775 (prim->verts[1].xyz[1] - prim->verts[0].xyz[1]) *
1776 (prim->verts[2].xyz[2] - prim->verts[1].xyz[2])) / area;
1778 ((prim->verts[1].xyz[0] - prim->verts[0].xyz[0]) *
1779 (prim->verts[2].xyz[2] - prim->verts[1].xyz[2]) -
1780 (prim->verts[2].xyz[0] - prim->verts[1].xyz[0]) *
1781 (prim->verts[1].xyz[2] - prim->verts[0].xyz[2])) / area;
1782 maxdZ = (GLfloat)sqrt(dZdX * dZdX + dZdY * dZdY);
1787 dZ = factor * maxdZ + units;
1788 prim->verts[0].xyz[2] += dZ;
1789 prim->verts[1].xyz[2] += dZ;
1790 prim->verts[2].xyz[2] += dZ;
1805 plane[0] = b[1] - a[1];
1806 plane[1] = a[0] - b[0];
1807 n = (GLfloat)sqrt(plane[0]*plane[0] + plane[1]*plane[1]);
1812 plane[3] = -plane[0]*a[0]-plane[1]*a[1];
1838 if(pt_dis > GL2PS_EPSILON)
return GL2PS_POINT_INFRONT;
1839 else if(pt_dis < -GL2PS_EPSILON)
return GL2PS_POINT_BACK;
1840 else return GL2PS_POINT_COINCIDENT;
1844 GL2PSbsptree2d **tree)
1849 GL2PSbsptree2d *head = NULL, *cur = NULL;
1851 if((*tree == NULL) && (prim->numverts > 2)){
1856 head = (GL2PSbsptree2d*)
gl2psMalloc(
sizeof(GL2PSbsptree2d));
1857 for(i = 0; i < prim->numverts-1; i++){
1859 prim->verts[i+1].xyz,
1861 if(prim->numverts-i > 3){
1875 for(i = 2+offset; i < prim->numverts; i++){
1877 if(ret != GL2PS_POINT_COINCIDENT)
break;
1880 case GL2PS_POINT_INFRONT :
1882 for(i = 1+offset; i < prim->numverts-1; i++){
1883 if(cur->front == NULL){
1884 cur->front = (GL2PSbsptree2d*)
gl2psMalloc(
sizeof(GL2PSbsptree2d));
1887 prim->verts[i+1].xyz,
1888 cur->front->plane)){
1894 if(cur->front == NULL){
1895 cur->front = (GL2PSbsptree2d*)
gl2psMalloc(
sizeof(GL2PSbsptree2d));
1898 prim->verts[offset].xyz,
1899 cur->front->plane)){
1900 cur->front->front = NULL;
1901 cur->front->back = NULL;
1908 case GL2PS_POINT_BACK :
1909 for(i = 0; i < 4; i++){
1910 head->plane[i] = -head->plane[i];
1913 for(i = 1+offset; i < prim->numverts-1; i++){
1914 if(cur->front == NULL){
1915 cur->front = (GL2PSbsptree2d*)
gl2psMalloc(
sizeof(GL2PSbsptree2d));
1919 cur->front->plane)){
1925 if(cur->front == NULL){
1926 cur->front = (GL2PSbsptree2d*)
gl2psMalloc(
sizeof(GL2PSbsptree2d));
1930 cur->front->plane)){
1931 cur->front->front = NULL;
1932 cur->front->back = NULL;
1953 for(i = 1; i < prim->numverts; i++){
1955 if(pos == (GL2PS_POINT_INFRONT | GL2PS_POINT_BACK))
return GL2PS_SPANNING;
1957 if(pos & GL2PS_POINT_INFRONT)
return GL2PS_IN_FRONT_OF;
1958 else if(pos & GL2PS_POINT_BACK)
return GL2PS_IN_BACK_OF;
1959 else return GL2PS_COINCIDENT;
1967 GL2PSprimitive *child = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
1971 child->data.image = parent->data.image;
1982 child->boundary = 0;
1983 child->culled = parent->culled;
1984 child->offset = parent->offset;
1985 child->ofactor = parent->ofactor;
1986 child->ounits = parent->ounits;
1987 child->pattern = parent->pattern;
1988 child->factor = parent->factor;
1989 child->width = parent->width;
1990 child->linecap = parent->linecap;
1991 child->linejoin = parent->linejoin;
1992 child->numverts = numverts;
1994 for(i = 0; i < numverts; i++){
1995 child->verts[i] = vertx[i];
2002 GL2PSprimitive **front,
2003 GL2PSprimitive **back)
2010 GLint cur = -1, prev = -1, i,
v1 = 0,
v2 = 0, flag = 1, prev0 = -1;
2013 GL2PSvertex *front_list = NULL, *back_list = NULL;
2016 GLshort front_count = 0, back_count = 0;
2018 for(i = 0; i <= prim->numverts; i++){
2020 if(v1 == prim->numverts){
2021 if(prim->numverts < 3)
break;
2023 v2 = prim->numverts - 1;
2032 if(((prev == -1) || (prev == cur) || (prev == 0) || (cur == 0)) &&
2033 (i < prim->numverts)){
2034 if(cur == GL2PS_POINT_INFRONT){
2038 front_list[front_count-1] = prim->verts[
v1];
2040 else if(cur == GL2PS_POINT_BACK){
2044 back_list[back_count-1] = prim->verts[
v1];
2050 front_list[front_count-1] = prim->verts[
v1];
2054 back_list[back_count-1] = prim->verts[
v1];
2058 else if((prev != cur) && (cur != 0) && (prev != 0)){
2067 plane, &front_list[front_count-1]);
2071 back_list[back_count-1] = front_list[front_count-1];
2085 GL2PSprimitive *frontprim = NULL, *backprim = NULL;
2105 case GL2PS_IN_FRONT_OF:
2108 case GL2PS_SPANNING:
2111 if((*tree)->front != NULL){
2121 case GL2PS_COINCIDENT:
2122 if((*tree)->back != NULL){
2123 gl2ps->zerosurfacearea = GL_TRUE;
2125 gl2ps->zerosurfacearea = GL_FALSE;
2128 if((*tree)->front != NULL){
2129 gl2ps->zerosurfacearea = GL_TRUE;
2131 gl2ps->zerosurfacearea = GL_FALSE;
2143 GL2PSprimitive *prim = *(GL2PSprimitive **)data;
2144 gl2ps->primitivetoadd = prim;
2164 c[0] = c[1] = c[2] = 0.0F;
2165 for(i = 0; i < prim->numverts; i++){
2166 c[0] += prim->verts[i].xyz[0];
2167 c[1] += prim->verts[i].xyz[1];
2169 c[0] /= prim->numverts;
2170 c[1] /= prim->numverts;
2172 for(i = 0; i < prim->numverts; i++){
2173 if(prim->boundary & (GLint)pow(2., i)){
2174 b = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
2176 b->offset = prim->offset;
2177 b->ofactor = prim->ofactor;
2178 b->ounits = prim->ounits;
2179 b->pattern = prim->pattern;
2180 b->factor = prim->factor;
2181 b->culled = prim->culled;
2182 b->width = prim->width;
2183 b->linecap = prim->linecap;
2184 b->linejoin = prim->linejoin;
2190 v[0] = c[0] - prim->verts[i].xyz[0];
2191 v[1] = c[1] - prim->verts[i].xyz[1];
2196 b->verts[0].xyz[0] = prim->verts[i].xyz[0] +0.1*v[0];
2197 b->verts[0].xyz[1] = prim->verts[i].xyz[1] +0.1*v[1];
2198 b->verts[0].xyz[2] = prim->verts[i].xyz[2];
2199 v[0] = c[0] - prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[0];
2200 v[1] = c[1] - prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[1];
2204 b->verts[1].xyz[0] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[0] +0.1*v[0];
2205 b->verts[1].xyz[1] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[1] +0.1*v[1];
2206 b->verts[1].xyz[2] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[2];
2208 b->verts[0].xyz[0] = prim->verts[i].xyz[0];
2209 b->verts[0].xyz[1] = prim->verts[i].xyz[1];
2210 b->verts[0].xyz[2] = prim->verts[i].xyz[2];
2211 b->verts[1].xyz[0] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[0];
2212 b->verts[1].xyz[1] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[1];
2213 b->verts[1].xyz[2] = prim->verts[
gl2psGetIndex(i, prim->numverts)].xyz[2];
2216 b->verts[0].rgba[0] = 0.0F;
2217 b->verts[0].rgba[1] = 0.0F;
2218 b->verts[0].rgba[2] = 0.0F;
2219 b->verts[0].rgba[3] = 0.0F;
2220 b->verts[1].rgba[0] = 0.0F;
2221 b->verts[1].rgba[1] = 0.0F;
2222 b->verts[1].rgba[2] = 0.0F;
2223 b->verts[1].rgba[3] = 0.0F;
2233 GL2PSprimitive *prim;
2252 GLfloat ofactor, GLfloat ounits,
2253 GLushort pattern, GLint factor,
2254 GLfloat width, GLint linecap,
2255 GLint linejoin,
char boundary)
2257 GL2PSprimitive *prim;
2259 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
2261 prim->numverts = numverts;
2263 memcpy(prim->verts, verts, numverts *
sizeof(
GL2PSvertex));
2264 prim->boundary = boundary;
2265 prim->offset = (char)offset;
2266 prim->ofactor = ofactor;
2267 prim->ounits = ounits;
2268 prim->pattern = pattern;
2269 prim->factor = factor;
2270 prim->width = width;
2271 prim->linecap = linecap;
2272 prim->linejoin = linejoin;
2289 if(
gl2ps->colormode == GL_COLOR_INDEX &&
gl2ps->colorsize > 0){
2290 i = (GLint)(p[3] + 0.5);
2309 GLushort pattern = 0;
2311 GLint i, sizeoffloat, count,
v, vtot, offset = 0, factor = 0, auxindex = 0;
2312 GLint lcap = 0, ljoin = 0;
2313 GLfloat lwidth = 1.0F, psize = 1.0F, ofactor = 0.0F, ounits = 0.0F;
2316 GL2PSprimitive *prim;
2317 GL2PSimagemap *node;
2319 current =
gl2ps->feedback;
2320 boundary =
gl2ps->boundary = GL_FALSE;
2324 if(GL_TRUE == boundary)
gl2ps->boundary = GL_TRUE;
2326 switch((GLint)*current){
2327 case GL_POINT_TOKEN :
2334 pattern, factor, psize, lcap, ljoin, 0);
2336 case GL_LINE_TOKEN :
2337 case GL_LINE_RESET_TOKEN :
2347 pattern, factor, lwidth, lcap, ljoin, 0);
2349 case GL_POLYGON_TOKEN :
2350 count = (GLint)current[1];
2354 while(count > 0 && used > 0){
2362 if(GL_TRUE == boundary){
2363 if(!count && vtot == 2) flag = 1|2|4;
2364 else if(!count) flag = 2|4;
2365 else if(vtot == 2) flag = 1|2;
2371 ounits, pattern, factor, 1, lcap, ljoin,
2373 vertices[1] = vertices[2];
2379 case GL_BITMAP_TOKEN :
2380 case GL_DRAW_PIXEL_TOKEN :
2381 case GL_COPY_PIXEL_TOKEN :
2388 case GL_PASS_THROUGH_TOKEN :
2389 switch((GLint)current[1]){
2390 case GL2PS_BEGIN_OFFSET_TOKEN :
2394 ofactor = current[1];
2397 ounits = current[1];
2399 case GL2PS_END_OFFSET_TOKEN :
2404 case GL2PS_BEGIN_BOUNDARY_TOKEN : boundary = GL_TRUE;
break;
2405 case GL2PS_END_BOUNDARY_TOKEN : boundary = GL_FALSE;
break;
2406 case GL2PS_END_STIPPLE_TOKEN : pattern = 0; factor = 0;
break;
2407 case GL2PS_BEGIN_BLEND_TOKEN :
gl2ps->blending = GL_TRUE;
break;
2408 case GL2PS_END_BLEND_TOKEN :
gl2ps->blending = GL_FALSE;
break;
2409 case GL2PS_BEGIN_STIPPLE_TOKEN :
2412 pattern = (GLushort)current[1];
2415 factor = (GLint)current[1];
2417 case GL2PS_SRC_BLEND_TOKEN :
2420 gl2ps->blendfunc[0] = (GLint)current[1];
2422 case GL2PS_DST_BLEND_TOKEN :
2425 gl2ps->blendfunc[1] = (GLint)current[1];
2427 case GL2PS_POINT_SIZE_TOKEN :
2432 case GL2PS_LINE_CAP_TOKEN :
2437 case GL2PS_LINE_JOIN_TOKEN :
2442 case GL2PS_LINE_WIDTH_TOKEN :
2445 lwidth = current[1];
2447 case GL2PS_IMAGEMAP_TOKEN :
2448 prim = (GL2PSprimitive *)
gl2psMalloc(
sizeof(GL2PSprimitive));
2455 prim->ofactor = 0.0;
2461 node = (GL2PSimagemap*)
gl2psMalloc(
sizeof(GL2PSimagemap));
2462 node->image = (GL2PSimage*)
gl2psMalloc(
sizeof(GL2PSimage));
2463 node->image->type = 0;
2464 node->image->format = 0;
2465 node->image->zoom_x = 1.0F;
2466 node->image->zoom_y = 1.0F;
2469 if(
gl2ps->imagemap_head == NULL)
2470 gl2ps->imagemap_head = node;
2472 gl2ps->imagemap_tail->next = node;
2473 gl2ps->imagemap_tail = node;
2474 prim->data.image = node->image;
2476 current += 2; used -= 2;
2478 current += i; used -= i;
2480 node->image->width = (GLint)current[2];
2481 current += 2; used -= 2;
2482 node->image->height = (GLint)current[2];
2483 prim->verts[0].xyz[0] = prim->verts[0].xyz[0] - (
int)(node->image->width / 2) + 0.5F;
2484 prim->verts[0].xyz[1] = prim->verts[0].xyz[1] - (
int)(node->image->height / 2) + 0.5F;
2485 for(i = 1; i < 4; i++){
2486 for(v = 0; v < 3; v++){
2487 prim->verts[i].xyz[
v] = prim->verts[0].xyz[
v];
2488 prim->verts[i].rgba[
v] = prim->verts[0].rgba[
v];
2490 prim->verts[i].rgba[
v] = prim->verts[0].rgba[
v];
2492 prim->verts[1].xyz[0] = prim->verts[1].xyz[0] + node->image->width;
2493 prim->verts[2].xyz[0] = prim->verts[1].xyz[0];
2494 prim->verts[2].xyz[1] = prim->verts[2].xyz[1] + node->image->height;
2495 prim->verts[3].xyz[1] = prim->verts[2].xyz[1];
2497 sizeoffloat =
sizeof(GLfloat);
2498 v = 2 * sizeoffloat;
2499 vtot = node->image->height + node->image->height *
2500 ((node->image->width - 1) / 8);
2501 node->image->pixels = (GLfloat*)
gl2psMalloc(v + vtot);
2502 node->image->pixels[0] = prim->verts[0].xyz[0];
2503 node->image->pixels[1] = prim->verts[0].xyz[1];
2505 for(i = 0; i < vtot; i += sizeoffloat){
2506 current += 2; used -= 2;
2508 memcpy(&(((
char*)(node->image->pixels))[i +
v]), &(current[2]), sizeoffloat);
2510 memcpy(&(((
char*)(node->image->pixels))[i + v]), &(current[2]), vtot - i);
2515 case GL2PS_DRAW_PIXELS_TOKEN :
2516 case GL2PS_TEXT_TOKEN :
2546 unsigned char h = byte / 16;
2547 unsigned char l = byte % 16;
2553 GLuint nbhex, nbyte, nrgb, nbits;
2554 GLuint row,
col, ibyte, icase;
2555 GLfloat dr = 0., dg = 0., db = 0., fgrey;
2556 unsigned char red = 0, green = 0, blue = 0,
b, grey;
2557 GLuint width = (GLuint)im->width;
2558 GLuint height = (GLuint)im->height;
2565 if((width <= 0) || (height <= 0))
return;
2569 gl2psPrintf(
"%.2f %.2f scale\n", width * im->zoom_x, height * im->zoom_y);
2574 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2575 gl2psPrintf(
"{ currentfile picstr readhexstring pop }\n");
2577 for(row = 0; row < height; row++){
2578 for(col = 0; col < width; col++){
2580 fgrey = (0.30F * dr + 0.59F * dg + 0.11F *
db);
2581 grey = (
unsigned char)(255. * fgrey);
2586 nbhex = width * height * 2;
2591 nbits = nrgb * nbit;
2593 if((nbyte * 8) != nbits) nbyte++;
2596 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2597 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2600 for(row = 0; row < height; row++){
2604 for(ibyte = 0; ibyte < nbyte; ibyte++){
2613 red = (
unsigned char)(3. * dr);
2614 green = (
unsigned char)(3. * dg);
2615 blue = (
unsigned char)(3. * db);
2626 red = (
unsigned char)(3. * dr);
2627 green = (
unsigned char)(3. * dg);
2628 blue = (
unsigned char)(3. * db);
2634 else if(icase == 2) {
2644 red = (
unsigned char)(3. * dr);
2645 green = (
unsigned char)(3. * dg);
2646 blue = (
unsigned char)(3. * db);
2653 else if(icase == 3) {
2662 red = (
unsigned char)(3. * dr);
2663 green = (
unsigned char)(3. * dg);
2664 blue = (
unsigned char)(3. * db);
2678 nbits = nrgb * nbit;
2680 if((nbyte * 8) != nbits) nbyte++;
2683 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2684 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2687 for(row = 0; row < height; row++){
2690 for(ibyte = 0; ibyte < nbyte; ibyte++){
2699 red = (
unsigned char)(15. * dr);
2700 green = (
unsigned char)(15. * dg);
2704 else if(icase == 2) {
2705 blue = (
unsigned char)(15. * db);
2713 red = (
unsigned char)(15. * dr);
2717 else if(icase == 3) {
2718 green = (
unsigned char)(15. * dg);
2719 blue = (
unsigned char)(15. * db);
2731 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2732 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2735 for(row = 0; row < height; row++){
2736 for(col = 0; col < width; col++){
2738 red = (
unsigned char)(255. * dr);
2740 green = (
unsigned char)(255. * dg);
2742 blue = (
unsigned char)(255. * db);
2753 GLsizei width, GLsizei height,
2754 const unsigned char *imagemap){
2757 if((width <= 0) || (height <= 0))
return;
2759 size = height + height * (width - 1) / 8;
2763 gl2psPrintf(
"%d %d scale\n%d %d\ntrue\n", width, height,width, height);
2764 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ] {<", width, height);
2765 for(i = 0; i < size; i++){
2791 "%%%%Creator: GL2PS %d.%d.%d%s, %s\n"
2793 "%%%%CreationDate: \n"
2794 "%%%%LanguageLevel: 3\n"
2795 "%%%%DocumentData: Clean7Bit\n"
2803 "%%%%DocumentMedia: Default %d %d 0 () ()\n",
2806 (
int)
gl2ps->viewport[2],
2808 (
int)
gl2ps->viewport[3]);
2812 "%%%%EndComments\n",
2814 (
int)
gl2ps->viewport[0],
2816 (
int)
gl2ps->viewport[1],
2818 (
int)
gl2ps->viewport[2],
2820 (
int)
gl2ps->viewport[3]);
2836 "/gl2psdict 64 dict def gl2psdict begin\n"
2837 "/tryPS3shading %s def %% set to false to force subdivision\n"
2838 "/rThreshold %g def %% red component subdivision threshold\n"
2839 "/gThreshold %g def %% green component subdivision threshold\n"
2840 "/bThreshold %g def %% blue component subdivision threshold\n",
2845 "/C { setrgbcolor } BD\n"
2846 "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n"
2847 "/W { setlinewidth } BD\n"
2848 "/LC { setlinecap } BD\n"
2849 "/LJ { setlinejoin } BD\n");
2851 gl2psPrintf(
"/FC { findfont exch /SH exch def SH scalefont setfont } BD\n"
2852 "/SW { dup stringwidth pop } BD\n"
2853 "/S { FC moveto show } BD\n"
2854 "/SBC{ FC moveto SW -2 div 0 rmoveto show } BD\n"
2855 "/SBR{ FC moveto SW neg 0 rmoveto show } BD\n"
2856 "/SCL{ FC moveto 0 SH -2 div rmoveto show } BD\n"
2857 "/SCC{ FC moveto SW -2 div SH -2 div rmoveto show } BD\n"
2858 "/SCR{ FC moveto SW neg SH -2 div rmoveto show } BD\n"
2859 "/STL{ FC moveto 0 SH neg rmoveto show } BD\n"
2860 "/STC{ FC moveto SW -2 div SH neg rmoveto show } BD\n"
2861 "/STR{ FC moveto SW neg SH neg rmoveto show } BD\n");
2866 "/SR { gsave FCT moveto rotate show grestore } BD\n"
2867 "/SBCR{ gsave FCT moveto rotate SW -2 div 0 rmoveto show grestore } BD\n"
2868 "/SBRR{ gsave FCT moveto rotate SW neg 0 rmoveto show grestore } BD\n"
2869 "/SCLR{ gsave FCT moveto rotate 0 SH -2 div rmoveto show grestore} BD\n");
2870 gl2psPrintf(
"/SCCR{ gsave FCT moveto rotate SW -2 div SH -2 div rmoveto show grestore} BD\n"
2871 "/SCRR{ gsave FCT moveto rotate SW neg SH -2 div rmoveto show grestore} BD\n"
2872 "/STLR{ gsave FCT moveto rotate 0 SH neg rmoveto show grestore } BD\n"
2873 "/STCR{ gsave FCT moveto rotate SW -2 div SH neg rmoveto show grestore } BD\n"
2874 "/STRR{ gsave FCT moveto rotate SW neg SH neg rmoveto show grestore } BD\n");
2876 gl2psPrintf(
"/P { newpath 0.0 360.0 arc closepath fill } BD\n"
2877 "/LS { newpath moveto } BD\n"
2878 "/L { lineto } BD\n"
2879 "/LE { lineto stroke } BD\n"
2880 "/T { newpath moveto lineto lineto closepath fill } BD\n");
2886 " /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n"
2887 " /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n"
2888 " /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n"
2889 " gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n"
2890 " /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] >>\n"
2891 " shfill grestore } BD\n");
2897 "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n"
2899 " 3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n"
2901 " 3 -1 roll 6 -1 roll 9 -1 roll add add 3 div"
2911 " 4 index 15 index add 0.5 mul\n"
2912 " 4 index 15 index add 0.5 mul\n"
2913 " 4 index 15 index add 0.5 mul\n"
2914 " 4 index 15 index add 0.5 mul\n"
2915 " 4 index 15 index add 0.5 mul\n"
2916 " 5 copy 5 copy 25 15 roll\n");
2921 " 9 index 30 index add 0.5 mul\n"
2922 " 9 index 30 index add 0.5 mul\n"
2923 " 9 index 30 index add 0.5 mul\n"
2924 " 9 index 30 index add 0.5 mul\n"
2925 " 5 copy 5 copy 35 5 roll 25 5 roll 15 5 roll\n");
2930 " 4 index 10 index add 0.5 mul\n"
2931 " 4 index 10 index add 0.5 mul\n"
2932 " 4 index 10 index add 0.5 mul\n"
2933 " 4 index 10 index add 0.5 mul\n"
2934 " 5 copy 5 copy 40 5 roll 25 5 roll 15 5 roll 25 5 roll\n");
2938 gl2psPrintf(
" STnoshfill STnoshfill STnoshfill STnoshfill } BD\n");
2945 " 2 index 8 index sub abs rThreshold gt\n"
2947 " { 1 index 7 index sub abs gThreshold gt\n"
2949 " { dup 6 index sub abs bThreshold gt\n"
2951 " { 2 index 13 index sub abs rThreshold gt\n"
2953 " { 1 index 12 index sub abs gThreshold gt\n"
2955 " { dup 11 index sub abs bThreshold gt\n"
2957 " { 7 index 13 index sub abs rThreshold gt\n");
2959 " { 6 index 12 index sub abs gThreshold gt\n"
2961 " { 5 index 11 index sub abs bThreshold gt\n"
2976 " { /ST { STshfill } BD }\n"
2977 " { /ST { STnoshfill } BD }\n"
2979 "{ /ST { STnoshfill } BD }\n"
2985 "/DeviceRGB setcolorspace\n"
2989 "%%%%BeginPageSetup\n");
2993 (
int)
gl2ps->viewport[3]);
3003 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3006 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[1], (
int)
gl2ps->viewport[2],
3007 (
int)
gl2ps->viewport[1], (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[3],
3008 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[3]);
3016 gl2psPrintf(
"%g %g %g C\n", rgba[0], rgba[1], rgba[2]);
3028 if(
gl2ps->lastvertex.rgba[0] >= 0.){
3030 for(i = 0; i < 3; i++)
3031 gl2ps->lastvertex.xyz[i] = -1.;
3032 for(i = 0; i < 4; i++)
3033 gl2ps->lastvertex.rgba[i] = -1.;
3038 int *nb,
int array[10])
3041 int on[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3042 int off[8] = {0, 0, 0, 0, 0, 0, 0, 0};
3046 for(n = 15; n >= 0; n--){
3047 tmp[
n] = (char)(pattern & 0x01);
3052 for(i = 0; i < 8; i++){
3053 while(n < 16 && !tmp[n]){ off[i]++; n++; }
3054 while(n < 16 && tmp[n]){ on[i]++; n++; }
3055 if(n >= 15){ i++;
break; }
3064 for(n = i - 1; n >= 0; n--){
3065 array[(*nb)++] = factor * on[
n];
3066 array[(*nb)++] = factor * off[
n];
3067 if(*nb == 10)
break;
3073 int len = 0, i,
n, array[10];
3075 if(pattern ==
gl2ps->lastpattern && factor ==
gl2ps->lastfactor)
3078 gl2ps->lastpattern = pattern;
3079 gl2ps->lastfactor = factor;
3081 if(!pattern || !factor){
3088 for(i = 0; i <
n; i++){
3101 GL2PSprimitive *prim;
3103 prim = *(GL2PSprimitive**)data;
3118 prim->verts[0].xyz[0], prim->verts[0].xyz[1], 0.5 * prim->width);
3123 gl2ps->lastlinewidth != prim->width ||
3124 gl2ps->lastlinecap != prim->linecap ||
3125 gl2ps->lastlinejoin != prim->linejoin ||
3126 gl2ps->lastpattern != prim->pattern ||
3127 gl2ps->lastfactor != prim->factor){
3140 if(
gl2ps->lastlinewidth != prim->width){
3141 gl2ps->lastlinewidth = prim->width;
3144 if(
gl2ps->lastlinecap != prim->linecap){
3145 gl2ps->lastlinecap = prim->linecap;
3148 if(
gl2ps->lastlinejoin != prim->linejoin){
3149 gl2ps->lastlinejoin = prim->linejoin;
3154 gl2psPrintf(
"%g %g %s\n", prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3155 newline ?
"LS" :
"L");
3156 gl2ps->lastvertex = prim->verts[1];
3161 gl2psPrintf(
"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n",
3162 prim->verts[2].xyz[0], prim->verts[2].xyz[1],
3163 prim->verts[2].rgba[0], prim->verts[2].rgba[1],
3164 prim->verts[2].rgba[2], prim->verts[1].xyz[0],
3165 prim->verts[1].xyz[1], prim->verts[1].rgba[0],
3166 prim->verts[1].rgba[1], prim->verts[1].rgba[2],
3167 prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3168 prim->verts[0].rgba[0], prim->verts[0].rgba[1],
3169 prim->verts[0].rgba[2]);
3174 prim->verts[2].xyz[0], prim->verts[2].xyz[1],
3175 prim->verts[1].xyz[0], prim->verts[1].xyz[1],
3176 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3190 prim->data.image->pixels[1],
3191 prim->data.image->width, prim->data.image->height,
3192 (
const unsigned char*)(&(prim->data.image->pixels[2])));
3199 if(prim->data.text->angle)
3202 prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3203 prim->data.text->fontsize, prim->data.text->fontname);
3204 switch(prim->data.text->alignment){
3206 gl2psPrintf(prim->data.text->angle ?
"SCCR\n" :
"SCC\n");
3209 gl2psPrintf(prim->data.text->angle ?
"SCLR\n" :
"SCL\n");
3212 gl2psPrintf(prim->data.text->angle ?
"SCRR\n" :
"SCR\n");
3215 gl2psPrintf(prim->data.text->angle ?
"SBCR\n" :
"SBC\n");
3218 gl2psPrintf(prim->data.text->angle ?
"SBRR\n" :
"SBR\n");
3221 gl2psPrintf(prim->data.text->angle ?
"STCR\n" :
"STC\n");
3224 gl2psPrintf(prim->data.text->angle ?
"STLR\n" :
"STL\n");
3227 gl2psPrintf(prim->data.text->angle ?
"STRR\n" :
"STR\n");
3231 gl2psPrintf(prim->data.text->angle ?
"SR\n" :
"S\n");
3238 if(prim->data.text->alignment ==
GL2PS_PS ||
3239 prim->data.text->alignment ==
GL2PS_EPS)
3264 int x = viewport[0], y = viewport[1], w = viewport[2],
h = viewport[3];
3266 glRenderMode(GL_FEEDBACK);
3270 gl2ps->header = GL_FALSE;
3274 gl2psResetLineProperties();
3280 if(
gl2ps->colormode == GL_RGBA ||
gl2ps->colorsize == 0){
3281 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
3284 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
3291 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3293 rgba[0], rgba[1], rgba[2],
3294 x, y, x+w, y, x+w, y+h, x, y+h);
3297 gl2psPrintf(
"newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3299 x, y, x+w, y, x+w, y+h, x, y+h);
3320 static GL2PSbackend gl2psPS = {
3331 static GL2PSbackend gl2psEPS = {
3339 "Encapsulated Postscript"
3354 if(
gl2ps->filename && strlen(
gl2ps->filename) < 256){
3355 for(i = (
int)strlen(
gl2ps->filename) - 1; i >= 0; i--){
3356 if(
gl2ps->filename[i] ==
'.'){
3357 strncpy(name,
gl2ps->filename, i);
3362 if(i <= 0) strcpy(name,
gl2ps->filename);
3365 strcpy(name,
"untitled");
3370 fprintf(
gl2ps->stream,
3372 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
3374 "%% CreationDate: %s\n",
3377 gl2ps->producer, ctime(&now));
3379 fprintf(
gl2ps->stream,
3380 "\\setlength{\\unitlength}{1pt}\n"
3381 "\\begin{picture}(0,0)\n"
3382 "\\includegraphics{%s}\n"
3383 "\\end{picture}%%\n"
3384 "%s\\begin{picture}(%d,%d)(0,0)\n",
3386 (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[3]);
3391 GL2PSprimitive *prim;
3393 prim = *(GL2PSprimitive**)data;
3397 fprintf(
gl2ps->stream,
"\\fontsize{%d}{0}\n\\selectfont",
3398 prim->data.text->fontsize);
3399 fprintf(
gl2ps->stream,
"\\put(%g,%g)",
3400 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3401 if(prim->data.text->angle)
3402 fprintf(
gl2ps->stream,
"{\\rotatebox{%g}", prim->data.text->angle);
3403 fprintf(
gl2ps->stream,
"{\\makebox(0,0)");
3404 switch(prim->data.text->alignment){
3406 fprintf(
gl2ps->stream,
"{");
3409 fprintf(
gl2ps->stream,
"[l]{");
3412 fprintf(
gl2ps->stream,
"[r]{");
3415 fprintf(
gl2ps->stream,
"[b]{");
3418 fprintf(
gl2ps->stream,
"[br]{");
3421 fprintf(
gl2ps->stream,
"[t]{");
3424 fprintf(
gl2ps->stream,
"[tl]{");
3427 fprintf(
gl2ps->stream,
"[tr]{");
3431 fprintf(
gl2ps->stream,
"[bl]{");
3434 fprintf(
gl2ps->stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
3435 prim->verts[0].rgba[0], prim->verts[0].rgba[1], prim->verts[0].rgba[2],
3436 prim->data.text->str);
3437 if(prim->data.text->angle)
3438 fprintf(
gl2ps->stream,
"}");
3439 fprintf(
gl2ps->stream,
"}}\n");
3444 if (prim->data.text->alignment ==
GL2PS_TEX)
3445 fprintf(
gl2ps->stream,
"%s\n", prim->data.text->str);
3454 fprintf(
gl2ps->stream,
"\\end{picture}%s\n",
3461 glRenderMode(GL_FEEDBACK);
3463 gl2psResetLineProperties();
3467 gl2ps->header = GL_FALSE;
3482 static GL2PSbackend gl2psTEX = {
3501 #if defined(GL2PS_HAVE_ZLIB)
3503 return fprintf(
gl2ps->stream,
"/Filter [/FlateDecode]\n");
3514 for(i = 0; i < 3; ++i){
3515 if(GL2PS_ZERO(rgba[i]))
3517 else if(rgba[i] < 1
e-4 || rgba[i] > 1
e6)
3530 for(i = 0; i < 3; ++i){
3531 if(GL2PS_ZERO(rgba[i]))
3533 else if(rgba[i] < 1
e-4 || rgba[i] > 1
e6)
3546 else if(lw < 1e-4 || lw > 1
e6)
3552 static int gl2psPrintPDFLineCap(GLint
lc)
3554 if(
gl2ps->lastlinecap == lc)
3560 static int gl2psPrintPDFLineJoin(GLint lj)
3562 if(
gl2ps->lastlinejoin == lj)
3568 static void gl2psPutPDFText(GL2PSstring *text,
int cnt, GLfloat x, GLfloat y)
3570 GLfloat
rad, crad, srad;
3572 if(text->angle == 0.0F){
3579 cnt, text->fontsize, x, y, text->str);
3582 rad = (GLfloat)(3.141593F * text->angle / 180.0F);
3583 srad = (GLfloat)sin(rad);
3584 crad = (GLfloat)cos(rad);
3588 "%f %f %f %f %f %f Tm\n"
3591 cnt, text->fontsize, crad, srad, -srad, crad, x, y, text->str);
3595 static void gl2psPutPDFSpecial(
int prim,
int sec, GL2PSstring *text)
3601 static void gl2psPutPDFImage(GL2PSimage *image,
int cnt, GLfloat x, GLfloat y)
3605 "%d 0 0 %d %f %f cm\n"
3608 (
int)(image->zoom_x * image->width), (
int)(image->zoom_y * image->height),
3614 gl2ps->objects_stack = 7 + 1;
3615 gl2ps->extgs_stack = 0;
3616 gl2ps->font_stack = 0;
3617 gl2ps->im_stack = 0;
3618 gl2ps->trgroupobjects_stack = 0;
3619 gl2ps->shader_stack = 0;
3620 gl2ps->mshader_stack = 0;
3628 gro->ptrlist = NULL;
3629 gro->fontno = gro->gsno = gro->imno = gro->maskshno = gro->shno
3630 = gro->trgroupno = gro->fontobjno = gro->imobjno = gro->shobjno
3631 = gro->maskshobjno = gro->gsobjno = gro->trgroupobjno = -1;
3639 GL2PSprimitive *p = NULL;
3642 GL2PSrgba lastrgba = {-1.0F, -1.0F, -1.0F, -1.0F};
3643 GLushort lastpattern = 0;
3644 GLint lastfactor = 0;
3645 GLfloat lastwidth = 1;
3646 GLint lastlinecap = 0;
3647 GLint lastlinejoin = 0;
3648 GL2PStriangle lastt, tmpt;
3649 int lastTriangleWasNotSimpleWithSameColor = 0;
3651 if(!
gl2ps->pdfprimlist)
3663 gro.imno =
gl2ps->im_stack++;
3670 gro.fontno =
gl2ps->font_stack++;
3675 if(lasttype != p->type || lastwidth != p->width ||
3676 lastlinecap != p->linecap || lastlinejoin != p->linejoin ||
3677 lastpattern != p->pattern || lastfactor != p->factor ||
3687 lastpattern = p->pattern;
3688 lastfactor = p->factor;
3689 lastwidth = p->width;
3690 lastlinecap = p->linecap;
3691 lastlinejoin = p->linejoin;
3692 lastrgba[0] = p->verts[0].rgba[0];
3693 lastrgba[1] = p->verts[0].rgba[1];
3694 lastrgba[2] = p->verts[0].rgba[2];
3697 if(lasttype != p->type || lastwidth != p->width ||
3707 lastwidth = p->width;
3708 lastrgba[0] = p->verts[0].rgba[0];
3709 lastrgba[1] = p->verts[0].rgba[1];
3710 lastrgba[2] = p->verts[0].rgba[2];
3714 lastTriangleWasNotSimpleWithSameColor =
3715 !(tmpt.prop & T_CONST_COLOR && tmpt.prop & T_ALPHA_1) ||
3717 if(lasttype == p->type && tmpt.prop == lastt.prop &&
3718 lastTriangleWasNotSimpleWithSameColor){
3746 GL2PSprimitive *prim = NULL;
3761 if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_LESS_1){
3762 gro->gsno =
gl2ps->extgs_stack++;
3763 gro->gsobjno =
gl2ps->objects_stack ++;
3765 else if(t.prop & T_CONST_COLOR && t.prop & T_VAR_ALPHA){
3766 gro->gsno =
gl2ps->extgs_stack++;
3767 gro->gsobjno =
gl2ps->objects_stack++;
3768 gro->trgroupno =
gl2ps->trgroupobjects_stack++;
3769 gro->trgroupobjno =
gl2ps->objects_stack++;
3770 gro->maskshno =
gl2ps->mshader_stack++;
3771 gro->maskshobjno =
gl2ps->objects_stack++;
3773 else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_1){
3774 gro->shno =
gl2ps->shader_stack++;
3775 gro->shobjno =
gl2ps->objects_stack++;
3777 else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_LESS_1){
3778 gro->gsno =
gl2ps->extgs_stack++;
3779 gro->gsobjno =
gl2ps->objects_stack++;
3780 gro->shno =
gl2ps->shader_stack++;
3781 gro->shobjno =
gl2ps->objects_stack++;
3783 else if(t.prop & T_VAR_COLOR && t.prop & T_VAR_ALPHA){
3784 gro->gsno =
gl2ps->extgs_stack++;
3785 gro->gsobjno =
gl2ps->objects_stack++;
3786 gro->shno =
gl2ps->shader_stack++;
3787 gro->shobjno =
gl2ps->objects_stack++;
3788 gro->trgroupno =
gl2ps->trgroupobjects_stack++;
3789 gro->trgroupobjno =
gl2ps->objects_stack++;
3790 gro->maskshno =
gl2ps->mshader_stack++;
3791 gro->maskshobjno =
gl2ps->objects_stack++;
3799 int i, j, lastel, count;
3800 GL2PSprimitive *prim = NULL, *prev = NULL;
3804 if(!
gl2ps->pdfgrouplist)
3809 for(i = 0; i < count; ++i){
3823 for(j = 0; j <= lastel; ++j){
3825 gl2ps->streamlength +=
3827 prim->verts[0].xyz[0], prim->verts[0].xyz[1],
3828 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3838 gl2ps->streamlength += gl2psPrintPDFLineCap(prim->linecap);
3839 gl2ps->streamlength += gl2psPrintPDFLineJoin(prim->linejoin);
3843 gl2ps->streamlength +=
3845 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3847 for(j = 1; j <= lastel; ++j){
3854 gl2ps->streamlength +=
3856 prev->verts[1].xyz[0], prev->verts[1].xyz[1]);
3857 gl2ps->streamlength +=
3859 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3864 gl2ps->streamlength +=
3866 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
3870 gl2ps->streamlength +=
3872 prim->verts[1].xyz[0], prim->verts[1].xyz[1]);
3880 if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_1){
3882 for(j = 0; j <= lastel; ++j){
3890 t.vertex[0].xyz[0], t.vertex[0].xyz[1],
3891 t.vertex[1].xyz[0], t.vertex[1].xyz[1],
3892 t.vertex[2].xyz[0], t.vertex[2].xyz[1]);
3897 else if(t.prop & T_CONST_COLOR && t.prop & T_ALPHA_LESS_1){
3902 for(j = 0; j <= lastel; ++j){
3910 t.vertex[0].xyz[0], t.vertex[0].xyz[1],
3911 t.vertex[1].xyz[0], t.vertex[1].xyz[1],
3912 t.vertex[2].xyz[0], t.vertex[2].xyz[1]);
3919 else if(t.prop & T_CONST_COLOR && t.prop & T_VAR_ALPHA){
3923 gro->gsno, gro->trgroupno);
3925 for(j = 0; j <= lastel; ++j){
3933 t.vertex[0].xyz[0], t.vertex[0].xyz[1],
3934 t.vertex[1].xyz[0], t.vertex[1].xyz[1],
3935 t.vertex[2].xyz[0], t.vertex[2].xyz[1]);
3941 else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_1){
3947 else if(t.prop & T_VAR_COLOR && t.prop & T_ALPHA_LESS_1){
3952 gro->gsno, gro->shno);
3957 else if(t.prop & T_VAR_COLOR && t.prop & T_VAR_ALPHA){
3963 gro->gsno, gro->trgroupno, gro->shno);
3967 for(j = 0; j <= lastel; ++j){
3970 prim->verts[0].xyz[1]);
3974 for(j = 0; j <= lastel; ++j){
3978 prim->verts[0].xyz[1]);
3986 for(j = 0; j <= lastel; ++j){
3988 gl2psPutPDFSpecial(i, j, prim->data.text);
4004 offs += fprintf(
gl2ps->stream,
4011 offs += fprintf(
gl2ps->stream,
"/GS%d %d 0 R\n", gro->gsno, gro->gsobjno);
4013 offs += fprintf(
gl2ps->stream,
">>\n");
4025 offs += fprintf(
gl2ps->stream,
4031 offs += fprintf(
gl2ps->stream,
"/Sh%d %d 0 R\n", gro->shno, gro->shobjno);
4032 if(gro->maskshno >= 0)
4033 offs += fprintf(
gl2ps->stream,
"/TrSh%d %d 0 R\n", gro->maskshno, gro->maskshobjno);
4035 offs += fprintf(
gl2ps->stream,
">>\n");
4043 GL2PSprimitive *p = NULL;
4047 offs += fprintf(
gl2ps->stream,
4058 gro->imobjno =
gl2ps->objects_stack++;
4059 if(GL_RGBA == p->data.image->format)
4060 gl2ps->objects_stack++;
4061 offs += fprintf(
gl2ps->stream,
"/Im%d %d 0 R\n", gro->imno, gro->imobjno);
4064 if(gro->trgroupno >=0)
4065 offs += fprintf(
gl2ps->stream,
"/TrG%d %d 0 R\n", gro->trgroupno, gro->trgroupobjno);
4071 offs += fprintf(
gl2ps->stream,
">>\n");
4083 offs += fprintf(
gl2ps->stream,
"/Font\n<<\n");
4089 gro->fontobjno =
gl2ps->objects_stack++;
4090 offs += fprintf(
gl2ps->stream,
"/F%d %d 0 R\n", gro->fontno, gro->fontobjno);
4092 offs += fprintf(
gl2ps->stream,
">>\n");
4100 GL2PSpdfgroup *gro = NULL;
4102 if(!
gl2ps->pdfgrouplist)
4111 gl2ps->pdfgrouplist = NULL;
4123 newtime = gmtime(&now);
4125 offs = fprintf(
gl2ps->stream,
4129 "/Creator (GL2PS %d.%d.%d%s, %s)\n"
4136 offs += fprintf(
gl2ps->stream,
4142 offs += fprintf(
gl2ps->stream,
4143 "/CreationDate (D:%d%02d%02d%02d%02d%02d)\n"
4146 newtime->tm_year+1900,
4159 return fprintf(
gl2ps->stream,
4170 return fprintf(
gl2ps->stream,
4186 offs += fprintf(
gl2ps->stream,
4189 "/Length 5 0 R\n" );
4191 offs += fprintf(
gl2ps->stream,
4208 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[1],
4209 (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[3]);
4225 #if defined(GL2PS_HAVE_ZLIB)
4230 gl2ps->xreflist[0] = 0;
4231 offs += fprintf(
gl2ps->stream,
"%%PDF-1.4\n");
4232 gl2ps->xreflist[1] = offs;
4235 gl2ps->xreflist[2] = offs;
4238 gl2ps->xreflist[3] = offs;
4241 gl2ps->xreflist[4] = offs;
4244 gl2ps->xreflist[5] = offs;
4252 GL2PSprimitive *prim = *(GL2PSprimitive**)data;
4267 #if defined(GL2PS_HAVE_ZLIB)
4272 fwrite(
gl2ps->compress->dest,
gl2ps->compress->destLen, 1,
gl2ps->stream);
4273 gl2ps->streamlength +=
gl2ps->compress->destLen;
4275 offs +=
gl2ps->streamlength;
4280 offs += fprintf(
gl2ps->stream,
4290 return fprintf(
gl2ps->stream,
4304 offs = fprintf(
gl2ps->stream,
4309 "/MediaBox [%d %d %d %d]\n",
4310 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[1],
4311 (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[3]);
4314 offs += fprintf(
gl2ps->stream,
"/Rotate -90\n");
4316 offs += fprintf(
gl2ps->stream,
4320 "/ProcSet [/PDF /Text /ImageB /ImageC] %%/ImageI\n");
4344 offs += fprintf(
gl2ps->stream,
4355 return fprintf(
gl2ps->stream,
4358 "/Type /ExtGState\n"
4374 int (*action)(
unsigned long data,
int size),
4375 GLfloat
dx, GLfloat
dy,
4381 double dmax = (double) ~1UL;
4385 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4387 offs += (*action)(edgeflag, 1);
4392 if(GL2PS_ZERO(dx * dy)){
4393 offs += (*action)(0, 4);
4394 offs += (*action)(0, 4);
4397 diff = (vertex->
xyz[0] -
xmin) / dx;
4402 imap = (
unsigned long)(diff * dmax);
4403 offs += (*action)(imap, 4);
4405 diff = (vertex->
xyz[1] -
ymin) / dy;
4410 imap = (
unsigned long)(diff * dmax);
4411 offs += (*action)(imap, 4);
4420 int (*action)(
unsigned long data,
int size))
4424 double dmax = (double) ~1UL;
4427 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4429 imap = (
unsigned long)((vertex->
rgba[0]) * dmax);
4430 offs += (*action)(imap, 1);
4432 imap = (
unsigned long)((vertex->
rgba[1]) * dmax);
4433 offs += (*action)(imap, 1);
4435 imap = (
unsigned long)((vertex->
rgba[2]) * dmax);
4436 offs += (*action)(imap, 1);
4444 int (*action)(
unsigned long data,
int size),
4449 double dmax = (double) ~1UL;
4452 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4454 if(sigbyte != 8 && sigbyte != 16)
4459 imap = (
unsigned long)((vertex->
rgba[3]) * dmax);
4461 offs += (*action)(imap, sigbyte);
4469 GLfloat dx, GLfloat dy,
4470 GLfloat xmin, GLfloat ymin,
4471 int (*action)(
unsigned long data,
int size),
4477 if(gray && gray != 8 && gray != 16)
4480 for(i = 0; i < 3; ++i){
4482 dx, dy, xmin, ymin);
4484 v = triangle->vertex[i];
4496 GLfloat *ymin, GLfloat *
ymax,
4497 GL2PStriangle *triangles,
int cnt)
4501 *xmin = triangles[0].vertex[0].xyz[0];
4502 *xmax = triangles[0].vertex[0].xyz[0];
4503 *ymin = triangles[0].vertex[0].xyz[1];
4504 *ymax = triangles[0].vertex[0].xyz[1];
4506 for(i = 0; i < cnt; ++i){
4507 for(j = 0; j < 3; ++j){
4508 if(*xmin > triangles[i].vertex[j].xyz[0])
4509 *xmin = triangles[i].vertex[j].xyz[0];
4510 if(*xmax < triangles[i].vertex[j].xyz[0])
4511 *xmax = triangles[i].vertex[j].xyz[0];
4512 if(*ymin > triangles[i].vertex[j].xyz[1])
4513 *ymin = triangles[i].vertex[j].xyz[1];
4514 if(*ymax < triangles[i].vertex[j].xyz[1])
4515 *ymax = triangles[i].vertex[j].xyz[1];
4528 int i, offs = 0, vertexbytes, done = 0;
4533 vertexbytes = 1+4+4+1+1+1;
4536 vertexbytes = 1+4+4+1;
4539 vertexbytes = 1+4+4+2;
4543 vertexbytes = 1+4+4+1;
4549 offs += fprintf(
gl2ps->stream,
4554 "/BitsPerCoordinate 32 "
4555 "/BitsPerComponent %d "
4557 "/Decode [%f %f %f %f 0 1 %s] ",
4559 (gray) ?
"/DeviceGray" :
"/DeviceRGB",
4561 xmin, xmax, ymin, ymax,
4562 (gray) ?
"" :
"0 1 0 1");
4564 #if defined(GL2PS_HAVE_ZLIB)
4568 for(i = 0; i < size; ++i)
4570 xmax-xmin, ymax-ymin, xmin, ymin,
4575 offs += fprintf(
gl2ps->stream,
4579 (
int)
gl2ps->compress->destLen);
4580 offs +=
gl2ps->compress->destLen * fwrite(
gl2ps->compress->dest,
4581 gl2ps->compress->destLen,
4592 offs += fprintf(
gl2ps->stream,
4596 vertexbytes * 3 * size);
4597 for(i = 0; i < size; ++i)
4599 xmax-xmin, ymax-ymin, xmin, ymin,
4603 offs += fprintf(
gl2ps->stream,
4616 offs += fprintf(
gl2ps->stream,
4621 "/BBox [ %d %d %d %d ]\n"
4622 "/Group \n<<\n/S /Transparency /CS /DeviceRGB\n"
4625 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[1],
4626 (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[3]);
4629 ? (
int)strlen(
"/TrSh sh\n") + (
int)log10((
double)childobj)+1
4630 : (
int)strlen(
"/TrSh0 sh\n");
4632 offs += fprintf(
gl2ps->stream,
4637 offs += fprintf(
gl2ps->stream,
4640 offs += fprintf(
gl2ps->stream,
4655 offs += fprintf(
gl2ps->stream,
4660 offs += fprintf(
gl2ps->stream,
4661 "/SMask << /S /Alpha /G %d 0 R >> ",
4664 offs += fprintf(
gl2ps->stream,
4676 offs += fprintf(
gl2ps->stream,
4689 int (*action)(
unsigned long data,
int size),
4695 if(im->format != GL_RGBA && gray)
4698 if(gray && gray != 8 && gray != 16)
4703 shift = (
sizeof(
unsigned long) - 1) * 8;
4705 for(y = 0; y < im->height; ++
y){
4706 for(x = 0; x < im->width; ++
x){
4708 if(im->format == GL_RGBA && gray){
4709 (*action)((
unsigned long)(a * 255) << shift,
gray);
4712 (*action)((
unsigned long)(r * 255) << shift, 1);
4713 (*action)((
unsigned long)(g * 255) << shift, 1);
4714 (*action)((
unsigned long)(b * 255) << shift, 1);
4720 case 0:
return 3 * im->width * im->height;
4721 case 1:
return im->width * im->height;
4722 case 2:
return 2 * im->width * im->height;
4723 default:
return 3 * im->width * im->height;
4729 int offs = 0, done = 0, sigbytes = 3;
4731 if(gray && gray !=8 && gray != 16)
4735 sigbytes = gray / 8;
4737 offs += fprintf(
gl2ps->stream,
4745 "/BitsPerComponent 8\n",
4747 (
int)im->width, (
int)im->height,
4748 (gray) ?
"/DeviceGray" :
"/DeviceRGB" );
4749 if(GL_RGBA == im->format && gray == 0){
4750 offs += fprintf(
gl2ps->stream,
4755 #if defined(GL2PS_HAVE_ZLIB)
4763 offs += fprintf(
gl2ps->stream,
4767 (
int)
gl2ps->compress->destLen);
4768 offs +=
gl2ps->compress->destLen * fwrite(
gl2ps->compress->dest,
gl2ps->compress->destLen,
4779 offs += fprintf(
gl2ps->stream,
4783 (
int)(im->width * im->height * sigbytes));
4787 offs += fprintf(
gl2ps->stream,
4798 offs += fprintf(
gl2ps->stream,
4805 "/Encoding /MacRomanEncoding\n"
4808 obj, fontnumber, s->fontname);
4817 GL2PSprimitive *p = NULL;
4819 int offs = entryoffs;
4820 GL2PStriangle *triangles;
4823 if(!
gl2ps->pdfgrouplist)
4838 triangles = (GL2PStriangle*)
gl2psMalloc(
sizeof(GL2PStriangle) * size);
4839 for(j = 0; j < size; ++j){
4843 if(triangles[0].prop & T_VAR_COLOR){
4844 gl2ps->xreflist[gro->shobjno] = offs;
4847 if(triangles[0].prop & T_ALPHA_LESS_1){
4848 gl2ps->xreflist[gro->gsobjno] = offs;
4851 if(triangles[0].prop & T_VAR_ALPHA){
4852 gl2ps->xreflist[gro->gsobjno] = offs;
4854 gl2ps->xreflist[gro->trgroupobjno] = offs;
4856 gl2ps->xreflist[gro->maskshobjno] = offs;
4862 gl2ps->xreflist[gro->imobjno] = offs;
4864 if(p->data.image->format == GL_RGBA){
4865 gl2ps->xreflist[gro->imobjno+1] = offs;
4870 gl2ps->xreflist[gro->fontobjno] = offs;
4876 if(p->data.text->alignment ==
GL2PS_PDF)
4877 offs += fprintf(
gl2ps->stream,
"%s\n", p->data.text->str);
4897 offs =
gl2ps->xreflist[5] +
gl2ps->streamlength;
4899 gl2ps->xreflist[5] = offs;
4902 gl2ps->xreflist[6] = offs;
4903 gl2ps->streamlength = 0;
4908 sizeof(
int) * (
gl2ps->objects_stack + 1));
4909 gl2ps->xreflist[7] = offs;
4912 gl2ps->xreflist[8] = offs;
4919 fprintf(
gl2ps->stream,
4922 "%010d 65535 f \n",
gl2ps->objects_stack, 0);
4924 for(i = 1; i <
gl2ps->objects_stack; ++i)
4925 fprintf(
gl2ps->stream,
"%010d 00000 n \n",
gl2ps->xreflist[i]);
4927 fprintf(
gl2ps->stream,
4944 #if defined(GL2PS_HAVE_ZLIB)
4948 gl2ps->compress = NULL;
4960 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
4962 glRenderMode(GL_FEEDBACK);
4964 gl2psResetLineProperties();
4968 gl2ps->header = GL_FALSE;
4974 if(
gl2ps->colormode == GL_RGBA ||
gl2ps->colorsize == 0){
4975 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
4978 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
4997 gl2ps->streamlength += offs;
5015 static GL2PSbackend gl2psPDF = {
5023 "Portable Document Format"
5037 for(i = 0; i <
n; i++){
5038 xyz[i][0] = verts[i].
xyz[0];
5039 xyz[i][1] =
gl2ps->viewport[3] - verts[i].
xyz[1];
5041 for(j = 0; j < 4; j++)
5042 rgba[i][j] = verts[i].rgba[j];
5048 int r = (
int)(255. * rgba[0]);
5049 int g = (
int)(255. * rgba[1]);
5050 int b = (
int)(255. * rgba[2]);
5051 int rc = (r < 0) ? 0 : (r > 255) ? 255 : r;
5052 int gc = (g < 0) ? 0 : (g > 255) ? 255 : g;
5053 int bc = (b < 0) ? 0 : (b > 255) ? 255 : b;
5054 sprintf(str,
"#%2.2x%2.2x%2.2x", rc, gc, bc);
5059 int x,
y, width, height;
5067 y = (
int)
gl2ps->viewport[0];
5069 height = (
int)
gl2ps->viewport[2];
5073 y = (
int)
gl2ps->viewport[1];
5075 height = (
int)
gl2ps->viewport[3];
5081 gl2psPrintf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
5082 gl2psPrintf(
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n");
5083 gl2psPrintf(
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
5084 " width=\"%dpx\" height=\"%dpx\" viewBox=\"%d %d %d %d\">\n",
5085 width, height, x, y, width, height);
5090 "CreationDate: %s\n",
5099 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", col,
5100 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[1],
5101 (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[1],
5102 (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[3],
5103 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[3]);
5124 if(rgba[0][3] < 1.0F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
5126 gl2psPrintf(
"points=\"%g,%g %g,%g %g,%g\"/>\n", xyz[0][0], xyz[0][1],
5127 xyz[1][0], xyz[1][1], xyz[2][0], xyz[2][1]);
5131 for(i = 0; i < 3; i++){
5132 xyz2[0][i] = xyz[0][i];
5133 xyz2[1][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
5134 xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
5136 for(i = 0; i < 4; i++){
5137 rgba2[0][i] = rgba[0][i];
5138 rgba2[1][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
5139 rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5142 for(i = 0; i < 3; i++){
5143 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
5144 xyz2[1][i] = xyz[1][i];
5145 xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5147 for(i = 0; i < 4; i++){
5148 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
5149 rgba2[1][i] = rgba[1][i];
5150 rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5153 for(i = 0; i < 3; i++){
5154 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
5155 xyz2[1][i] = xyz[2][i];
5156 xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5158 for(i = 0; i < 4; i++){
5159 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5160 rgba2[1][i] = rgba[2][i];
5161 rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5164 for(i = 0; i < 3; i++){
5165 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
5166 xyz2[1][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5167 xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
5169 for(i = 0; i < 4; i++){
5170 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
5171 rgba2[1][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5172 rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5180 int i,
n, array[10];
5182 if(!pattern || !factor)
return;
5186 for(i = 0; i <
n; i++){
5196 if(
gl2ps->lastvertex.rgba[0] >= 0.){
5198 gl2ps->viewport[3] -
gl2ps->lastvertex.xyz[1]);
5199 for(i = 0; i < 3; i++)
5200 gl2ps->lastvertex.xyz[i] = -1.;
5201 for(i = 0; i < 4; i++)
5202 gl2ps->lastvertex.rgba[i] = -1.;
5206 #if defined(GL2PS_HAVE_LIBPNG)
5212 #if defined(GL2PS_HAVE_LIBPNG)
5224 sizeof(
unsigned char));
5230 y -= pixmap->zoom_y * (GLfloat)pixmap->height;
5231 gl2psPrintf(
"<image x=\"%g\" y=\"%g\" width=\"%d\" height=\"%d\"\n",
5232 0., 0., pixmap->width, pixmap->height);
5233 gl2psPrintf(
"transform=\"matrix(%g,0,0,%g,%g,%g)\"\n",
5234 pixmap->zoom_x, pixmap->zoom_y, x, y);
5235 gl2psPrintf(
"xlink:href=\"data:image/png;base64,");
5244 "order to embed images in SVG streams");
5250 GL2PSprimitive *prim;
5254 char lcap[7] =
"", ljoin[7] =
"";
5257 prim = *(GL2PSprimitive**)data;
5272 if(rgba[0][3] < 1.0F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
5274 xyz[0][0], xyz[0][1], 0.5 * prim->width);
5279 gl2ps->lastlinewidth != prim->width ||
5280 gl2ps->lastlinecap != prim->linecap ||
5281 gl2ps->lastlinejoin != prim->linejoin ||
5282 gl2ps->lastpattern != prim->pattern ||
5283 gl2ps->lastfactor != prim->factor){
5294 gl2ps->lastvertex = prim->verts[1];
5296 gl2ps->lastlinewidth = prim->width;
5297 gl2ps->lastlinecap = prim->linecap;
5298 gl2ps->lastlinejoin = prim->linejoin;
5299 gl2ps->lastpattern = prim->pattern;
5300 gl2ps->lastfactor = prim->factor;
5303 gl2psPrintf(
"<polyline fill=\"none\" stroke=\"%s\" stroke-width=\"%g\" ",
5305 switch (prim->linecap){
5307 sprintf (lcap,
"%s",
"butt");
5310 sprintf (lcap,
"%s",
"round");
5313 sprintf (lcap,
"%s",
"square");
5316 switch (prim->linejoin){
5318 sprintf (ljoin,
"%s",
"miter");
5321 sprintf (ljoin,
"%s",
"round");
5324 sprintf (ljoin,
"%s",
"bevel");
5327 gl2psPrintf(
"stroke-linecap=\"%s\" stroke-linejoin=\"%s\" ",
5329 if(rgba[0][3] < 1.0F)
gl2psPrintf(
"stroke-opacity=\"%g\" ", rgba[0][3]);
5331 gl2psPrintf(
"points=\"%g,%g ", xyz[0][0], xyz[0][1]);
5348 gl2psPrintf(
"<text fill=\"%s\" x=\"%g\" y=\"%g\" font-size=\"%d\" ",
5349 col, xyz[0][0], xyz[0][1], prim->data.text->fontsize);
5350 if(prim->data.text->angle)
5352 -prim->data.text->angle, xyz[0][0], xyz[0][1]);
5353 switch(prim->data.text->alignment){
5356 prim->data.text->fontsize / 2);
5360 prim->data.text->fontsize / 2);
5364 prim->data.text->fontsize / 2);
5374 prim->data.text->fontsize);
5378 prim->data.text->fontsize);
5382 prim->data.text->fontsize);
5389 if(!strcmp(prim->data.text->fontname,
"Times-Roman"))
5391 else if(!strcmp(prim->data.text->fontname,
"Times-Bold"))
5392 gl2psPrintf(
"font-family=\"Times\" font-weight=\"bold\">");
5393 else if(!strcmp(prim->data.text->fontname,
"Times-Italic"))
5394 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\">");
5395 else if(!strcmp(prim->data.text->fontname,
"Times-BoldItalic"))
5396 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\" font-weight=\"bold\">");
5397 else if(!strcmp(prim->data.text->fontname,
"Helvetica-Bold"))
5398 gl2psPrintf(
"font-family=\"Helvetica\" font-weight=\"bold\">");
5399 else if(!strcmp(prim->data.text->fontname,
"Helvetica-Oblique"))
5400 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\">");
5401 else if(!strcmp(prim->data.text->fontname,
"Helvetica-BoldOblique"))
5402 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\" font-weight=\"bold\">");
5403 else if(!strcmp(prim->data.text->fontname,
"Courier-Bold"))
5404 gl2psPrintf(
"font-family=\"Courier\" font-weight=\"bold\">");
5405 else if(!strcmp(prim->data.text->fontname,
"Courier-Oblique"))
5406 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\">");
5407 else if(!strcmp(prim->data.text->fontname,
"Courier-BoldOblique"))
5408 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\" font-weight=\"bold\">");
5410 gl2psPrintf(
"font-family=\"%s\">", prim->data.text->fontname);
5416 if(prim->data.text->alignment ==
GL2PS_SVG)
5437 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
5439 glRenderMode(GL_FEEDBACK);
5441 gl2psResetLineProperties();
5445 gl2ps->header = GL_FALSE;
5449 if(
gl2ps->colormode == GL_RGBA ||
gl2ps->colorsize == 0){
5450 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5453 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5460 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\" ", col,
5461 x,
gl2ps->viewport[3] - y,
5462 x + w,
gl2ps->viewport[3] - y,
5463 x + w,
gl2ps->viewport[3] - (y + h),
5464 x,
gl2ps->viewport[3] - (y + h));
5465 gl2psPrintf(
"shape-rendering=\"crispEdges\"/>\n");
5468 gl2psPrintf(
"<clipPath id=\"cp%d%d%d%d\">\n", x, y, w, h);
5469 gl2psPrintf(
" <polygon points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n",
5470 x,
gl2ps->viewport[3] - y,
5471 x + w,
gl2ps->viewport[3] - y,
5472 x + w,
gl2ps->viewport[3] - (y + h),
5473 x,
gl2ps->viewport[3] - (y + h));
5475 gl2psPrintf(
"<g clip-path=\"url(#cp%d%d%d%d)\">\n", x, y, w, h);
5495 static GL2PSbackend gl2psSVG = {
5503 "Scalable Vector Graphics"
5516 fprintf(
gl2ps->stream,
"\\color[rgb]{%f,%f,%f}\n", rgba[0], rgba[1], rgba[2]);
5526 fprintf(
gl2ps->stream,
5528 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
5530 "%% CreationDate: \n",
5535 fprintf(
gl2ps->stream,
"\\begin{pgfpicture}\n");
5538 fprintf(
gl2ps->stream,
5539 "\\pgfpathrectanglecorners{"
5540 "\\pgfpoint{%dpt}{%dpt}}{\\pgfpoint{%dpt}{%dpt}}\n"
5541 "\\pgfusepath{fill}\n",
5542 (
int)
gl2ps->viewport[0], (
int)
gl2ps->viewport[1],
5543 (
int)
gl2ps->viewport[2], (
int)
gl2ps->viewport[3]);
5549 int i,
n, array[10];
5551 if(pattern ==
gl2ps->lastpattern && factor ==
gl2ps->lastfactor)
5554 gl2ps->lastpattern = pattern;
5555 gl2ps->lastfactor = factor;
5557 if(!pattern || !factor){
5559 fprintf(
gl2ps->stream,
"\\pgfsetdash{}{0pt}\n");
5563 fprintf(
gl2ps->stream,
"\\pgfsetdash{");
5564 for(i = 0; i <
n; i++) fprintf(
gl2ps->stream,
"{%dpt}", array[i]);
5565 fprintf(
gl2ps->stream,
"}{0pt}\n");
5581 default :
return "south west";
5587 GL2PSprimitive *prim;
5589 prim = *(GL2PSprimitive**)data;
5595 fprintf(
gl2ps->stream,
5596 "\\pgfpathrectangle{\\pgfpoint{%fpt}{%fpt}}"
5597 "{\\pgfpoint{%fpt}{%fpt}}\n\\pgfusepath{fill}\n",
5598 prim->verts[0].xyz[0]-0.5*prim->width,
5599 prim->verts[0].xyz[1]-0.5*prim->width,
5600 prim->width,prim->width);
5604 if(
gl2ps->lastlinewidth != prim->width){
5605 gl2ps->lastlinewidth = prim->width;
5606 fprintf(
gl2ps->stream,
"\\pgfsetlinewidth{%fpt}\n",
gl2ps->lastlinewidth);
5608 if(
gl2ps->lastlinecap != prim->linecap){
5609 gl2ps->lastlinecap = prim->linecap;
5610 switch (prim->linecap){
5612 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"buttcap");
5615 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"roundcap");
5618 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"rectcap");
5622 if(
gl2ps->lastlinejoin != prim->linejoin){
5623 gl2ps->lastlinejoin = prim->linejoin;
5624 switch (prim->linejoin){
5626 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"miterjoin");
5629 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"roundjoin");
5632 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"beveljoin");
5637 fprintf(
gl2ps->stream,
5638 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5639 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5640 "\\pgfusepath{stroke}\n",
5641 prim->verts[1].xyz[0], prim->verts[1].xyz[1],
5642 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
5645 if(
gl2ps->lastlinewidth != 0){
5646 gl2ps->lastlinewidth = 0;
5647 fprintf(
gl2ps->stream,
"\\pgfsetlinewidth{0.01pt}\n");
5649 if(
gl2ps->lastlinecap != prim->linecap){
5650 gl2ps->lastlinecap = prim->linecap;
5651 switch (prim->linecap){
5653 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"buttcap");
5656 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"roundcap");
5659 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"rectcap");
5663 if(
gl2ps->lastlinejoin != prim->linejoin){
5664 gl2ps->lastlinejoin = prim->linejoin;
5665 switch (prim->linejoin){
5667 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"miterjoin");
5670 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"roundjoin");
5673 fprintf(
gl2ps->stream,
"\\pgfset%s\n",
"beveljoin");
5678 fprintf(
gl2ps->stream,
5679 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5680 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5681 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5683 "\\pgfusepath{fill,stroke}\n",
5684 prim->verts[2].xyz[0], prim->verts[2].xyz[1],
5685 prim->verts[1].xyz[0], prim->verts[1].xyz[1],
5686 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
5689 fprintf(
gl2ps->stream,
"{\n\\pgftransformshift{\\pgfpoint{%fpt}{%fpt}}\n",
5690 prim->verts[0].xyz[0], prim->verts[0].xyz[1]);
5692 if(prim->data.text->angle)
5693 fprintf(
gl2ps->stream,
"\\pgftransformrotate{%f}{", prim->data.text->angle);
5695 fprintf(
gl2ps->stream,
"\\pgfnode{rectangle}{%s}{\\fontsize{%d}{0}\\selectfont",
5697 prim->data.text->fontsize);
5699 fprintf(
gl2ps->stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
5700 prim->verts[0].rgba[0], prim->verts[0].rgba[1],
5701 prim->verts[0].rgba[2], prim->data.text->str);
5703 fprintf(
gl2ps->stream,
"}{}{\\pgfusepath{discard}}}");
5705 if(prim->data.text->angle)
5706 fprintf(
gl2ps->stream,
"}");
5708 fprintf(
gl2ps->stream,
"\n");
5713 if (prim->data.text->alignment ==
GL2PS_PGF)
5714 fprintf(
gl2ps->stream,
"%s\n", prim->data.text->str);
5723 fprintf(
gl2ps->stream,
"\\end{pgfpicture}\n");
5730 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
5732 glRenderMode(GL_FEEDBACK);
5734 gl2psResetLineProperties();
5738 gl2ps->header = GL_FALSE;
5741 fprintf(
gl2ps->stream,
"\\begin{pgfscope}\n");
5743 if(
gl2ps->colormode == GL_RGBA ||
gl2ps->colorsize == 0){
5744 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5747 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5754 fprintf(
gl2ps->stream,
5755 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5756 "{\\pgfpoint{%dpt}{%dpt}}\n"
5757 "\\pgfusepath{fill}\n",
5761 fprintf(
gl2ps->stream,
5762 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5763 "{\\pgfpoint{%dpt}{%dpt}}\n"
5764 "\\pgfusepath{clip}\n",
5772 fprintf(
gl2ps->stream,
"\\end{pgfscope}\n");
5782 static GL2PSbackend gl2psPGF = {
5790 "PGF Latex Graphics"
5802 static GL2PSbackend *gl2psbackends[] = {
5813 GL2PSprimitive *prim;
5816 prim = *(GL2PSprimitive**)data;
5818 for(i = 0; i < prim->numverts; i++){
5819 if(prim->verts[i].xyz[0] <
gl2ps->viewport[0])
5820 gl2ps->viewport[0] = (GLint)prim->verts[i].xyz[0];
5821 if(prim->verts[i].xyz[0] >
gl2ps->viewport[2])
5822 gl2ps->viewport[2] = (GLint)(prim->verts[i].xyz[0] + 0.5F);
5823 if(prim->verts[i].xyz[1] <
gl2ps->viewport[1])
5824 gl2ps->viewport[1] = (GLint)prim->verts[i].xyz[1];
5825 if(prim->verts[i].xyz[1] >
gl2ps->viewport[3])
5826 gl2ps->viewport[3] = (GLint)(prim->verts[i].xyz[1] + 0.5F);
5833 GL2PSxyz eye = {0.0F, 0.0F, 100.0F * GL2PS_ZSCALE};
5837 used = glRenderMode(GL_RENDER);
5853 gl2ps->viewport[0] =
gl2ps->viewport[1] = 100000;
5854 gl2ps->viewport[2] =
gl2ps->viewport[3] = -100000;
5857 (gl2psbackends[
gl2ps->format]->printHeader)();
5858 gl2ps->header = GL_FALSE;
5866 switch(
gl2ps->sort){
5885 root = (GL2PSbsptree*)
gl2psMalloc(
sizeof(GL2PSbsptree));
5894 gl2psbackends[
gl2ps->format]->printPrimitive, 0);
5901 gl2psbackends[
gl2ps->format]->printFinalPrimitive();
5906 static GLboolean gl2psCheckOptions(GLint options, GLint colormode)
5911 "GL2PS_DRAW_BACKGROUND are incompatible.");
5916 "GL2PS_USE_CURRENT_VIEWPORT are incompatible.");
5921 "option GL2PS_NO_BLENDING.");
5924 if (colormode != GL_RGBA) {
5941 GLint viewport[4], GLint format, GLint sort,
5942 GLint options, GLint colormode,
5944 GLint nr, GLint ng, GLint nb, GLint buffersize,
5945 FILE *stream,
const char *
filename)
5958 if (gl2psCheckOptions(options, colormode) == GL_FALSE) {
5964 if(format >= 0 && format < (GLint)(
sizeof(gl2psbackends) /
sizeof(gl2psbackends[0]))){
5965 gl2ps->format = format;
5988 gl2ps->stream = stream;
5997 gl2ps->header = GL_TRUE;
5998 gl2ps->forcerasterpos = GL_FALSE;
5999 gl2ps->maxbestroot = 10;
6000 gl2ps->options = options;
6001 gl2ps->compress = NULL;
6002 gl2ps->imagemap_head = NULL;
6003 gl2ps->imagemap_tail = NULL;
6005 if(
gl2ps->options & GL2PS_USE_CURRENT_VIEWPORT){
6006 glGetIntegerv(GL_VIEWPORT,
gl2ps->viewport);
6009 for(i = 0; i < 4; i++){
6010 gl2ps->viewport[i] = viewport[i];
6014 if(!
gl2ps->viewport[2] || !
gl2ps->viewport[3]){
6023 gl2ps->threshold[0] = nr ? 1.0F / (GLfloat)nr : 0.064F;
6024 gl2ps->threshold[1] = ng ? 1.0F / (GLfloat)ng : 0.034F;
6025 gl2ps->threshold[2] = nb ? 1.0F / (GLfloat)nb : 0.100F;
6026 gl2ps->colormode = colormode;
6027 gl2ps->buffersize = buffersize > 0 ? buffersize : 2048 * 2048;
6028 for(i = 0; i < 3; i++){
6029 gl2ps->lastvertex.xyz[i] = -1.0F;
6031 for(i = 0; i < 4; i++){
6032 gl2ps->lastvertex.rgba[i] = -1.0F;
6033 gl2ps->lastrgba[i] = -1.0F;
6035 gl2ps->lastlinewidth = -1.0F;
6036 gl2ps->lastlinecap = 0;
6037 gl2ps->lastlinejoin = 0;
6038 gl2ps->lastpattern = 0;
6039 gl2ps->lastfactor = 0;
6040 gl2ps->imagetree = NULL;
6041 gl2ps->primitivetoadd = NULL;
6042 gl2ps->zerosurfacearea = GL_FALSE;
6043 gl2ps->pdfprimlist = NULL;
6044 gl2ps->pdfgrouplist = NULL;
6045 gl2ps->xreflist = NULL;
6051 : glIsEnabled(GL_BLEND);
6052 glGetIntegerv(GL_BLEND_SRC, &
gl2ps->blendfunc[0]);
6053 glGetIntegerv(GL_BLEND_DST, &
gl2ps->blendfunc[1]);
6056 gl2ps->blending = GL_FALSE;
6059 if(
gl2ps->colormode == GL_RGBA){
6060 gl2ps->colorsize = 0;
6061 gl2ps->colormap = NULL;
6063 glGetFloatv(GL_COLOR_CLEAR_VALUE,
gl2ps->bgcolor);
6066 else if(
gl2ps->colormode == GL_COLOR_INDEX){
6067 if(!colorsize || !colormap){
6073 gl2ps->colorsize = colorsize;
6076 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
6080 gl2ps->bgcolor[3] = 1.0F;
6091 gl2ps->title[0] =
'\0';
6095 strcpy(
gl2ps->title, title);
6100 gl2ps->producer[0] =
'\0';
6104 strcpy(
gl2ps->producer, producer);
6109 gl2ps->filename[0] =
'\0';
6113 strcpy(
gl2ps->filename, filename);
6121 glFeedbackBuffer(
gl2ps->buffersize, GL_3D_COLOR,
gl2ps->feedback);
6122 glRenderMode(GL_FEEDBACK);
6125 gl2ps->feedback = NULL;
6126 gl2ps->buffersize = 0;
6141 (gl2psbackends[
gl2ps->format]->printFooter)();
6143 fflush(
gl2ps->stream);
6163 (gl2psbackends[
gl2ps->format]->beginViewport)(viewport);
6174 res = (gl2psbackends[
gl2ps->format]->endViewport)();
6177 gl2psResetLineProperties();
6183 GLshort fontsize, GLint alignment, GLfloat angle,
6191 GLshort fontsize, GLint alignment, GLfloat angle)
6213 GLint xorig, GLint yorig,
6214 GLenum format, GLenum type,
6219 GLfloat pos[4], zoom_x, zoom_y;
6220 GL2PSprimitive *prim;
6225 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
6229 if((format != GL_RGB && format != GL_RGBA) || type != GL_FLOAT){
6231 "GL_RGB/GL_RGBA, GL_FLOAT pixels");
6235 if (
gl2ps->forcerasterpos) {
6236 pos[0] =
gl2ps->rasterpos.xyz[0];
6237 pos[1] =
gl2ps->rasterpos.xyz[1];
6238 pos[2] =
gl2ps->rasterpos.xyz[2];
6245 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
6247 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
6248 glGetFloatv(GL_ZOOM_X, &zoom_x);
6249 glGetFloatv(GL_ZOOM_Y, &zoom_y);
6252 prim = (GL2PSprimitive*)
gl2psMalloc(
sizeof(GL2PSprimitive));
6257 prim->verts[0].xyz[0] = pos[0] + xorig;
6258 prim->verts[0].xyz[1] = pos[1] + yorig;
6259 prim->verts[0].xyz[2] = pos[2];
6262 prim->ofactor = 0.0;
6267 if (
gl2ps->forcerasterpos) {
6268 prim->verts[0].rgba[0] =
gl2ps->rasterpos.rgba[0];
6269 prim->verts[0].rgba[1] =
gl2ps->rasterpos.rgba[1];
6270 prim->verts[0].rgba[2] =
gl2ps->rasterpos.rgba[2];
6271 prim->verts[0].rgba[3] =
gl2ps->rasterpos.rgba[3];
6274 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->verts[0].rgba);
6276 prim->data.image = (GL2PSimage*)
gl2psMalloc(
sizeof(GL2PSimage));
6277 prim->data.image->width = width;
6278 prim->data.image->height = height;
6279 prim->data.image->zoom_x = zoom_x;
6280 prim->data.image->zoom_y = zoom_y;
6281 prim->data.image->format = format;
6282 prim->data.image->type = type;
6284 gl2ps->forcerasterpos = GL_FALSE;
6290 prim->data.image->format = GL_RGB;
6291 size = height * width * 3;
6292 prim->data.image->pixels = (GLfloat*)
gl2psMalloc(size *
sizeof(GLfloat));
6293 piv = (
const GLfloat*)pixels;
6294 for(i = 0; i < size; ++i, ++piv){
6295 prim->data.image->pixels[i] = *piv;
6301 size = height * width * 4;
6302 prim->data.image->pixels = (GLfloat*)
gl2psMalloc(size *
sizeof(GLfloat));
6303 memcpy(prim->data.image->pixels, pixels, size *
sizeof(GLfloat));
6308 size = height * width * 3;
6309 prim->data.image->pixels = (GLfloat*)
gl2psMalloc(size *
sizeof(GLfloat));
6310 memcpy(prim->data.image->pixels, pixels, size *
sizeof(GLfloat));
6317 glPassThrough(GL2PS_DRAW_PIXELS_TOKEN);
6328 const unsigned char *imagemap){
6330 int sizeoffloat =
sizeof(GLfloat);
6334 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
6336 size = height + height * ((width - 1) / 8);
6337 glPassThrough(GL2PS_IMAGEMAP_TOKEN);
6339 glVertex3f(position[0], position[1],position[2]);
6341 glPassThrough((GLfloat)width);
6342 glPassThrough((GLfloat)height);
6343 for(i = 0; i < size; i += sizeoffloat){
6344 const float *
value = (
const float*)imagemap;
6345 glPassThrough(*value);
6346 imagemap += sizeoffloat;
6360 glPassThrough(GL2PS_BEGIN_OFFSET_TOKEN);
6361 glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &tmp2);
6362 glPassThrough(tmp2);
6363 glGetFloatv(GL_POLYGON_OFFSET_UNITS, &tmp2);
6364 glPassThrough(tmp2);
6367 glPassThrough(GL2PS_BEGIN_BOUNDARY_TOKEN);
6370 glPassThrough(GL2PS_BEGIN_STIPPLE_TOKEN);
6371 glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &tmp);
6372 glPassThrough((GLfloat)tmp);
6373 glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &tmp);
6374 glPassThrough((GLfloat)tmp);
6377 glPassThrough(GL2PS_BEGIN_BLEND_TOKEN);
6393 glPassThrough(GL2PS_END_OFFSET_TOKEN);
6396 glPassThrough(GL2PS_END_BOUNDARY_TOKEN);
6399 glPassThrough(GL2PS_END_STIPPLE_TOKEN);
6402 glPassThrough(GL2PS_END_BLEND_TOKEN);
6416 glPassThrough(GL2PS_POINT_SIZE_TOKEN);
6417 glPassThrough(value);
6426 glPassThrough(GL2PS_LINE_CAP_TOKEN);
6427 glPassThrough(value);
6436 glPassThrough(GL2PS_LINE_JOIN_TOKEN);
6437 glPassThrough(value);
6446 glPassThrough(GL2PS_LINE_WIDTH_TOKEN);
6447 glPassThrough(value);
6459 glPassThrough(GL2PS_SRC_BLEND_TOKEN);
6460 glPassThrough((GLfloat)sfactor);
6461 glPassThrough(GL2PS_DST_BLEND_TOKEN);
6462 glPassThrough((GLfloat)dfactor);
6471 if(gl2psCheckOptions(options,
gl2ps->colormode) == GL_FALSE) {
6475 gl2ps->options = options;
6487 *options =
gl2ps->options;
6494 if(format >= 0 && format < (GLint)(
sizeof(gl2psbackends) /
sizeof(gl2psbackends[0])))
6495 return gl2psbackends[format]->file_extension;
6497 return "Unknown format";
6502 if(format >= 0 && format < (GLint)(
sizeof(gl2psbackends) /
sizeof(gl2psbackends[0])))
6503 return gl2psbackends[format]->description;
6505 return "Unknown format";
6510 return gl2ps->format;
6520 gl2ps->forcerasterpos = GL_TRUE;
6521 gl2ps->rasterpos.xyz[0] = vert->
xyz[0];
6522 gl2ps->rasterpos.xyz[1] = vert->
xyz[1];
6523 gl2ps->rasterpos.xyz[2] = vert->
xyz[2];
6524 gl2ps->rasterpos.rgba[0] = vert->
rgba[0];
6525 gl2ps->rasterpos.rgba[1] = vert->
rgba[1];
6526 gl2ps->rasterpos.rgba[2] = vert->
rgba[2];
6527 gl2ps->rasterpos.rgba[3] = vert->
rgba[3];