SgtMe 46 Veteran Poster Featured Poster

Hi.

I am trying to get texturing to work in PyOpenGL in 2D. I have the following code so far for textures:

def tex(path):
    img = pygame.image.load(path)
    img.convert_alpha()
    try:
        ix, iy, image = img.get_width(), img.get_height(), pygame.image.tostring(img, 'RGBA')
    except SystemError:
        ix, iy, image = imgs.get_width(), img.get_height(), pygame.image.tostring(img, 'RGBA')
    ID = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, ID)
    glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
    return ID

This is in an external script that I call from my programs, and it produces the following error:

Traceback (most recent call last):
  File "<PATH>", line 39, in <module>
    Main()
  File "<MY_PATH>", line 20, in __init__
    self.menu()
  File "<MY_PATH>", line 23, in menu
    glGenTextures(1, glTex2D.tex('start.png'))
  File "<MY_PATH>", line 16, in tex
    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
  File "C:\Python26\lib\site-packages\OpenGL\latebind.py", line 45, in __call__
    return self._finalCall( *args, **named )
  File "C:\Python26\lib\site-packages\OpenGL\wrapper.py", line 791, in wrapperCall
    raise err
OpenGL.error.GLError: GLError(
        err = 1281,
        description = 'invalid value',
        baseOperation = glTexImage2D,
        pyArgs = (
                GL_TEXTURE_2D,
                0,
                3,
                270,
                100,
                0,
                GL_RGBA,
                GL_UNSIGNED_BYTE,
                '\xff\x00\x00\xff\xff\x00\x00\xff\xff...,
        ),
        cArgs = (
                GL_TEXTURE_2D,
                0,
                3,
                270,
                100,
                0,
                GL_RGBA,
                GL_UNSIGNED_BYTE,
                '\xff\x00\x00\xff\xff\x00\x00\xff\xff...,
        ),
        cArguments = (
                GL_TEXTURE_2D,
                0,
                3,
                270,
                100,
                0,
                GL_RGBA,
                GL_UNSIGNED_BYTE,
                '\xff\x00\x00\xff\xff\x00\x00\xff\xff...,
        )
)

Please can somebody help me with this.
Thank you very much for yoru time.
Mark

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.