Sign in to follow this  
UeberBobo

OpenGL difficulties loading a texure

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this