Re: [pygame] PyOpenGL Screenshots

2008-05-06 Thread René Dudfield
hi again,

note, you can convert a series of images with image magik, or the gimp
most easily I think...

convert -delay 20 -loop 0 bla*.tga animated.gif

Or opening them as gimp layers, then saving to an animated gif.

cu,



On Wed, May 7, 2008 at 2:44 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
> looks like pyopengl 3.x returns a numpy array now instead of a string
>  by default... which breaks pygame.image.save on gl with pyopengl 3.x.
>
>  Here's a work around screenshot function for gl.
>
>
>  def save_screen(screen, filename):
>
> def readScreen(x, y, width, height):
> """ Read in the screen information in the area specified """
> glFinish()
> glPixelStorei(GL_PACK_ALIGNMENT, 4)
> glPixelStorei(GL_PACK_ROW_LENGTH, 0)
> glPixelStorei(GL_PACK_SKIP_ROWS, 0)
> glPixelStorei(GL_PACK_SKIP_PIXELS, 0)
>
> data = glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE)
> if hasattr(data, "tostring"):
> data = data.tostring()
>
> return data
> def saveImageData(width, height, data, filename):
> """ Save image data """
> surface = pygame.image.fromstring(data, (width, height), 'RGB', 1)
> pygame.image.save(surface, filename)
>
> data = readScreen(0,0, screen.get_width(), screen.get_height())
> saveImageData(screen.get_width(), screen.get_height(), data, filename)
>
>
>
>
>
>  On Wed, May 7, 2008 at 2:27 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
>  > hi,
>  >
>  >  glReadPixels, make a surface, then use pygame.image.save()
>  >
>  >  Then use ffmpeg, or vlc etc to make a movie out of still frames.
>  >
>  >  cheers,
>  >
>


BUG: pygame.image.save(screen) with pyopengl 3.x Re: [pygame] PyOpenGL Screenshots

2008-05-06 Thread René Dudfield
Added a bug to the subject.

cu,

On Wed, May 7, 2008 at 2:44 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
> looks like pyopengl 3.x returns a numpy array now instead of a string
>  by default... which breaks pygame.image.save on gl with pyopengl 3.x.
>
>  Here's a work around screenshot function for gl.
>
>
>  def save_screen(screen, filename):
>
> def readScreen(x, y, width, height):
> """ Read in the screen information in the area specified """
> glFinish()
> glPixelStorei(GL_PACK_ALIGNMENT, 4)
> glPixelStorei(GL_PACK_ROW_LENGTH, 0)
> glPixelStorei(GL_PACK_SKIP_ROWS, 0)
> glPixelStorei(GL_PACK_SKIP_PIXELS, 0)
>
> data = glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE)
> if hasattr(data, "tostring"):
> data = data.tostring()
>
> return data
> def saveImageData(width, height, data, filename):
> """ Save image data """
> surface = pygame.image.fromstring(data, (width, height), 'RGB', 1)
> pygame.image.save(surface, filename)
>
> data = readScreen(0,0, screen.get_width(), screen.get_height())
> saveImageData(screen.get_width(), screen.get_height(), data, filename)
>
>
>
>
>
>  On Wed, May 7, 2008 at 2:27 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
>  > hi,
>  >
>  >  glReadPixels, make a surface, then use pygame.image.save()
>  >
>  >  Then use ffmpeg, or vlc etc to make a movie out of still frames.
>  >
>  >  cheers,
>  >
>


Re: [pygame] PyOpenGL Screenshots

2008-05-06 Thread René Dudfield
looks like pyopengl 3.x returns a numpy array now instead of a string
by default... which breaks pygame.image.save on gl with pyopengl 3.x.

Here's a work around screenshot function for gl.


def save_screen(screen, filename):

def readScreen(x, y, width, height):
""" Read in the screen information in the area specified """
glFinish()
glPixelStorei(GL_PACK_ALIGNMENT, 4)
glPixelStorei(GL_PACK_ROW_LENGTH, 0)
glPixelStorei(GL_PACK_SKIP_ROWS, 0)
glPixelStorei(GL_PACK_SKIP_PIXELS, 0)

data = glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE)
if hasattr(data, "tostring"):
data = data.tostring()

return data
def saveImageData(width, height, data, filename):
""" Save image data """
surface = pygame.image.fromstring(data, (width, height), 'RGB', 1)
pygame.image.save(surface, filename)

data = readScreen(0,0, screen.get_width(), screen.get_height())
saveImageData(screen.get_width(), screen.get_height(), data, filename)



On Wed, May 7, 2008 at 2:27 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
> hi,
>
>  glReadPixels, make a surface, then use pygame.image.save()
>
>  Then use ffmpeg, or vlc etc to make a movie out of still frames.
>
>  cheers,
>


Re: [pygame] PyOpenGL Screenshots

2008-05-06 Thread René Dudfield
hi,

glReadPixels, make a surface, then use pygame.image.save()

Then use ffmpeg, or vlc etc to make a movie out of still frames.

cheers,


Re: [pygame] PyOpenGL Screenshots

2008-05-06 Thread Noah Kantrowitz

Ian Mallett wrote:

Hello,

-I have a project which must be finished by Thursday.  The project is a
movie, for a presentation, and my solution has been to make a program to
render each frame in OpenGL.  I can now render each frame individually, but
now I face the challenge of turning these renders into a movie.  (Movie
capture programs are no good--free ones have drawbacks, and in any case the
renders are slow to update (think 1 fps tops).).

-I decided to do it as a .gif animation, as I have several programs for
making movies from a series of images


Using an animated gif would be dumb. 
http://www.yourmachines.org/tutorials/mgpy.html shows how to use ffmpeg 
to create video files from images.


--Noah




signature.asc
Description: OpenPGP digital signature


[pygame] PyOpenGL Screenshots

2008-05-06 Thread Ian Mallett
Hello,

-I have a project which must be finished by Thursday.  The project is a
movie, for a presentation, and my solution has been to make a program to
render each frame in OpenGL.  I can now render each frame individually, but
now I face the challenge of turning these renders into a movie.  (Movie
capture programs are no good--free ones have drawbacks, and in any case the
renders are slow to update (think 1 fps tops).).

-I decided to do it as a .gif animation, as I have several programs for
making movies from a series of images.
-The obvious thing to do is to copy each frame into the programs, building
my movie that way.
-However, there are exactly 1200 frames in the movie at a minimal
quality--that's (150 frames/scene)*(8 scenes).  I want this framerate to be
higher.  This pushes the frame count higher, naturally.  The stupendous
number of necessary frames is impractical to copy via ALT-PRINTSCREEN--(my
current method).

-The ideal solution is to directly export the frames into a .gif animation.

-My second best option would be to save each render in a separate file.  I
could then drag and drop these renders chunks at a time into my program to
make the animation.
-I face several challenges here.  The most important is that I have no idea
how to save screenshots from PyOpenGL.  Last I heard, people sort-of had
ideas about how to do it.  pygame.image.save() *does not work* on OpenGL
surfaces.  Any concrete working examples here?

-Summary: From an PyOpenGL program, what is a working method of saving
renders to either many files or directly to a .gif animation?

Thanks,
Ian