[PyOpenGL-Users] OpenGL textures
Brought to you by:
mcfletch
From: altern <al...@gm...> - 2007-03-29 08:25:42
|
hi I am trying to translate a pygame+opengl application to wx+opengl. And I am stuck at the function to import images to create OpenGL textures. I already asked for help on the wxpython list, but nobody seemed to be interested on my problem, so i thought there might be some wx-pyopengl users in the pyopengl list. This is the pygame code: surface = pygame.image.load(path) if surface.get_alpha is None: surface = surface.convert() else: surface = surface.convert_alpha() bin = pygame.image.tostring(surface, "RGBA", 1) w, h = surface.get_width(), surface.get_height() textid = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textid) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bin) ... and so on ... and this is the wx code i am using : image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) bin = image.ConvertToBitmap() w,h = image.GetWidth(), image.GetHeight() textid = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textid) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bin) ... etc ... It doesnt crash but the texture that OpenGL displays in not at all the image i am importing but some weird random colors. I guess this is the bit that i am missing, since printing "image.ConvertToBitmap()" returns a wxBitmap instance and not the image data bin = pygame.image.tostring(surface, "RGBA", 1) I have been trying to find out how to access the data an looking for examples on the net but did not find anything. any tips? thanks! enrike |