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

[pygame] Creating surfaces from OpenGL buffers



Something mentioned to me today got me wondering if it would be possible
to create a pygame surface from the PyOpenGL buffer. To test it, I
grabbed one of the Pygame NEHE tutorials (lesson04.py) and started
dropping pieces of it into a typical Pygame setup.

I set up a display with the default mode instead of OPENGL. I put
together a quick "bouncing ball" example so I could see Pygame running.
Then I put the OpenGL functions into the startup section (i.e. resize()
and init() from the NEHE example). No problem. I put the draw() function
into the main loop, and again no problem.

So I started trying to get the OpenGL buffer and draw it to a surface.
These two functions *seem* to be doing something like that:
  pixels = glReadPixels(0,0,640, 480, GL_RGB,GL_UNSIGNED_BYTE)
  glsurf = pygame.image.fromstring(pixels, (640, 480), 'RGB', 1)

I tried to blit that to the screen, and just got a big black screen. I
tried using GL_RGBA and 'RGBA' in the args, and this time I got the
background with the bouncing ball. So adding the alpha made the entire
surface clear.

I tried adding a:
  glsurf.convert()
but it didn't do anything.

I know that glReadPixels is returning a string of the correct size
because pygame.image.fromstring accepts it and turns it into a surface.
It just seems to be returning a big string of blank pixels.

Do I need to do something to get PyOpenGL to draw to the buffer that
glReadPixels is looking at? When Pygame's display mode is set to OPENGL,
how does it find the buffer to draw from?

Thanks,

Ben