So, I've just started learning OpenGL with PySDL2, and I've created a class that will create a cube to the window that I've created with PySDL2. What I'd like to do now, is to figure out a way to texture the cube. I don't believe that the actual texturing part is the problem, but actually loading the image. I've tried to do this with PySDL's image loader, but this causes an error from the OpenGL texture creator. Here is my code to load an texture and bind it to OpenGL:
def LoadTexture(self, filename): """Loads a texture for the cube""" surface = SDL_LoadBMP(filename) #Checks if the loading succeeded if surface: #Translate the LP_SDL_Surface-pointer got from SDL_LoadBMP() to a real SDL_Surface texture_surface = surface.contents texture_format = GL.GL_RGBA GL_TEXTURE_ID = GL.glGenTextures(1) GL.glBindTexture(GL.GL_TEXTURE_2D, GL_TEXTURE_ID) GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, texture_surface.w, texture_surface.h, 0, texture_format, GL.GL_UNSIGNED_BYTE, texture_surface) return GL_TEXTURE_ID return None
And the error that gives looks like this:
TypeError: ("No array-type handler for type <class 'sdl2.surface.SDL_Surface'> (value: <sdl2.surface.SDL_Surface object at 0x030762B0>) registered", <OpenGL.GL.images.ImageInputConverter object at 0x02EC49F0>)
I'm using Python 3 so using something like PIL won't work for me. Any ideas how to get the texture loaded, preferably with PySDL2?