[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame.surfarray.pixels2d does not work with OpenGL?



You could create an empty surface with RGBA order, then blit to it:

image = pygame.image.load(filename)
surf = pygame.Surface(image.get_size, pygame.SRCALPHA, 32, masks=(0xFF, 0xFF00, 0xFF0000, 0xFF000000))
surf.blit(image, (0,0))

But there is no way to load an external file into a surface with a different format. Maybe, if the PNG file had the desired RGBA order to start with... (Is that even possible?)


Nov 2, 2011 05:28:17 AM, pygame-users@xxxxxxxx wrote:
Mmh, I see. Is there any way to have a 32 bit source alpha surface
have pixels in that order? Or is there any other way how to speed up
my code by replacing tostring?

On Tue, Nov 1, 2011 at 10:14 PM, Lenard Lindstrom wrote:
> Hi,
>
> Function tostring unmaps each pixel into an RGBA sequence, with the R byte
> lowest. Function pixels2d returns a view of the actual surface memory. A 32
> bit source alpha surface need not, and probably does not, have pixels in an
> RGBA order.
>
> Lenard Lindstrom
>
> On Oct 31, 2011, Florian Krause wrote:
>
> Hi everyone,
>
> can anyone tell me what I am doing wrong here?
> Please have a look at the attached example code.
>
> When using pygame,image.tostring for getting the pixel values to
> transform them into a texture, everything works well (see the
> outcommented part with WORKS).
>
> However, when I replace this part with pygame.surfarray.pixels2d, then
> the resulting texture seems broken for some reason.
>
> Does anyone have an idea what is going on here?
>
> Thanks in advance,
> Florian
>



--
www.fladd.de - fladd.de: Homepage of Florian Krause
blog.fladd.de - fladd's Blog: Blog of Florian Krause
intermezzo.fladd.de - Intermezzo: Music by Florian Krause and Giacomo Novembre