Question

I am working on a 3D renderer, and as I was loading various test models, I noticed that everything looked OK, except for the fact the the textures were all flipped on the x-axis.

This is actually previewed as I'm blitting my GBuffer to the screen, so it can't be a FBO-rendering problem.

After I load each .obj file, I prepare its VBOs. Here's the snippet setting up the texture coordinates:

for(Face f : master.faces) {
    for(int i = pointsPerFace - 1; i >= 0; i--) {
        uv[0] = f.texCoords[i].x;
        uv[1] = f.texCoords[i].y;
        texcoords.append(uv);
    }
}

Things like replacing a coordinate with 1 - coordinate don't really work, since that would flip the whole bitmap, not just the current triangle.

What could cause everything to be rendering x-flipped?

Everything looks fine, except it's flipped sideways

Was it helpful?

Solution

except for the fact the the textures were all flipped on the x-axis.

I think what's actually happening is, that the model's geometry is flipped on the Z axis. The usual transformation setup used with OpenGL uses a right handed coordinate system. If the object has been designed saved for left handed, one axis is swapped and this also affects the texture application of course.

Things like replacing a coordinate with 1 - coordinate don't really work

Yes it would, because…

since that would flip the whole bitmap, not just the current triangle.

… that's exactly what you'd require, if doing it this way. But first I'd check if the model geometry is loaded correctly, i.e. with the right handedness. If not, I'd simply flip the Z axis of the geometry.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top