[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] OpenGL textures flipped



Hey, all.

An OpenGL noob problem. Loading a texture from an image, let's say some.png, is oriented upside-down and backwards when displayed. I've noticed this in two cases, I'll present the simplest.

I was looking at this nice module http://www.pygame.org/wiki/SimpleOpenGL2dClasses?parent=CookBook. I made a 32x32 image in GIMP according to the module's instructions and put an alphabetic character (L in the upper left corner) on it so I could see the orientation. When I run the module's __main__ demo the image is displayed upside-down and backwards. The image is attached to this post for those who care to try this.

I experimentally modified the code in function createTexDL based on a recollection of something I read once: the coordinate system for geometric objects (lines, triangels, etc.) is not the same as that for textures. Geometry has origin 0,0 at the bottom left corner, whereas textures have origin 0,0 at the upper left corner.

So the original code which displays upside-down/backwards...

    # Bottom Left Of The Texture and Quad
    glTexCoord2f(0, 0); glVertex2f(0, 0)
    # Top Left Of The Texture and Quad
    glTexCoord2f(0, 1); glVertex2f(0, height)
    # Top Right Of The Texture and Quad
    glTexCoord2f(1, 1); glVertex2f( width,  height)
    # Bottom Right Of The Texture and Quad
    glTexCoord2f(1, 0); glVertex2f(width, 0)

Became this, the "right" orientation facing forward and upright...

    # Bottom Left Of The Texture and Quad
    glTexCoord2f(0, 0); glVertex2f(0, height)
    # Bottom Right Of The Texture and Quad
    glTexCoord2f(1, 0); glVertex2f( width,  height)
    # Top Right Of The Texture and Quad
    glTexCoord2f(1, 1); glVertex2f(width, 0)
    # Top Left Of The Texture and Quad
    glTexCoord2f(0, 1); glVertex2f(0, 0)

I'm posing this puzzle because I can't find where I think I may have read about the coordinate systems (I *will*, but in the meantime this is eating at me). I don't know enough yet to tell if this flip-behavior is due to an anomaly in my OpenGL environment or if the way I've mapped the texture is correct. And I'm sure the module's author saw that his/her images displayed correctly, which kinda makes me unsure of anything.

You OpenGL experts, could you please properly align my thinking on this topic?

Thanks. :)

Gumm

Attachment: foo.png
Description: PNG image