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

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



You want pixels2d, which gives you a variable which _references_ the data. While the reference is still there, the surface is locked (otherwise you could change the data mid-blit, which would be bad). Instead, you should use:

del (variable with pixels2d in it)

right before you pass it off to GL or pygame.

Also, how are you setting up opengl? I haven't gotten that working (hence why I've looked into surfarray).

Also, if you are dropping to a reasonably moniterable framerate (~120 or so and below) you can check to see what is taking too long. Simply separate your commands with calls to time.time() and check at the end. you can print out the time required (possibly on keypress?) and it'll show you what is taking so long:

firstTime = time.time()
(create texture)
aCheckpoint = time.time()
(draw your sprites)
bCheckpoint = time.time()
(scale)
cCheckpoint = time.time()

print firstTime, aCheckpoint - firstTime, bCheckpoint - aCheckpoint - firstTime [etc]

This'll give you the time used (in milliseconds) for each step of the frame. While I have my own suspicions of what is taking so long, timing it will show us for certain.


On Wed, Jul 30, 2014 at 9:35 PM, VertPingouin <sylvain.boussekey@xxxxxxxxxxxxxxx> wrote:
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().
>