I have a program that is written in python and uses pygame along with pyopengl. The only problem is, I can't draw anything on the screen with pygame.draw which is what I was going to use for interfacing with my program. I would like to know if there is a way to draw using pygame's system while also drawing 3D using pyopengl behind it.
In this PyGame and Python programming tutorial video, we cover how to draw shapes with PyGame's built in drawing functionality. We can do things like draw specific pixels, lines, circles, rectangles, and any polygon we want by simply specifying the points to draw between. Let's get started!
You can't do that directly.
However you can draw on a pygame.Surface
object with the pygame.draw
module or pygame.Surface.blit
. Use pygame.PixelArray
to access the pixels on the surface directly. Use the pixels to generate an OpenGL Texture object. This texture can be used in OpenGL.
In the other direction you can render into a OpenGL Renderbuffer or Texture object (see Framebuffers). Load the texture onto the GPU with glReadPixels
or glGetTexImage
and create a pygame.Surface
with pygame.image.frombuffer
.
See also Does PyGame do 3d?, PyGame and ModernGL library, PyGame and OpenGL 4 or PyGame and OpenGL immediate mode (Legacy OpenGL).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With