Incompatibility with Renpygame and Ren'py 6.99 - pygame_SDL2

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
User avatar
morte111
Newbie
Posts: 4
Joined: Tue Mar 31, 2015 8:31 pm
Projects: AnimeGen
Location: Australia
Contact:

Incompatibility with Renpygame and Ren'py 6.99 - pygame_SDL2

#1 Post by morte111 »

renpygame framework v1.2 with the font.py fix described in this post http://lemmasoft.renai.us/forums/viewto ... 39#p330982
works just fine on Ren'Py 6.17 and 6.18
however both with and without the font.py fix,
renpygame-demo v1.2 aliens.py does not work with Ren'Py 6.99.1 or 6.99.3


Traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 11, in script
    $ import aliens
  File "game/script.rpy", line 11, in <module>
    $ import aliens
AttributeError: 'module' object has no attribute 'Overlay'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 11, in script
    $ import aliens
  File "D:\dev\renpy\renpy-6.99.3-sdk\renpy\ast.py", line 785, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\dev\renpy\renpy-6.99.3-sdk\renpy\python.py", line 1445, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 11, in <module>
    $ import aliens
  File "D:\dev\renpy\renpy-6.99.3-sdk\renpy\loader.py", line 607, in load_module
    exec code in mod.__dict__
  File "aliens.py", line 4, in <module>
  File "D:\dev\renpy\renpy-6.99.3-sdk\renpygame-demo\renpygame\__init__.py", line 28, in <module>
    Overlay = pygame.Overlay
AttributeError: 'module' object has no attribute 'Overlay'

Windows-7-6.1.7601-SP1
Ren'Py 6.99.3.404
Update 2015/05/08:
Thx to PyTom who answered in this thread yesterday:
http://lemmasoft.renai.us/forums/viewto ... me#p370060

This is apparently caused by the migration to pygame_SDL2.
Until that is addressed, "User/Creator Defined Displayables" are the only advised option.

I am attempting to use pygame.image save function
- ultimately trying to export a flattened livecomposite Ren'Py image to a pygame surface and then to a .PNG file with alpha channel,
because I can't find any functions which expose an image buffer at a pixel/binary level inside Ren'Py.
(renpy.load_surface in 6.99 aside which I thought was for external use by pygame... which is not compatible now...)


Update 2015/05/14:
renpy.load_surface(im) is suggested by PyTom here:
http://lemmasoft.renai.us/forums/viewto ... ce#p370555
however that function requires an image as input, and rejects the general displayable type returned by Flatten:

Code: Select all

Exception: Expected an image, but got a general displayable.
Ren'Py doc states that a displayable can be assigned to an image name via the image statement:
A displayable is an object that can be shown to the user. Ren'Py displayables can be used in many ways.
Assignment to an image name using the image statement.
Tried that a few ways, this seems to work:
image char = DynamicDisplayable(draw_char) # using DynamicDisplayable ensures changes are visible immediately
image charflat=Flatten("char")

However, then have to get load_surface to honour the image as an image,
as the utility methods listed in doc http://www.renpy.org/doc/html/udd.html
don't work directly inside renpy init python or start method contexts

i.e. these do not work:
$charsurf=renpy.load_surface("charflat")
IOError: Couldn't find file 'charflat'.

$charsurf=renpy.load_surface(charflat)
NameError: name 'charflat' is not defined

charsurf=load_surface("charflat")
File "game/animegen.rpy", line 169: expected statement.

charsurf=load_surface(charflat)
File "game/animegen.rpy", line 169: expected statement.


Guess I have to encode the load_surface into an init python creator defined displayable class with a customised method...
will do more testing.

Also no doco on whether load_surface then exposes pixel data directly or through as-yet-undocumented methods (perhaps inherited from pygame surface object?)

Update 2015/05/17
I think I found the doco I need to work with pygame.surface here:
http://www.pygame.org/docs/ref/surface.html
Just hoping it is still relevant for SDL2.
Many thanks also to the excellent step-by-step explanation within Trooper6' Clock tutorial (Creator Defined Displayable) here:
http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
without which I would be sorely scratching my head.
For the time being, I am more than willing to accept things at face value such as "don't ask why, you just need to do this"

So, currently I am using the Appearing class demo code in Ren'Py CDD doco,
trying to convert the contents on the surface pixel buffer into a format for writing out to external file

Update 2015/05/17 Part2:
Ok, getting nowhere with pygame.Surface methods while trying to access list items from surface pixel/buffer address -
as a test, initially trying to read buf[0] (or at least, to print str(buf[0] to stdout) where:
buf=surf._pixels_address
TypeError: 'long' object has no attribute '__getitem__'

buf=surf.get_buffer()
TypeError: 'int' object has no attribute '__getitem__'

buf=surf.get_view('0')
File "pygame_sdl2/surface.pyx", line 738, in pygame_sdl2.surface.Surface.get_view (gen\pygame_sdl2.surface.c:10253)
error: Surface.get_view is not supported.

Instead, tried to directly import pygame_sdl2.image in order to use pygame.image.save
(which incidentally is what I tried to do a month ago but erroneously using pygame)
from recommendations here: https://github.com/renpy/pygame_sdl2
advising:
There isn't much pygame_sdl2 documentation at the moment, especially for end-users. Check out the pygame documentation at:
http://www.pygame.org/docs/
There is one new api we should mention. Running the code:
import pygame_sdl2
pygame_sdl2.import_as_pygame()
Will modify sys.modules so that pygame_sdl2 modules are used instead of their pygame equivalents. For example, after running the code above, the code:
import pygame.image
img = pygame.image.load("logo.png")
will use pygame_sdl2 to load the image, instead of pygame. (This is intended to allow code to run on pygame_sdl2 or pygame.)
That didn't quite work, citing this warning message to stdout/stderr:
E:\dev\renpy\renpy-6.99.3-sdk\renpy\minstore.py:7: UserWarning: Pygame has already been imported, import_as_pygame may not work.
# publish, distribute, sublicense, and/or sell copies of the Software,

-instead I did this

Code: Select all

  import pygame_sdl2.image
...
      pygame_sdl2.image.save(surf,"test.png")
which [kind of] works - at least, it saves the png file to my renpy lib:
E:\dev\renpy\renpy-6.99.3-sdk\lib\windows-i686
so I suppose next step is to figure out how to write to the renpy game saves directory instead.

Still, can't complain, making progress, and now I can dispense with handcoded .png data packing and file open/write/close!

Update 2015/05/18:
Will try using config.savedir to set png file output location.
file:///E:/dev/renpy/renpy-6.99.3-sdk/doc/config.html

Update 2015/05/20:
Got pygame_SDL2.image.save to work with logo.png, but cannot get it to work with an in-game image.
Added this question to forums:
http://lemmasoft.renai.us/forums/viewto ... =8&t=32203

Post Reply

Who is online

Users browsing this forum: No registered users