Thread: [PyOpenGL-Users] Creating a postscript image of a scene : how do I use openglutil ?
Brought to you by:
mcfletch
From: Champ H. <cha...@be...> - 2003-05-19 12:43:03
|
Hello, I need to create PostScript image of a scene created with PyOpenGL. I have seen that "openglutil" should provide the required functionnalities such as "openglutil.glSaveEPS('teapot.eps', 240, 240)". However my installation does not seem to recognize "openglutil" and I get the error message : "NameError: global name 'openglutil' is not defined" when I run the following program (lising #3 of article http://www.linuxjournal.com/article.php?sid=4830): from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.Tk import * import sys def display(togl): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glColor3f(0.3, 1.0, 1.0) glMaterialfv(GL_FRONT, GL_AMBIENT, [0.1745, 0.0, 0.1, 0.0]) glMaterialfv(GL_FRONT, GL_DIFFUSE, [0.1, 0.0, 0.6, 0.0]) glMaterialfv(GL_FRONT, GL_SPECULAR, [0.7, 0.6, 0.8, 0.0]) glMaterialf(GL_FRONT, GL_SHININESS, 80) glutSolidTeapot(1.0) glFlush() openglutil.glSaveEPS('teapot.eps', 240, 240) sys.exit() togl = Opengl(width = 250, height = 250, double = 1) togl.redraw = display togl.pack(side = 'top', expand = 1, fill = 'both') togl.basic_lighting() togl.set_background(0, 0, 0) togl.mainloop() Here is my system configuration: - windows XP professional - python 2.2.2 - PyOpenGL 2.0.0.44 What do I need to install openglutil ? How to do it ? Is there other way of creating images (jpeg, bmp, png, gif ...) from PyOpenGL scenes ? Thanks, Bernard |
From: Mike C. F. <mcf...@ro...> - 2003-05-19 16:42:45
|
openglutil was a PyOpenGL 1.x-specific add-on module that was dropped for the 2.x series because the functionality could all be written in Python (this allowed us to eliminate the libpng and libjpeg dependencies of the 1.x series) and result in more flexible and robust code. You can see samples of saving images linked off the glReadPixels manual page here: http://pyopengl.sourceforge.net/documentation/manual/glReadPixels.3G.html AFAIK all of those save to png or jpeg, but PIL does (apparently) support writting EPS from an image, so it should work fine. HTH, Mike Champ Hippy wrote: >Hello, > >I need to create PostScript image of a scene created with PyOpenGL. I >have seen that "openglutil" should provide the required >functionnalities such as "openglutil.glSaveEPS('teapot.eps', 240, >240)". However my installation does not seem to recognize "openglutil" >and I get the error message : "NameError: global name 'openglutil' is >not defined" when I run the following program (lising #3 of article >http://www.linuxjournal.com/article.php?sid=4830): > > ... _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |
From: gabor <ga...@z1...> - 2003-05-19 16:59:12
|
On Mon, 2003-05-19 at 18:41, Mike C. Fletcher wrote: > You can=20 > see samples of saving images linked off the glReadPixels manual page here= : >=20 > =20 > http://pyopengl.sourceforge.net/documentation/manual/glReadPixels.3G.html >=20 > AFAIK all of those save to png or jpeg, but PIL does (apparently)=20 > support writting EPS from an image, so it should work fine. i'm not sure if he wants the same as me,but: when i wrote my master thesis ( i used pyopengl -)), i needed to make a lot of screenshots. and i also wanted to be able to make eps screenshots. i mean vector-based eps screenshots. that means if there is a line on the screen i want it to be described as a line in the eps file. not as a series of dots. i know that eps is able to handle vectorial data. reason: when printing the master-thesis, all the screenshots look a little ugly, because the resolution of the monitor is a lot smaller than the resolution of the printer. with a vector-based image i wouldn't have that problem. hope this helps, gabor |
From: Mike C. F. <mcf...@ro...> - 2003-05-19 17:17:13
|
gabor wrote: ... >when i wrote my master thesis ( i used pyopengl -)), i needed to make a >lot of screenshots. > >and i also wanted to be able to make eps screenshots. i mean >vector-based eps screenshots. > ... I assume you used glFeedbackBuffer (I'm interpreting your message to mean you did create such screenshots)? Do you (or anyone) have any sample code you'd be willing to share? Rendering an OpenGL scene to postscript commands seems like it would be a fairly doable thing, but I haven't any experience in the area. I'd imagine with the basic mechanism in-place it would be just as easy (maybe easier) to go to a format such as SVG so that the result would be editable in Illustrator or CorelDraw. BTW, the openglutils module was just storing a bitmap in the EPS file, it wasn't AFAIK trying to draw the scene with PS commands. Enjoy all, Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |
From: gabor <ga...@z1...> - 2003-05-19 17:25:15
|
On Mon, 2003-05-19 at 19:16, Mike C. Fletcher wrote: > gabor wrote: > ... > > > ... > I assume you used glFeedbackBuffer (I'm interpreting your message to=20 > mean you did create such screenshots)? Do you (or anyone) have any=20 > sample code you'd be willing to share? Rendering an OpenGL scene to=20 no, i didn't do anything sophisticated :) i simply create screenshots with kde, and that's all :( gabor |
From: Mike C. F. <mcf...@ro...> - 2003-05-19 20:08:31
|
If anyone's interested the GLP library is an (LGPL) C++ lib to do OpenGL -> postscript: http://www.easysw.com/~mike/opengl/index.html it honestly doesn't seem particuarly complex, it uses the feedback buffer, and apparently does some culling of the results to eliminate massive overdraw. Similar-looking C lib for the same purpose (also LGPL): http://www.geuz.org/gl2ps/ apparently had a Python wrapper at some point in time, though it doesn't appear to be available any more (Toby?) All in all this looks like the most mature of the solutions (for instance it appears able to deal with intersection polygons, though if I'm reading right it may generate striated results for smooth-shaded polygons. There's another variant on the same approach here: http://192.48.159.181/developers/code/mjktips/Feedback.html Enjoy, Mike gabor wrote: >On Mon, 2003-05-19 at 19:16, Mike C. Fletcher wrote: > > >>gabor wrote: >>... >> >> >>... >>I assume you used glFeedbackBuffer (I'm interpreting your message to >>mean you did create such screenshots)? Do you (or anyone) have any >>sample code you'd be willing to share? Rendering an OpenGL scene to >> >> > >no, i didn't do anything sophisticated :) > >i simply create screenshots with kde, and that's all :( > > >gabor > > _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |
From: Mike C. F. <mcf...@ro...> - 2003-05-20 07:39:48
|
I've just built (and done some minimal testing of) a gl2ps wrapper for use with PyOpenGL. Haven't tested anything save the two primary entry points, but they seem to work properly. As a note, the mechanism works using view-space absolute coordinates w/out the benefit of the depth buffer, so if your background-drawing code plays tricks such as clearing the depth buffer after drawing (which OpenGLContext does), you can wind up with your scene behind the background's geometry. Anyway, if people are interested enough, I'll post the source somewhere. The wrapper script is basically just a slightly trimmed version of the gl2ps.h header with some minimal type-mapping. I wound up renaming the gl2ps.c file to _gl2ps.c to get around an annoying error where the build system was creating two gl2ps.o files. Other than that no noticable changes to the base package that I can recall. Oh, and at the moment you need to define WIN32 explicitly to build. Haven't figured out why that's necessary as of yet. Here's the results from a simple VRML file (one normally intended to be drawn w/out textures): http://members.rogers.com/mcfletch/programming/test.eps Anyway, if anyone's interested, I'll look at polishing/finishing the wrapper and releasing it. Enjoy all, Mike Mike C. Fletcher wrote: ... > Similar-looking C lib for the same purpose (also LGPL): > > http://www.geuz.org/gl2ps/ > > apparently had a Python wrapper at some point in time, though it > doesn't appear to be available any more (Toby?) All in all this looks > like the most mature of the solutions (for instance it appears able to > deal with intersection polygons, though if I'm reading right it may > generate striated results for smooth-shaded polygons. ... _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |