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

Re: [pygame] blit speedup



On Sun, Mar 28, 2010 at 3:29 PM, Wakefield, Robert <rjw03002@xxxxxxxxxxxxxx> wrote:
Do you have any recommendation for the best way to get an OpenGL engine running, especially going Pygame surface to OpenGL texture?  I'd like to preserve platform-independent .py files or executables if possible.
Google is your friend:
textureSurface = pygame.image.load(path)
textureData = pygame.image.tostring(textureSurface,"RGB",1)
width = textureSurface.get_width()
height = textureSurface.get_height()
 
texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texture)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

This
is quite cross-compatible.
I had previously coded a simple engine with OpenGL/C++, and trying to get textures from LibPNG or the like proved to be a headache even on different machines, let alone a separate OS.
There are quite a few code samples (and complete OpenGL libraries (including mine)) on pygame.org.  As far as I know, most are cross-compatible. 
Ian