0

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

Andrei Bârsan
  • 3,473
  • 2
  • 22
  • 46

1 Answers1

3

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.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • That makes sense... the assets I was loading are from a D3D game. However, simply `*=-1`-ing the geometry when loading it produces broken results, as if only the backfaces were being shown. – Andrei Bârsan May 20 '13 at 13:43
  • Never mind - I had to reverse the order in which the faces' vertices were being rendered as well. It's working now. – Andrei Bârsan May 20 '13 at 14:18