void saveAsEps(){ FILE *fp; // char file[]="visualized.eps"; string fname = data.ifname + IntToStr(data.node.size()) + ".eps"; int state = GL2PS_OVERFLOW, buffsize = 0; GLint viewport[4]; int options=GL2PS_BEST_ROOT | GL2PS_OCCLUSION_CULL | GL2PS_USE_CURRENT_VIEWPORT; if( (fp = fopen(fname.c_str(), "wb")) == NULL ){ cout << "cant open \"" << fname << "\"" << endl; exit(0); } cout << "start to output \"" << fname << "\" ..." << endl; while(state == GL2PS_OVERFLOW){ buffsize += 1024*1024; gl2psBeginPage(fname.c_str(), "gl2psTest", viewport, GL2PS_EPS, GL2PS_NO_SORT, options, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, fname.c_str()); display(); state = gl2psEndPage(); } fclose(fp); cout << "Done." << endl; }
bool CObjectView::saveEPS(const char *fileName){ SELECT_CONTEXT(); // to use GL2PS FILE *f = fopen(fileName, "w"); if (!f) return false; int buffsize = 0, state = GL2PS_OVERFLOW; while( state == GL2PS_OVERFLOW ){ buffsize += 1024*1024; TRACE("bufferSize set to %d\n", buffsize); gl2psBeginPage("GRB", "GRB", GL2PS_BSP_SORT /*GL2PS_SIMPLE_SORT*/, GL2PS_NONE /*GL2PS_OCCLUSION_CULL*/, GL_RGBA, 0, NULL, buffsize, f); gl2psLineWidth(1); gl2psPointSize(1); setupPerspective(); drawScene(NULL, -1); state = gl2psEndPage(); } fclose(f); UNSELECT_CONTEXT(); return true; }
static void keyboard(unsigned char key, int x, int y) { FILE *fp; int state = GL2PS_OVERFLOW, buffsize = 0; (void) x; (void) y; /* not used */ switch(key){ case 'q': exit(0); break; case 's': fp = fopen("out.eps", "wb"); printf("Writing 'out.eps'... "); while(state == GL2PS_OVERFLOW){ buffsize += 1024*1024; gl2psBeginPage("test", "gl2psTestSimple", NULL, GL2PS_EPS, GL2PS_SIMPLE_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps"); display(); state = gl2psEndPage(); } fclose(fp); printf("Done!\n"); break; } }
bool RGLView::postscript(int formatID, const char* filename, bool drawText) { bool success = false; FILE *fp = fopen(filename, "wb"); char *oldlocale = setlocale(LC_NUMERIC, "C"); GLint buffsize = 0, state = GL2PS_OVERFLOW; GLint viewport[4]; GLint options = GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET | GL2PS_NO_BLENDING | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT; if (!drawText) options |= GL2PS_NO_TEXT; if (windowImpl->beginGL()) { glGetIntegerv(GL_VIEWPORT, viewport); while( state == GL2PS_OVERFLOW ) { buffsize += 1024*1024; gl2psBeginPage ( filename, "Generated by rgl", viewport, formatID, GL2PS_BSP_SORT, options, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, filename ); if ( drawText ) { // signal gl2ps for text scene->invalidateDisplaylists(); if (formatID == GL2PS_PS || formatID == GL2PS_EPS || formatID == GL2PS_TEX || formatID == GL2PS_PGF) renderContext.gl2psActive = GL2PS_POSITIONAL; else renderContext.gl2psActive = GL2PS_LEFT_ONLY; } // redraw: scene->render(&renderContext); glFinish(); if ( drawText ) { scene->invalidateDisplaylists(); renderContext.gl2psActive = GL2PS_NONE; } success = true; state = gl2psEndPage(); } windowImpl->endGL(); } setlocale(LC_NUMERIC, oldlocale); fclose(fp); return success; }
// print /// void figure_t_t::print(const std::string filename) { FILE *fp; int state = GL2PS_OVERFLOW, buffsize = 0; fp = fopen(filename.c_str(), "wb"); std::cout << "Writing '" << filename << "'... "; while(state == GL2PS_OVERFLOW) { buffsize += 2024*2024; gl2psBeginPage("test", "gl2ps", NULL, GL2PS_EPS, GL2PS_SIMPLE_SORT, GL2PS_USE_CURRENT_VIEWPORT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, filename.c_str()); draw(); state = gl2psEndPage(); } fclose(fp); std::cout << "Done!" << std::endl; }
void writefile(int format, int sort, int options, int nbcol, const char *filename, const char *extension) { FILE *fp; char file[256]; int state = GL2PS_OVERFLOW, buffsize = 0; GLint viewport[4]; strcpy(file, filename); strcat(file, "."); strcat(file, extension); viewport[0] = 0; viewport[1] = 0; viewport[2] = window_w; viewport[3] = window_h; fp = fopen(file, "wb"); if(!fp){ printf("Unable to open file %s for writing\n", file); exit(1); } printf("Saving image to file %s... ", file); fflush(stdout); while(state == GL2PS_OVERFLOW){ buffsize += 1024*1024; gl2psBeginPage(file, "gl2psTest", viewport, format, sort, options, GL_RGBA, 0, NULL, nbcol, nbcol, nbcol, buffsize, fp, file); display(); state = gl2psEndPage(); } fclose(fp); printf("Done!\n"); fflush(stdout); }
void gl2ps() { FILE *fp; int state = GL2PS_OVERFLOW, buffsize = 0; string epsfilename = objfilename + "-" + to_string(k) +".eps"; { epsfilename = objfilename + "-" + to_string(k) + "-n-"+ to_string(modelnum) + ".eps"; } fp = fopen(epsfilename.c_str(), "wb"); printf("Writing %s ...\n", epsfilename.c_str()); while(state == GL2PS_OVERFLOW){ buffsize += 1024*1024; gl2psBeginPage("test", "gl2psTestSimple", NULL, GL2PS_EPS , GL2PS_SIMPLE_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT | GL2PS_TIGHT_BOUNDING_BOX, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, epsfilename.c_str()); display(); state = gl2psEndPage(); } fclose(fp); printf("Done!\n"); }
void MainWindow::doSave() { GLint viewport[4]; viewport[0] = 0; viewport[1] = 0; viewport[2] = glw->width(); viewport[3] = glw->height(); GLint fmt = fileFormat->itemData(fileFormat->currentIndex()).toInt(); GLint srt = sort->itemData(sort->currentIndex()).toInt(); GLint options = GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT; if (srt==GL2PS_BSP_SORT) options |= GL2PS_BEST_ROOT; QString fname("out."); fname += fileFormat->currentText(); FILE* fp = fopen(fname.toLatin1().constData(), "wb"); if (!fp) { return; } int state = GL2PS_OVERFLOW, buffsize = 0, ret; while(state == GL2PS_OVERFLOW){ buffsize += 1024*1024; ret = gl2psBeginPage(fname.toLatin1().constData(), "qgl2ps", viewport, fmt, srt, options, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, fname.toLatin1().constData()); if (ret==GL2PS_ERROR) break; glw->repaint(); state = gl2psEndPage(); } fclose(fp); }
void CheckMove(CCam & Camera1) { if(downPressed)Camera1.CamMove(-speed); if(upPressed)Camera1.CamMove(speed); if(leftPressed)Camera1.CamRotatePos(-speed/1000); if(rightPressed)Camera1.CamRotatePos(speed/1000); //assumes noone does ctrl and shift together! if(shift_leftPressed)Camera1.CamRotateView(-speed/1000); if(shift_rightPressed)Camera1.CamRotateView(speed/1000); if(ctrl_leftPressed)Camera1.CamStrafe(speed); if(ctrl_rightPressed)Camera1.CamStrafe(-speed); if(p_Pressed){ FILE *fp=fopen("MyFileName.ps","wb"); GLint buffsize=0; GLint state=GL2PS_OVERFLOW; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); while(state==GL2PS_OVERFLOW){ buffsize+=1024*1024; // could use GL2PS_USE_CURRENT_VIEWPORT, int ips=gl2psBeginPage("MyTitle","MyProducer",viewport, GL2PS_PS,GL2PS_BSP_SORT,GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET | GL2PS_BEST_ROOT,GL_RGBA,0,NULL, 0,0,0,buffsize,fp,"MyFileName.ps"); RenderScene(Camera1); state=gl2psEndPage(); } //end while loop fclose(fp); } // end p_Pressed }
bool RGLView::postscript(int formatID, const char* filename) { bool success = false; FILE *fp = fopen(filename, "wb"); GLint buffsize = 0, state = GL2PS_OVERFLOW; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); while( state == GL2PS_OVERFLOW ){ buffsize += 1024*1024; gl2psBeginPage ( "MyTitle", "Generated by rgl", viewport, formatID, GL2PS_BSP_SORT, GL2PS_SILENT | GL2PS_SIMPLE_LINE_OFFSET | GL2PS_NO_BLENDING | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, filename ); windowImpl->beginGL(); // redraw: paint(); windowImpl->endGL(); success = true; state = gl2psEndPage(); } fclose(fp); return success; }
std::string GUISUMOAbstractView::makeSnapshot(const std::string& destFile) { std::string errorMessage; FXString ext = FXPath::extension(destFile.c_str()); const bool useGL2PS = ext == "ps" || ext == "eps" || ext == "pdf" || ext == "svg" || ext == "tex" || ext == "pgf"; #ifdef HAVE_FFMPEG const bool useVideo = destFile == "" || ext == "h264" || ext == "hevc"; #endif for (int i = 0; i < 10 && !makeCurrent(); ++i) { FXSingleEventThread::sleep(100); } // draw glClearColor( myVisualizationSettings->backgroundColor.red() / 255., myVisualizationSettings->backgroundColor.green() / 255., myVisualizationSettings->backgroundColor.blue() / 255., myVisualizationSettings->backgroundColor.alpha() / 255.); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (myVisualizationSettings->dither) { glEnable(GL_DITHER); } else { glDisable(GL_DITHER); } if (myVisualizationSettings->antialiase) { glEnable(GL_BLEND); glEnable(GL_POLYGON_SMOOTH); glEnable(GL_LINE_SMOOTH); } else { glDisable(GL_BLEND); glDisable(GL_POLYGON_SMOOTH); glDisable(GL_LINE_SMOOTH); } applyGLTransform(); if (useGL2PS) { GLint format = GL2PS_PS; if (ext == "ps") { format = GL2PS_PS; } else if (ext == "eps") { format = GL2PS_EPS; } else if (ext == "pdf") { format = GL2PS_PDF; } else if (ext == "tex") { format = GL2PS_TEX; } else if (ext == "svg") { format = GL2PS_SVG; } else if (ext == "pgf") { format = GL2PS_PGF; } else { return "Could not save '" + destFile + "'.\n Unrecognized format '" + std::string(ext.text()) + "'."; } FILE* fp = fopen(destFile.c_str(), "wb"); if (fp == 0) { return "Could not save '" + destFile + "'.\n Could not open file for writing"; } GLint buffsize = 0, state = GL2PS_OVERFLOW; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); while (state == GL2PS_OVERFLOW) { buffsize += 1024 * 1024; gl2psBeginPage(destFile.c_str(), "sumo-gui; http://sumo.dlr.de", viewport, format, GL2PS_SIMPLE_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps"); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); // compute lane width // draw decals (if not in grabbing mode) if (!myUseToolTips) { drawDecals(); if (myVisualizationSettings->showGrid) { paintGLGrid(); } } glLineWidth(1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); Boundary viewPort = myChanger->getViewport(); float minB[2]; float maxB[2]; minB[0] = viewPort.xmin(); minB[1] = viewPort.ymin(); maxB[0] = viewPort.xmax(); maxB[1] = viewPort.ymax(); myVisualizationSettings->scale = m2p(SUMO_const_laneWidth); glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); myGrid->Search(minB, maxB, *myVisualizationSettings); if (myVisualizationSettings->showSizeLegend) { displayLegend(); } state = gl2psEndPage(); glFinish(); } fclose(fp); } else { doPaintGL(GL_RENDER, myChanger->getViewport()); if (myVisualizationSettings->showSizeLegend) { displayLegend(); } swapBuffers(); glFinish(); FXColor* buf; FXMALLOC(&buf, FXColor, getWidth()*getHeight()); // read from the back buffer glReadBuffer(GL_BACK); // Read the pixels glReadPixels(0, 0, getWidth(), getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)buf); makeNonCurrent(); update(); // mirror size_t mwidth = getWidth(); size_t mheight = getHeight(); FXColor* paa = buf; FXColor* pbb = buf + mwidth * (mheight - 1); do { FXColor* pa = paa; paa += mwidth; FXColor* pb = pbb; pbb -= mwidth; do { FXColor t = *pa; *pa++ = *pb; *pb++ = t; } while (pa < paa); } while (paa < pbb); try { #ifdef HAVE_FFMPEG if (useVideo) { try { saveFrame(destFile, buf); errorMessage = "video"; } catch (std::runtime_error& err) { errorMessage = err.what(); } } else #endif if (!MFXImageHelper::saveImage(destFile, getWidth(), getHeight(), buf)) { errorMessage = "Could not save '" + destFile + "'."; } } catch (InvalidArgument& e) { errorMessage = "Could not save '" + destFile + "'.\n" + e.what(); } FXFREE(&buf); } return errorMessage; }
/** * Renders the current scene to a file in the format given. * * @param filename The name of the target file. It must already contain the correct extension and must be encoded in UTF-8. * @param format The format of the file to render. Supported are PNG, PDF, PS (postscript) and EPS (encapsulated postscript). * @param title The titel for the document. Must be ANSI encoded for now. * @param software A string describing the producer of the document. Must be ANSI encoded for now. * @param content A set of flags indicating what additional info to render. * @param zoom The zoom at which render the file. * @param bounds Position and size of the area to store in the file (currently only for PNG). * @return True if successful otherwise false. */ bool CGenericCanvas::renderToFile(const char* filename, TGCFileFormat format, const char* title, const char* software, TGCRenderContent content, float zoom, TGCViewport& bounds) { bool result = false; if (!updating()) { beginUpdate(); try { if ((FStates & GC_STATE_PENDING_ACTIVATION) != 0) { // A pending activation state always means there is a valid current view. FStates &= ~GC_STATE_PENDING_ACTIVATION; FCurrentView->activate(); }; switch (format) { case GC_FILE_FORMAT_PDF: case GC_FILE_FORMAT_PS: case GC_FILE_FORMAT_EPS: { if (FCurrentView != NULL) { const int fileTypeMapper[4] = {GL2PS_PDF, GL2PS_PS, GL2PS_EPS, GL2PS_TEX}; FILE *file = openFile(filename, "wb"); GLint bufferSize = 0; GLint state = GL2PS_OVERFLOW; char *oldlocale = setlocale(LC_NUMERIC, "C"); while (state == GL2PS_OVERFLOW) { bufferSize += 1024 * 1024; gl2psBeginPage(title, software, NULL, fileTypeMapper[format], GL2PS_NO_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT | GL2PS_COMPRESS, GL_RGBA, 0, NULL, 0, 0, 0, bufferSize, file, filename); gl2psEnable(GL2PS_BLEND); gl2psBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); clearBuffers(); FCurrentView->render(content); state = gl2psEndPage(); }; setlocale(LC_NUMERIC, oldlocale); fclose(file); result = true; }; break; }; case GC_FILE_FORMAT_PNG: { if (FCurrentView != NULL) { TImage image; float workspaceWidth; float workspaceHeight; FCurrentView->getWorkspace(&workspaceWidth, &workspaceHeight); image.width = bounds.width; if (image.width < 0) image.width = (int) workspaceWidth; image.height = bounds.height; if (image.height < 0) image.height = (int) workspaceHeight; // If the frame buffer extension is not supported then there is no sense // to allocate a buffer larger than the current viewport, // because we cannot render more than this area in this case. if (!supportsExtension(GC_OE_FRAME_BUFFER_OBJECTS)) { if (image.height > FCurrentView->viewportGet().height) image.height = FCurrentView->viewportGet().height; if (image.width > FCurrentView->viewportGet().width) image.width = FCurrentView->viewportGet().width; }; image.colorType = COLOR_TYPE_RGB_ALPHA; image.data = (unsigned char*) malloc(image.width * image.height * 4); if (image.data != NULL) { FCurrentView->renderToMemory(GC_COLOR_FORMAT_RGBA, content, zoom, bounds, image.data); image.width = bounds.width; image.height = bounds.height; result = savePNG(utf8ToUtf16(filename), &image, true, title, software); free(image.data); }; }; break; }; }; endUpdate(); } catch(...) { endUpdate(); throw; }; checkError(); }; return result; }
void GLViewer::draw() { #ifdef YADE_GL2PS if(!nextFrameSnapshotFilename.empty() && boost::algorithm::ends_with(nextFrameSnapshotFilename,".pdf")){ gl2psStream=fopen(nextFrameSnapshotFilename.c_str(),"wb"); if(!gl2psStream){ int err=errno; throw runtime_error(string("Error opening file ")+nextFrameSnapshotFilename+": "+strerror(err)); } LOG_DEBUG("Start saving snapshot to "<<nextFrameSnapshotFilename); size_t nBodies=Omega::instance().getScene()->bodies->size(); int sortAlgo=(nBodies<100 ? GL2PS_BSP_SORT : GL2PS_SIMPLE_SORT); gl2psBeginPage(/*const char *title*/"Some title", /*const char *producer*/ "Yade", /*GLint viewport[4]*/ NULL, /*GLint format*/ GL2PS_PDF, /*GLint sort*/ sortAlgo, /*GLint options*/GL2PS_SIMPLE_LINE_OFFSET|GL2PS_USE_CURRENT_VIEWPORT|GL2PS_TIGHT_BOUNDING_BOX|GL2PS_COMPRESS|GL2PS_OCCLUSION_CULL|GL2PS_NO_BLENDING, /*GLint colormode*/ GL_RGBA, /*GLint colorsize*/0, /*GL2PSrgba *colortable*/NULL, /*GLint nr*/0, /*GLint ng*/0, /*GLint nb*/0, /*GLint buffersize*/4096*4096 /* 16MB */, /*FILE *stream*/ gl2psStream, /*const char *filename*/NULL); } #endif qglviewer::Vec vd=camera()->viewDirection(); renderer->viewDirection=Vector3r(vd[0],vd[1],vd[2]); if(Omega::instance().getScene()){ const shared_ptr<Scene>& scene=Omega::instance().getScene(); int selection = selectedName(); if(selection!=-1 && (*(Omega::instance().getScene()->bodies)).exists(selection) && isMoving){ static Real lastTimeMoved(0); float v0,v1,v2; manipulatedFrame()->getPosition(v0,v1,v2); if(last == selection) // delay by one redraw, so the body will not jump into 0,0,0 coords { Quaternionr& q = (*(Omega::instance().getScene()->bodies))[selection]->state->ori; Vector3r& v = (*(Omega::instance().getScene()->bodies))[selection]->state->pos; Vector3r& vel = (*(Omega::instance().getScene()->bodies))[selection]->state->vel; Vector3r& angVel = (*(Omega::instance().getScene()->bodies))[selection]->state->angVel; angVel=Vector3r::Zero(); Real dt=(scene->time-lastTimeMoved); lastTimeMoved=scene->time; if (dt!=0) { vel[0]=-(v[0]-v0)/dt; vel[1]=-(v[1]-v1)/dt; vel[2]=-(v[2]-v2)/dt;} else vel[0]=vel[1]=vel[2]=0; //FIXME: should update spin like velocity above, when the body is rotated: double q0,q1,q2,q3; manipulatedFrame()->getOrientation(q0,q1,q2,q3); q.x()=q0;q.y()=q1;q.z()=q2;q.w()=q3; } (*(Omega::instance().getScene()->bodies))[selection]->userForcedDisplacementRedrawHook(); } if(manipulatedClipPlane>=0){ assert(manipulatedClipPlane<renderer->numClipPlanes); float v0,v1,v2; manipulatedFrame()->getPosition(v0,v1,v2); double q0,q1,q2,q3; manipulatedFrame()->getOrientation(q0,q1,q2,q3); Se3r newSe3(Vector3r(v0,v1,v2),Quaternionr(q0,q1,q2,q3)); newSe3.orientation.normalize(); const Se3r& oldSe3=renderer->clipPlaneSe3[manipulatedClipPlane]; FOREACH(int planeId, boundClipPlanes){ if(planeId>=renderer->numClipPlanes || !renderer->clipPlaneActive[planeId] || planeId==manipulatedClipPlane) continue; Se3r& boundSe3=renderer->clipPlaneSe3[planeId]; Quaternionr relOrient=oldSe3.orientation.conjugate()*boundSe3.orientation; relOrient.normalize(); Vector3r relPos=oldSe3.orientation.conjugate()*(boundSe3.position-oldSe3.position); boundSe3.position=newSe3.position+newSe3.orientation*relPos; boundSe3.orientation=newSe3.orientation*relOrient; boundSe3.orientation.normalize(); } renderer->clipPlaneSe3[manipulatedClipPlane]=newSe3; } scene->renderer=renderer; renderer->render(scene, selectedName()); }