📄 gleps.c
字号:
}static void PutUnsortedFeedback(glWindow w, FILE * file, GLint size, GLfloat * buffer){ GLfloat *loc, *end; loc = buffer; end = buffer + size; while (loc < end) { loc = PutPrimitive(w,file, loc); if (loc==NULL) return; }}typedef struct _DepthIndex { GLfloat *ptr; GLfloat depth;} DepthIndex;static int compare(const void *a, const void *b){ DepthIndex *p1 = (DepthIndex *) a; DepthIndex *p2 = (DepthIndex *) b; GLfloat diff = p2->depth - p1->depth; if (diff > 0.0) { return 1; } else if (diff < 0.0) { return -1; } else { return 0; }}static void PutSortedFeedback(glWindow w, FILE * file, GLint size, GLfloat * buffer){ int token; GLfloat *loc,*end; FBColorVertex *vertex; GLfloat depthSum,lastdepth; int nprimitives, item; DepthIndex *prims; int nvertices, i; end = buffer + size; /* Count how many primitives there are. */ nprimitives = 0; loc = buffer; while (loc < end) { token = *loc; loc++; switch (token) { case GL_LINE_TOKEN: case GL_LINE_RESET_TOKEN: loc += 2*FBColorVertexSize; nprimitives++; break; case GL_POLYGON_TOKEN: nvertices = *loc; loc++; loc += (FBColorVertexSize * nvertices); nprimitives++; break; case GL_POINT_TOKEN: loc += FBColorVertexSize; nprimitives++; break; case GL_PASS_THROUGH_TOKEN: loc++; nprimitives++; break; case GL_BITMAP_TOKEN: case GL_DRAW_PIXEL_TOKEN: case GL_COPY_PIXEL_TOKEN: loc+=FBColorVertexSize; nprimitives++; /* printf("Bitmaps & Pixels not supported in feedback mode\n");*/ break; default: printf("gleps error: Sorted FB 0: Unexpected token (%d).\n",token); return; } } /* Allocate an array of pointers that will point back at primitives in the feedback buffer. There will be one entry per primitive. This array is also where we keep the primitive's average depth. There is one entry per primitive in the feedback buffer. */ prims = (DepthIndex *) malloc(sizeof(DepthIndex) * nprimitives); item = 0; loc = buffer; while (loc < end) { prims[item].ptr = loc; /* Save this primitive's location. */ token = *loc; loc++; switch (token) { case GL_LINE_TOKEN: case GL_LINE_RESET_TOKEN: vertex = (FBColorVertex *) loc; depthSum = vertex[0].z + vertex[1].z; prims[item].depth = depthSum / 2.0; loc += 2*FBColorVertexSize; break; case GL_POLYGON_TOKEN: nvertices = *loc; loc++; vertex = (FBColorVertex *) loc; depthSum = vertex[0].z; for (i = 1; i < nvertices; i++) { depthSum += vertex[i].z; } prims[item].depth = depthSum / nvertices; loc += (FBColorVertexSize * nvertices); break; case GL_POINT_TOKEN: vertex = (FBColorVertex *) loc; prims[item].depth = vertex[0].z; loc += FBColorVertexSize; break; case GL_PASS_THROUGH_TOKEN: /* Pass through is only used for string handling. It assumes that before it has been called, a dummy bitmap has been invoked to get the position. */ prims[item].depth=lastdepth; loc++; break; case GL_BITMAP_TOKEN: case GL_DRAW_PIXEL_TOKEN: case GL_COPY_PIXEL_TOKEN: /* It is assumed that this stuff is currently used only to handle strings. In fact, marker bitmaps are written to just get some position. */ vertex = (FBColorVertex *) loc; lastdepth=prims[item].depth = vertex[0].z; loc+=FBColorVertexSize; break; default: printf("gleps error: Sorted FB 1: Unexpected token (%d).\n",token); return; } item++; } assert(item == nprimitives); /* Sort the primitives back to front. */ qsort(prims, nprimitives, sizeof(DepthIndex), compare); /* XXX Understand that sorting by a primitives average depth doesn't allow us to disambiguate some cases like self intersecting polygons. Handling these cases would require breaking up the primitives. That's too involved for this example. Sorting by depth is good enough for lots of applications. */ /* Emit the Encapsulated PostScript for the primitives in back to front order. */ for (item = 0; item < nprimitives; item++) { (void) PutPrimitive(w,file, prims[item].ptr); } free(prims);}static void Put(glWindow w, FILE * file, int doSort,int size, GLfloat * buffer){ GLfloat clearColor[4]; GLfloat lineWidth; float output_scale,xtran,ytran; int i; time_t t; int ww,wh; if (size<=0 || buffer==NULL) return; /* Read back a bunch of OpenGL state to help make the EPS consistent with the OpenGL clear color, line width, point size, and viewport. */ /* This is still inconsistent when multiple viewports, line sizes etc are used. Possibly, we will have to introduce some glwNewObject stuff to catch the necessary values when they are changed */ glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor); glGetFloatv(GL_LINE_WIDTH, &lineWidth); glGetFloatv(GL_POINT_SIZE, &pointSize); glwGetWindowSize(w,&ww,&wh); /* we want to place our stuff nicely @ A4 Potrait... */ output_scale=(A4_XINCH-1.0)*PS_UPI/(float)ww; xtran=(A4_XINCH*PS_UPI-(float)ww*output_scale)/2.0; ytran=((A4_YINCH-0.5)*PS_UPI-wh*output_scale); t=time(&t); /* Emit EPS header. */ fprintf(file,"%%!PS-Adobe-2.0 EPSF-2.0\n"); fprintf(file,"%%%%Title: %s\n",glwGetTitle(w)); fprintf(file,"%%%%Creator: gltools (c) J.Fuhrmann <fuhrmann@wias-berlin.de> \n"); fprintf(file,"%%%%CreationDate: %s",ctime(&t)); fprintf(file,"%%%%Pages: 1\n"); fprintf(file,"%%%%BoundingBox: %g %g %g %g\n",xtran,ytran,ww*output_scale+xtran,wh*output_scale+ytran); fprintf(file,"%%%%EndComments\n"); fprintf(file,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); fprintf(file,"%%BEGIN OF TUNING SECTION\n"); fprintf(file,"%%\n"); fprintf(file,"%%Fonts:\n"); fprintf(file,"%%By changing the definition of Fontscale and Fontname\n"); fprintf(file,"%%you can modify the font for your needs\n"); fprintf(file,"/Fontscale %g def\n",1.0); fprintf(file,"/Fontname /Helvetica def\n%%\n"); fprintf(file,"%%\n"); fprintf(file,"%%Triangle shading:\n"); fprintf(file,"%%By changing the definition of GouraudThreshold\n"); fprintf(file,"%%you can modify the quality of rendering of shaded triangles.\n"); fprintf(file,"%%Lower values mean increased smoothness at the cost of longer printing times\n"); fprintf(file, "/GouraudThreshold %g def\n", EPS_GOURAUD_THRESHOLD); fprintf(file,"%%\n"); fprintf(file,"%%Line width\n"); fprintf(file, "/DefaultLineWidth %g def\n", lineWidth-1.0); fprintf(file,"%%Background color in rgb values\n"); fprintf(file, "/DefaultBackgroundColor { %g %g %g } def\n", clearColor[0], clearColor[1], clearColor[2]); fprintf(file,"%%\n"); fprintf(file,"%%END OF TUNING SECTION\n"); fprintf(file,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); fprintf(file,"/FS { Fontscale mul %g mul Fontname findfont exch scalefont setfont} bind def\n",(double)wh); /* Output Frederic Delhoume's "gouraudtriangle" PostScript fragment. */ fputs("% The gouraudtriangle PostScript fragement below is free\n", file); fputs("% written by Frederic Delhoume <delhoume@ilog.fr>\n", file); fprintf(file, "/threshold GouraudThreshold def\n"); for (i = 0; gouraudtriangleEPS[i]; i++) fprintf(file, "%s\n", gouraudtriangleEPS[i]); fprintf(file,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); fprintf(file,"/GT {gouraudtriangle} bind def\n"); fprintf(file,"/M {moveto} bind def\n"); fprintf(file,"/L {lineto} bind def\n"); fprintf(file,"/LS {lineto stroke} bind def\n"); fprintf(file,"/CF {closepath fill} bind def\n"); fprintf(file,"/AF {arc fill} bind def\n"); fprintf(file,"/N {newpath} bind def\n"); fprintf(file,"/C {setrgbcolor} bind def\n"); fprintf(file,"/S {show} bind def\n"); fprintf(file,"/NP {newpath} bind def\n"); fprintf(file,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); fprintf(file,"%%%%EndProlog\n"); fprintf(file,"%%%%Page: 1 1\n"); fprintf(file,"gsave\n"); fprintf(file,"%g %g translate %g %g scale\n",xtran,ytran,output_scale, output_scale); fprintf(file, "DefaultLineWidth setlinewidth\n"); fprintf(file, "DefaultBackgroundColor setrgbcolor\n"); fprintf(file, "0 0 %d %d rectfill\n\n", ww,wh); if (doSort) PutSortedFeedback(w,file, size, buffer); else PutUnsortedFeedback(w,file, size, buffer); /* Emit EPS trailer. */ fputs("showpage\ngrestore\n", file); fprintf(file,"%%%%Trailer\n"); fprintf(file,"%%%%Pages: 1\n");}void glepsDumpSorted(glWindow w, FILE *file){ assert(w!=NULL); assert(file!=NULL); glwRenderFB(w); if (file) { Put(w,file, 1 ,glwGetFBSize(w), glwGetFB(w)); } glwResetFB(w);}void glepsDumpUnSorted(glWindow w, FILE *file){ assert(w!=NULL); assert(file!=NULL); glwRenderFB(w); if (file) { Put(w,file, 0 ,glwGetFBSize(w), glwGetFB(w)); } glwResetFB(w);}void glepsDump(glWindow w, FILE *file){ glepsDumpSorted(w,file);}/* * $Log: gleps.c,v $ * Revision 2.15 2000/01/13 17:36:41 fuhrmann * optmized ps output * * Revision 2.14 2000/01/11 17:04:49 fuhrmann * Iljas Aenderungen wieder 'raus * * Revision 2.13 2000/01/11 16:50:39 schmelze * *** empty log message *** * * Revision 2.12 1999/11/04 17:16:09 philip * string memory bug in glwin * roundoff error in colors in gleps * * Revision 2.11 1999/11/01 18:31:42 fuhrmann * linewidth 1->0 * * Revision 2.10 1999/09/17 16:35:01 fuhrmann * feedback stuff war kaputtrepariert... * * Revision 2.9 1999/09/15 16:16:24 fuhrmann * size_t for feedback buffer * file !=NULL check for dump files * * Revision 2.8 1999/08/04 13:03:43 fuhrmann * some hacks concerning feedback * * Revision 2.7 1999/07/02 10:38:04 fuhrmann * Mesa bug neutralized, gleps reference taken out of glwin * * Revision 2.6 1999/07/01 17:09:12 fuhrmann * tested portability (Linux, IRIX, DUNIX) * * Revision 2.5 1999/06/30 13:14:14 fuhrmann * fontscale bug removed * * Revision 2.4 1999/06/30 13:07:50 fuhrmann * font size stuff * * Revision 2.3 1999/06/30 10:55:45 fuhrmann * no exit at token errors * * Revision 2.2 1999/06/30 10:27:25 fuhrmann * some bells &whistles in feedback stuff * * Revision 2.1 1999/06/29 17:56:23 fuhrmann * Feedback buffer is used now... * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -