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

Re: [pygame] Creating surfaces from OpenGL buffers



Benjamin Olsen wrote:
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.

If you didn't initialize OpenGL, the OpenGL commands probably didn't have any effect at all (I wouldn't even be surprised if this could lead to a crash on some systems).
Before any OpenGL commands can be used, you have to set up an OpenGL context which relates your GL commands to a particular framebuffer. pygame does all this for you once you set the OPENGL flag.
An application can also create several OpenGL contexts (e.g. for several windows) from which one is always the "current" context, i.e. the context that is affected by your GL commands. When you want to draw to another window, you have to make the corresponding context the "current" context and then you can issue your OpenGL commands.
I don't know if pygame really supports having several contexts (I don't think so).


- Matthias -