Re: [pygame] OpenGL stretch of a pygame.Surface

2014-07-30 Thread VertPingouin
Ok I now create my texture once.

I'm having some issues with this

> You're creating an extra copy of the texture data here.
> To avoid that, you could use surfarray to create a surface
> backed by a numpy array, do your drawing into that, and
> then pass the numpy array directly to glTexImage2D.

As I understand it, you suggest a surface with a surfarray.pixel2d bound
to it. But I can't blit on such surface beacause it's locked. Did you
mean drawing directly in surfarray or just create and update a
surfarray.2darray which involve to do a copy of the native screen also ?


Thanks for all your advises everyone. 


Le mercredi 30 juillet 2014 à 11:15 +1200, Greg Ewing a écrit :
> sylvain.boussekey wrote:
>  > I managed to do it in opengl but perfs are poor.
> 
> A few things to consider:
> 
>  > textureData = pygame.image.tostring(textureSurface, "RGBA", 1)
> 
> * You're creating an extra copy of the texture data here.
> To avoid that, you could use surfarray to create a surface
> backed by a numpy array, do your drawing into that, and
> then pass the numpy array directly to glTexImage2D.
> 
>  > texture = glGenTextures(1)
>  > glBindTexture(GL_TEXTURE_2D, texture)
>  > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
>  > glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
> 
> * You're creating a new OpenGL texture for each frame and
> then discarding it. Try making these calls just once
> at the beginning and re-using the texture.
> 
> * You're using a non-power-of-2 texture size. Not all
> OpenGL implementations support that; yours seemingly does,
> but it might be less efficient than a power-of-2 size.
> You could try allocating the next larger power-of-2 size and
> updating the part that you use with glTexSubImage2D().
> 




Re: [pygame] OpenGL stretch of a pygame.Surface

2014-07-28 Thread vertpingouin
to Sam :
I'm using HWSURFACE flag but I got exatly the same framerate. The ideal
would be to rewrite everything in openGL but I don't know it well...
yet. 

to Noel:
On the topic of performing transform one time only, I'm not sure what
mean here. If I scale my surface one time, it gets, say, 1920x1080, but
then blitting is done only of a 640x480 part of the surface... So maybe
I misunderstood something here.

I'm using this to transform :

pygame.transform.scale(self.native, (SCREENWIDTH, SCREENHEIGHT),
self.screen)

where native is the little one and screen the big one. I assume that
self.native is scaled then blit onto self.screen...

I think this is the blitting that is slow because if I use a lesser
resolution for self.screen, I almost get back my precious frames per
second.

It will be really cool to send my little native surface to my graphic
card, then let it scale by itself. Don't know if it's even possible.


Le lundi 28 juillet 2014 à 11:50 -0400, Noel Garwick a écrit :
> Right now you are blitting tiles to a 640x480 surface, and then
> performing a transform on the whole surface and then blitting it to
> the display?
> 
> 
> If this is the case, then try to only perform the scale operation when
> the resolution is changed (instead of once each frame) and see how
> that works.  I know you mentioned that the full screen blit operation
> seems to be the main bottleneck, but this should help too.
> 
> 
> 
> 
> 
> 
> 
> On Mon, Jul 28, 2014 at 7:32 AM, Sam Bull 
> wrote:
> On lun, 2014-07-28 at 06:54 +0200, VertPingouin wrote:
> > So I came up with the idea of an hardware opengl texture
> stretching
> > instead of a dumb blit but I don't know how to achieve it.
> >
> > Anyone has already done this ?
> >
> 
> 
> You would just need to code the graphics in OpenGL without
> using
> pygame.Surface and pygame.draw. First though, check you are
> using the
> HWSURFACE flag, if you are running fullscreen, it's possible
> this might
> provide the necessary speedup without going to OpenGL.
> 
> http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode
> 
> 




[pygame] OpenGL stretch of a pygame.Surface

2014-07-27 Thread VertPingouin
Hi everyone,

I try to make a little 2d engines for my needs. I use the gameobject
library which bring me to a really really decent frame rate (between 400
and 2000 FPS depending on the computer). But I wanted to do some
beautiful pixel art so every frame, I pygame.transform.scale my 640 x
480 display into my native resolution. Despite the fact I carefully have
converted my surfaces to match each other, FPS is really slower (can't
have constant 60FPS anymore !). After a few investigation, the
transformation is slow but not as the blitting of an 1920x1080 surface.

So I came up with the idea of an hardware opengl texture stretching
instead of a dumb blit but I don't know how to achieve it. 

Anyone has already done this ?