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

2008-06-02 Thread Nicholas Dudfield
Hi,

pygame.image.save() of gl Surfaces is still a problem on windows, causing
segfaults.

I commited a test called image__save_gl_surface_test.py 

cheers.


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of René Dudfield
Sent: Monday, June 02, 2008 12:35 PM
To: pygame-users@seul.org
Subject: Re: BUG: pygame.image.save(screen) with pyopengl 3.x Re: [pygame]
PyOpenGL Screenshots

hi,

I fixed this on the weekend.  I stopped using pyopengl to get
glReadPixels (since pyopengl 3.x broke the glReadPixels API), and
instead loaded the gl functions dynamically with C.

Committed revision 1261.

You can get auto-built binaries for windows/mac osx here if needed:
http://thorbrian.com/pygame/builds.php

cheers,



On Wed, May 7, 2008 at 2:47 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
> 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: BUG: pygame.image.save(screen) with pyopengl 3.x Re: [pygame] PyOpenGL Screenshots

2008-06-01 Thread René Dudfield
hi,

I fixed this on the weekend.  I stopped using pyopengl to get
glReadPixels (since pyopengl 3.x broke the glReadPixels API), and
instead loaded the gl functions dynamically with C.

Committed revision 1261.

You can get auto-built binaries for windows/mac osx here if needed:
http://thorbrian.com/pygame/builds.php

cheers,



On Wed, May 7, 2008 at 2:47 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
> 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-12 Thread Astan Chee

Hmm, thanks, I thought it was a simple solution.
I guess I'd rather cheat and do it as a progress-window kinda thing.
Thanks again for the info.
Astan

René Dudfield wrote:

hi,

You could do this with mesa 3d.  I don't think you can do it without
an x server.

You can also draw offscreen with a software surface by using the dummy
video driver - but that won't work for opengl.

cu,


On Tue, May 13, 2008 at 4:24 PM, Astan Chee <[EMAIL PROTECTED]> wrote:
  

Hi,
 I was wondering if the latest solution to render pyopengl from pygame
(Alistair Buxton's script) includes off-screen rendering.
 I want to render something and save it as a sequence of images, but I dont
want to display it anywhere. Is there a way to 'hide' this window?
 Thanks
 Astan

 --
 "Formulations of number theory: Complete, Consistent, Non-trivial. Choose
two."


 Animal Logic
 http://www.animallogic.com

 Please think of the environment before printing this email.

 This email and any attachments may be confidential and/or privileged. If
you are not the intended recipient of this email, you must not disclose or
use the information contained in it. Please notify the sender immediately
and delete this document if you have received it in error. We do not
guarantee this email is error or virus free.







  


--
"Formulations of number theory: Complete, Consistent, Non-trivial. Choose two."



Animal Logic
http://www.animallogic.com

Please think of the environment before printing this email.

This email and any attachments may be confidential and/or privileged. If you 
are not the intended recipient of this email, you must not disclose or use the 
information contained in it. Please notify the sender immediately and delete 
this document if you have received it in error. We do not guarantee this email 
is error or virus free.



Re: [pygame] PyOpenGL Screenshots

2008-05-12 Thread René Dudfield
hi,

You could do this with mesa 3d.  I don't think you can do it without
an x server.

You can also draw offscreen with a software surface by using the dummy
video driver - but that won't work for opengl.

cu,


On Tue, May 13, 2008 at 4:24 PM, Astan Chee <[EMAIL PROTECTED]> wrote:
> Hi,
>  I was wondering if the latest solution to render pyopengl from pygame
> (Alistair Buxton's script) includes off-screen rendering.
>  I want to render something and save it as a sequence of images, but I dont
> want to display it anywhere. Is there a way to 'hide' this window?
>  Thanks
>  Astan
>
>  --
>  "Formulations of number theory: Complete, Consistent, Non-trivial. Choose
> two."
>
>
>  Animal Logic
>  http://www.animallogic.com
>
>  Please think of the environment before printing this email.
>
>  This email and any attachments may be confidential and/or privileged. If
> you are not the intended recipient of this email, you must not disclose or
> use the information contained in it. Please notify the sender immediately
> and delete this document if you have received it in error. We do not
> guarantee this email is error or virus free.
>
>
>
>


Re: [pygame] PyOpenGL Screenshots

2008-05-12 Thread Astan Chee

Hi,
I was wondering if the latest solution to render pyopengl from pygame 
(Alistair Buxton's script) includes off-screen rendering.
I want to render something and save it as a sequence of images, but I 
dont want to display it anywhere. Is there a way to 'hide' this window?

Thanks
Astan

--
"Formulations of number theory: Complete, Consistent, Non-trivial. Choose two."


Animal Logic
http://www.animallogic.com

Please think of the environment before printing this email.

This email and any attachments may be confidential and/or privileged. If you 
are not the intended recipient of this email, you must not disclose or use the 
information contained in it. Please notify the sender immediately and delete 
this document if you have received it in error. We do not guarantee this email 
is error or virus free.





Re: [pygame] PyOpenGL Screenshots

2008-05-07 Thread Alistair Buxton
Here it is. I didn't spend any time making this code nice, but you can
just rip out the parts you need.

2008/5/8 Alistair Buxton <[EMAIL PROTECTED]>:
> I have a full example of doing exactly this task using python to
>  render to a series of png images (which you can load into something
>  like adobe premier), or a raw RV24 file (which you can transcode under
>  linux using... transcode). Will post it as soon as I've dug it out and
>  tested it still works. Includes examples of using transcode too.
>
>  2008/5/8 Ian Mallett <[EMAIL PROTECTED]>:
>
>
> > I figured out a way to do it in my program--Animation Shop Pro.  It would
>  > still be cool to have examples of how to do this without Animation Shop.  I
>  > was thinking ffmpeg or pil for doing so.  I looked around, but couldn't 
> find
>  > anything.
>  >  Thanks everyone,
>  > Ian
>  >
>
>
>
>  --
>  Alistair Buxton
>  [EMAIL PROTECTED]
>



-- 
Alistair Buxton
[EMAIL PROTECTED]
#!/usr/bin/env python

# Python OpenGL -> Video file
# (c) 2008 Alistair Buxton <[EMAIL PROTECTED]>
# Handy for doing procedural animations for compositing with other 
# videos in 

import os, random, math

from OpenGL.GL import *
from OpenGL.GLU import *
import pygame, pygame.image, pygame.key
from pygame.locals import *
from PIL import Image

##

# render settings

# 1 = best
QUALITY = 16

# whether to actually write output files or just preview
render_on = True

# If you don't want to write separate png files, you can just dump the output 
# from glReadPixels() into one huge file and encode it with transcode:

# transcode --use_rgb -i whatever.rv24 -x raw=RGB,null -y xvid4 -o output.xvid.avi -k -z  -f 25
# (for xvid)

# But beware that whatever.rv24 will be HUGE as it is uncompressed (not even RLE). 
# the size will be width*height*numframes*3 bytes, that's 31mb/sec for standard PAL video.

# Also worth mentioning: RV24 export is RGB, but png export is RGBA - thus if you use
# RV24 method, you will loose the alpha channel of your video.

# render type
# if true, write one big RV24 raw video file
# if false, write a png sequence
render_rv24 = False

if render_on:
# size of final render
w = 720
h = 576
else:
# size for preview
w = 720
h = 576

# how many frames to render before exiting
max_frames = 25

# framerate of rendered video
fps = 25.0

if render_rv24:
framefile = file("whatever.rv24", "wb")

##

# the snowflake animation stuff

flakes = []

class SnowFlake(object):
def __init__(self):
self.x = random.randrange(0,720)
self.y = random.randrange(0,576)

self.z = 3 + (random.randrange(3,20) / random.randrange(3,25))

self.dy = random.randrange(1,10)
self.drift = random.randrange(1,100)/1000.0 
self.rad = random.randrange(1,100)/100.0

def draw(self):
glColor4f(1.0,1.0,1.0,1.0)
if self.z < 0:
return
glBegin(GL_POLYGON)
r = math.floor(self.z * 4)
for i in range(int(r)):
glVertex2f( self.x+(self.z*math.sin(2*math.pi*(i/r))), self.y+(self.z*math.cos(2*math.pi*(i/r))) )
glVertex2f( self.x, self.y+self.z )
glEnd()


def update(self, ftime):

self.rad += ((ftime*0.5)+self.drift)
self.x += math.sin(self.rad)

self.y -= 0.7*ftime*(40.0+self.dy)*self.z;

if (self.y < -10):
self.y = 586

if (self.x < -10):
self.x = 730

if (self.x > 730):
self.x = -10

# standard opengl stuff init/draw/update/resize

def resize((width, height)):
if height==0:
height=1.0
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0, 720, 0, 576)
#gluOrtho2D(-(width/(2*height)), width/(2*height), 0, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

def init():
glShadeModel(GL_SMOOTH)
glClearColor(0.3,0.5,0.7,0.0)
glClearDepth(1.0)
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glDisable(GL_DEPTH_TEST)

for i in range(100):
flakes.append(SnowFlake())

def update(ftime):
for f in flakes:
f.update(ftime)

def draw():
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glDisable(GL_TEXTURE_2D)

for f in flakes:
f.draw()

###

# write a png file from GL framebuffer data

def png_file_write(name, number, data):
im = Image.frombuffer("RGBA", (720,576), data, "raw", "RGBA", 0, 0)
fnumber = "%05d" % number
im.save(name + fnumber + ".png")


Re: [pygame] PyOpenGL Screenshots

2008-05-07 Thread Alistair Buxton
I have a full example of doing exactly this task using python to
render to a series of png images (which you can load into something
like adobe premier), or a raw RV24 file (which you can transcode under
linux using... transcode). Will post it as soon as I've dug it out and
tested it still works. Includes examples of using transcode too.

2008/5/8 Ian Mallett <[EMAIL PROTECTED]>:
> I figured out a way to do it in my program--Animation Shop Pro.  It would
> still be cool to have examples of how to do this without Animation Shop.  I
> was thinking ffmpeg or pil for doing so.  I looked around, but couldn't find
> anything.
>  Thanks everyone,
> Ian
>



-- 
Alistair Buxton
[EMAIL PROTECTED]


Re: [pygame] PyOpenGL Screenshots

2008-05-07 Thread Ian Mallett
I figured out a way to do it in my program--Animation Shop Pro.  It would
still be cool to have examples of how to do this without Animation Shop.  I
was thinking ffmpeg or pil for doing so.  I looked around, but couldn't find
anything.
Thanks everyone,
Ian


Re: [pygame] PyOpenGL Screenshots

2008-05-07 Thread René Dudfield
hi,

as I mentioned in the other emails you can make gif images with at
least image magik, ffmpeg, and gimp.

cheers,



On Thu, May 8, 2008 at 6:28 AM, Ian Mallett <[EMAIL PROTECTED]> wrote:
> AWESOME!
> That screenshot taker works!  Thanks so much!
>
> Now, I could copy each frame individually to the animation maker, but I
> would prefer it automated.  Is there a way to make the screenshots be
> clumped together into a .gif file via a program?  (Incidentally, I agree
> about the implausibility of using a .gif file for a movie.  The gif animator
> I'm working with does exports).
>
> Ian
>


Re: [pygame] PyOpenGL Screenshots

2008-05-07 Thread Ian Mallett
AWESOME!
That screenshot taker works!  Thanks so much!

Now, I could copy each frame individually to the animation maker, but I
would prefer it automated.  Is there a way to make the screenshots be
clumped together into a .gif file via a program?  (Incidentally, I agree
about the implausibility of using a .gif file for a movie.  The gif animator
I'm working with does exports).

Ian


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