Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tabasco

Pages: [1]
1
Graphics / upside-down textures in OpenGL
« on: June 03, 2009, 03:06:58 pm »
Nobody has suggested that it's always the standard, only that it's the standard in OpenGL.
My guess would be that multi-API engines simply store the texture based on the standard for what API they're using.  In addition to DirectX using top-left origin for UV's, the texture is probably not stored upside-down, so the UV's and textures you would get from modeling software would work either way.

2
Graphics / upside-down textures in OpenGL
« on: June 01, 2009, 05:42:45 pm »
I'm content to just flip the sf::Image myself.  I would say that if anything needs done in SFML it would be to provide a convenience function like Image->Flip or simply provide a comment in the OpenGL example describing the issue. (Maybe both?)

3
Graphics / upside-down textures in OpenGL
« on: May 31, 2009, 11:34:37 pm »
It's been bottom left since I've been using opengl and every other engine or framework I've used treats it that way.  When I export models from blender, and presumably any other modeling software, the UV's are/would be all upside down.
The article I posted is from opengl.org and the author (http://en.wikipedia.org/wiki/Mark_Kilgard) is credible, so if that's not enough proof, I don't know what is.
It really is shocking to me that it isn't documented any better than it is but opengl clearly reads textures starting with the bottom row.

4
Graphics / upside-down textures in OpenGL
« on: May 28, 2009, 12:57:07 am »
Thanks!  I appreciate that you're really active on this project and I'm looking forward to seeing how it grows.

In the mean time I'm just flipping rows like this

Code: [Select]

    GLuint imgsize = (Image.GetWidth() * Image.GetHeight()) * 4;
    GLuint rowsize = Image.GetWidth() * 4;
    sf::Uint8 *newimg = (sf::Uint8*) malloc(imgsize+1);
    const sf::Uint8 *oimg = Image.GetPixelsPtr();

    GLuint x;
    for(x = 0; x < Image.GetHeight(); x++)
    {
        memcpy(newimg + (x * rowsize), (oimg + imgsize) - (rowsize + (rowsize * x)), rowsize);
    }
    //Is this necessary?
    newimg[imgsize+1] = '\0';

5
Graphics / upside-down textures in OpenGL
« on: May 26, 2009, 12:45:16 am »
I'm surprised this isn't explained better than it is.  So far the best I've found is point 12 here:
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

Quote
Another common pitfall related to 2D rendering APIs having an upper left-hand coordinate system is that 2D image file formats start the image at the top scan line, not the bottom scan line. OpenGL assumes images start at the bottom scan line by default.


The NeHe tutorials and other implementations I've found scattered across the Internet all flip the image so that the origin is at the lower-left corner as well, but they don't explain why.  :(

I guess my question now is, what's the fastest way to swap the row order in an sf::Image?

6
Graphics / upside-down textures in OpenGL
« on: May 25, 2009, 10:27:31 pm »
Quote from: "Laurent"
The OpenGL demo uses a perspective projection with the Y axis pointing upwards. The result is just as expected.


If it's the projection, wouldn't all of my geometry be upside-down as well, not just the texture assignment?
Based on how opengl views texture coordinates
( http://www.gamedev.net/reference/programming/features/ogltm/texcoord.jpg )
the texture should not be upside-down on the above quad.
The quad starts in the lower left corner, then the upper left, moving clockwise and the texture coordinate provided for the bottom corner of the quad would correlate to the bottom corner of the texture image.

After a little more reading I came across this:
http://www.devolution.com/pipermail/sdl/2005-February/067479.html

If the data provided by sf::Image uses a top-left origin, it would be upside down in OpenGL.

7
Graphics / upside-down textures in OpenGL
« on: May 25, 2009, 08:22:21 pm »
Just to be thorough, I made some adjustments to the OpenGL demo program bundled with SFML1.4.

The rotation has been removed and all of the quads but one have been commented out.

Code: [Select]

glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, 50.f);
glTexCoord2f(0, 1); glVertex3f(-50.f,  50.f, 50.f);
glTexCoord2f(1, 1); glVertex3f( 50.f,  50.f, 50.f);
glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, 50.f);


http://tyranny.ckt.net/tabasco/smile.jpg

8
Graphics / upside-down textures in OpenGL
« on: May 25, 2009, 07:34:47 pm »
I've been moving one of my projects from GLFW to SFML.  The transition has been relatively simple, but with SFML when I load my models the textures are upside-down.

I have some models that I've made and UV-mapped in blender as well as some procedurally generated terrain meshes and the behavior has been the same.  I've tried storing the textures as jpg and png instead of tga, but as of yet, the only way I can get it looking right is to go into gimp and mirror the image.

This is what I'm getting:
The textures, original and flipped: http://tyranny.ckt.net/tabasco/kilntex.jpg

The results:
http://tyranny.ckt.net/tabasco/kiln1.jpg
http://tyranny.ckt.net/tabasco/kiln2.jpg

(I'm not particularly artistic, but there it is)

I'm loading textures almost exactly like I did in GLFW and SDL before that.  There are only a few minor differences:

Code: [Select]

    sf::Image Image;

    if (!Image.LoadFromFile(texname)) { return(0); }

    glGenTextures(1, &texid);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glBindTexture(GL_TEXTURE_2D, texid);

    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.GetWidth(), Image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, Image.GetPixelsPtr());


I've compiled it in Windows XP and Ubuntu 9.04 with no visible difference.
Any ideas?

Pages: [1]
anything