[Solved] Applying ColorTexture from FBO to a geom::Cube with unexpected results

I’ve rendered a scene into an FBO and then applied the texture directly to a geom::Cube with Cinders stock texture shader. Rendering the cube on top of the scene looks as follows:

My biggest surprise is that the texture is backwards on all sides. Is this normal?

I know that flipping the texture coordinate mapping would solve this, but I feel like mapping a the FBO texture directly on to a cube without fiddling with the texcoords would have the texture not be backwards?

Any thoughts are most welcome!

Cheers,
Gazoo

It would seem that this is a lovely top-left v. bottom-left co-ordinate issue - i.e. unrelated to Cinder specifically. More details here:

I expect the easiest approach is likely to flip the texture coordinates in anticipation of the image being upside-down / reversed from a typical texture, in the renderbuffer. Will update when I have a final solution.

The temporary solution ended up being hard-coding some new texture co-ordinates when rotating textures, and flipping some to compensate for OpenGL’s interpretation of co-ordinates.

The code below shows one (semi-)hacky approach on how to do this. Note that the code assumes indexing for the surfaces it wants to rotate. A more robust solution, would detect the proper indices by observing the normals for the vertices and picking the 4 vertices matching a particular direction.

Hopefully this helps anyone else playing around with geom’s and TexCoords!

	ci::TriMesh cubeTriMesh = cube1; // cube1 is a geom::Cube()

	auto numVertices = cubeTriMesh.getNumVertices();
	auto* texCoord = cubeTriMesh.getTexCoords0<2>();
	auto normalsIter = cubeTriMesh.getNormals().begin();

	// Rotating textures require more than "flipping" co-ordinates

	// Manually over-write posZ facing side (towards camera)
	texCoord[8] = { 0.0, 0.0 };
	texCoord[9] = { 0.0, 1.0 };
	texCoord[10] = { 1.0, 0.0 };
	texCoord[11] = { 1.0, 1.0 };

	// Overwrite bottom -box uv
	texCoord[16] = { 0.0, 0.0 };
	texCoord[17] = { 0.0, 1.0 };
	texCoord[18] = { 1.0, 0.0 };
	texCoord[19] = { 1.0, 1.0 };

	// Overwrite positive x, right side uv
	texCoord[0] = { 0.0, 0.0 };
	texCoord[1] = { 0.0, 1.0 };
	texCoord[2] = { 1.0, 0.0 };
	texCoord[3] = { 1.0, 1.0 };

	for (size_t i = 0; i < numVertices; ++i)
	{
		if (*normalsIter == ci::vec3(0, 0, -1.0f))
		{
			texCoord->s = 1.0f - texCoord->s; // Back-side needs to be flipped
		}

		++position;
		++texCoord;
		++normalsIter;
	}

	return cubeTriMesh;

Cheers,
Gazoo