pyglet output to postscript/pdf

41 views
Skip to first unread message

vaibhav

unread,
Oct 9, 2008, 3:15:06 PM10/9/08
to pyglet-users
Hi,
Is there a way i can output a pyglet screen to pdf? I want to save
something i have drawn on screen as PDF (as vector).

Alex Holkner

unread,
Oct 9, 2008, 6:13:53 PM10/9/08
to pyglet...@googlegroups.com

This article http://www.opengl.org/resources/code/samples/mjktips/Feedback.html
explains how to use OpenGL feedback to create postscript drawing
commands from OpenGL calls. The same technique can be used for
creating PDF (which has a similar rendering model to postscript).
This would be a fair chunk of work to implement, however.

Alex.

Python Nutter

unread,
Oct 10, 2008, 2:59:31 AM10/10/08
to pyglet...@googlegroups.com
If you just want a one-off and want the easiest way possible, it would
be to just take your program to a Mac and run it on the Mac and do a
screen capture. Mac OS X uses PDF as the rendering engine for the
screen so it natively handles and creates PDFs with ease. PDF used to
be the default output for screen captures (there is a list of
different possible file formats including PDF so you might have to
tweak the Mac back to PDF as default -- osxhints.com should tell you
as I've seen such tips posted there all the time.)

2008/10/10 Alex Holkner <alex.h...@gmail.com>:

infinite8s

unread,
Oct 10, 2008, 9:03:30 AM10/10/08
to pyglet-users

That won't work. Screen capture will return a bitmap image (plus, OS X
has it's own OpenGL context which completely bypasses the Quartz
drawing framework, so even if screen capture could capture the drawing
commands, it still wouldn't be in PDF format).

On Oct 10, 2:59 am, "Python Nutter" <pythonnut...@gmail.com> wrote:
> If you just want a one-off and want the easiest way possible, it would
> be to just take your program to a Mac and run it on the Mac and do a
> screen capture. Mac OS X uses PDF as the rendering engine for the
> screen so it natively handles and creates PDFs with ease. PDF used to
> be the default output for screen captures (there is a list of
> different possible file formats including PDF so you might have to
> tweak the Mac back to PDF as default -- osxhints.com should tell you
> as I've seen such tips posted there all the time.)
>
> 2008/10/10 Alex Holkner <alex.holk...@gmail.com>:
>
>
>
> > On 10/10/08, vaibhav <bhawsar.vaib...@gmail.com> wrote:
>
> >>  Hi,
> >>  Is there a way i can output a pyglet screen to pdf? I want to save
> >>  something i have drawn on screen as PDF (as vector).
>
> > This articlehttp://www.opengl.org/resources/code/samples/mjktips/Feedback.html

Drew Smathers

unread,
Oct 10, 2008, 10:24:14 AM10/10/08
to pyglet...@googlegroups.com
On Fri, Oct 10, 2008 at 9:03 AM, infinite8s
<naveen.mic...@gmail.com> wrote:
>
>
> That won't work. Screen capture will return a bitmap image (plus, OS X
> has it's own OpenGL context which completely bypasses the Quartz
> drawing framework, so even if screen capture could capture the drawing
> commands, it still wouldn't be in PDF format).
>

Yeah details, details ... but I still would second the Python Nutter's
(wow, what a name) basic argument - there are easier ways to do this,
don't try to make your life too hard ;)

One approach to consider is just outputing the color buffer to a
format supported natively by pyglet such as png, and use external
tools such png2eps, epstool, etc to get it where you want. Also,
ImageMagick (http://www.imagemagick.org/script/formats.php) has a
dizzying array of supported formats, including eps, ps, pdf ...

Another thing you might want to experiment with is PIL's pdf output
support (http://www.pythonware.com/library/pil/handbook/format-pdf.htm)
in combination with a library such as ReportLab
(http://www.reportlab.org/). This is likely a more cross-platform
solution.

Surgeon General's Warning: I have nil experience with this specific
problem, so ignore everything I've said.

Drew

vaibhav

unread,
Oct 10, 2008, 6:59:56 PM10/10/08
to pyglet-users
I can't use the capture on osx for the reasons already mentioned. my
py skills are limited but i will look at PIL and reportlab combo-
thanks for the tip. generally tracing a bitmap to vector does not give
good results if you have small fonts in the bitmap. that being said
its still an easy and straightforward option. thanks for all your
help. i will post if i find some great way to save postscript out of
pyglet.

On Oct 10, 7:24 am, "Drew Smathers" <drew.smath...@gmail.com> wrote:
> On Fri, Oct 10, 2008 at 9:03 AM, infinite8s
>

walgri

unread,
Oct 10, 2008, 2:48:30 PM10/10/08
to pyglet-users


On 10 Ott, 00:13, "Alex Holkner" <alex.holk...@gmail.com> wrote:
> On 10/10/08, vaibhav <bhawsar.vaib...@gmail.com> wrote:
[...]
> This articlehttp://www.opengl.org/resources/code/samples/mjktips/Feedback.html
> explains how to use OpenGL feedback to create postscript drawing
> commands from OpenGL calls.  The same technique can be used for
[...]

http://starship.python.net/crew/theller/wiki/GL2PS

Walgri

vaibhav

unread,
Oct 18, 2008, 2:23:29 AM10/18/08
to pyglet-users
so i managed to create the dynamic lib for gl2ps < http://www.geuz.org/gl2ps/
> on mac os x 10.4. I can import it using ctypes.

>>> gl2ps = ctypes.CDLL('libgl2ps.dylib')
>>> gl2ps
<CDLL 'libgl2ps.dylib', handle 10b660 at 7a330>

I then ran the header (gl2ps.h) through wraptypes to generate the
python code. I got bunch of errors < http://paste2.org/p/88416 > but I
can import this gl2ps.py file.

>>> import gl2ps
>>> gl2ps
<module 'gl2ps' from '/Library/Frameworks/Python.framework/Versions/
2.5/lib/python2.5/site-packages/gl2ps.pyc'>
>>> gl2ps.gl2psSetOptions()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: this function takes at least 1 argument (0 given)

I am assuming this is working so far.

But i figured i could not for example access
gl2ps.gl2psBeginPage("test", "gl2psTestSimple",
gl2ps.GL2PS_USE_CURRENT_VIEWPORT , gl2ps.GL2PS_EPS,
gl2ps.GL2PS_SIMPLE_SORT,gl2ps.GL2PS_DRAW_BACKGROUND |
gl2ps.GL2PS_USE_CURRENT_VIEWPORT, GL_RGBA, 0, NULL, 0, 0, 0, buffsize,
FILE, "out.eps")

I get this error
AttributeError: 'module' object has no attribute 'gl2psBeginPage'

I next checked gl2ps.py and found that i had no code generated for
this function gl2psBeginPage
this is what this function in C looks like

GLint gl2psBeginPage( const char *title, const char *producer,
GLint viewport[4],
GLint format, GLint sort, GLint options,
GLint colormode, GLint colorsize,
GL2PSrgba *colortable,
GLint nr, GLint ng, GLint nb,
GLint buffersize, FILE *stream,
const char *filename )

There are two datatypes there "FILE *stream" and "GL2PSrgba
*colortable" that i think caused the problem since ctypes does not
understand those datatypes. (i am not entirely sure if this is the
problem)
I was wondering what would be the appropriate argtype for "FILE
*stream" and "GL2PSrgba *colortable"
I started manually entering argtypes in the generated py file- but am
clueless what to enter for these two datatypes

gl2psBeginPage = _lib.gl2psBeginPage
gl2psBeginPage.restype = GLint
gl2psBeginPage.argtypes = [c_char_p, c_char_p, GLint * 4, GLint,
GLint, GLint, GLint, GLint, ?????, GLint, GLint GLint, GLint, ????,
c_char_p]


Thanks!
vaibhav
Reply all
Reply to author
Forward
0 new messages