Jump to content
  • Advertisement
Sign in to follow this  
UeberBobo

OpenGL difficulties loading a texure

This topic is 4209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!