difficulties loading a texure

Started by
1 comment, last by UeberBobo 17 years, 4 months ago
hi all, i got a problem loading and displaying a texture in OpenGL, using python (pyOpenGL) the texture shows up, but it looks like garbage data. ive made a test texture, a 2x2 red/black checkerboard BMP

| red     black |
| black  red    |
my code looks like this

    image = Image.open(filename)
    image = frombuffer(image.tostring(), ubyte)
    print image
    glBindTexture (GL_TEXTURE_2D, id);
    glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

the print statement produces:

    [255   0   0   0   0   0   0   0   0 255   0   0]
the result on screen is a quad with 4 different colored areas (non of them either red or black, both red/black pixels arent even the same color) should i give the data in a different format, like as a 2x2x3 matrix? ive played around with and searched the forum, but i just can't get it right any help on how you usually do this is greatly appreciated, some python specific advice ever more... thanks :) [Edited by - UeberBobo on December 15, 2006 1:19:37 AM]
//---------//Ueberbobo//*********
Advertisement
never used pyOGL.

Did you ever call glGenTexture(1, &id)? You have to do that to mark an area in memory as being used in opengl.


//dont really think u need this.
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


Every thing else looks fine, maybe post a screen?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

OK, so apparently the function expected a String, problem solved by simply changing it to:

image = image.tostring()

all that numPy reshaping of arrays for nothing :)
//---------//Ueberbobo//*********

This topic is closed to new replies.

Advertisement