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

**URL:** <https://discourse.libcinder.org/t/solved-applying-colortexture-from-fbo-to-a-geom-cube-with-unexpected-results/1826>\
**Category:** Using Cinder\
**Created:** [June 3, 2021, 9:10am UTC](https://discourse.libcinder.org/t/solved-applying-colortexture-from-fbo-to-a-geom-cube-with-unexpected-results/1826 "2021-06-03T09:10:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [June 3, 2021, 9:10am UTC](https://discourse.libcinder.org/t/solved-applying-colortexture-from-fbo-to-a-geom-cube-with-unexpected-results/1826/1 "2021-06-03T09:10:11Z")

</div>

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:

 ![Screenshot (32)](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/fd295e1b51dea6f0602808c8444ae5f7f90024dd.png)

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

---

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [June 6, 2021, 12:45am UTC](https://discourse.libcinder.org/t/solved-applying-colortexture-from-fbo-to-a-geom-cube-with-unexpected-results/1826/2 "2021-06-06T00:45:58Z")

</div>

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:

> <https://stackoverflow.com/questions/48124001/opengl-texture-coordinates-are-opposite-when-reading-from-a-framebuffer-object>

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.

---

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [June 6, 2021, 8:17am UTC](https://discourse.libcinder.org/t/solved-applying-colortexture-from-fbo-to-a-geom-cube-with-unexpected-results/1826/3 "2021-06-06T08:17:21Z")

</div>

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!

```auto
	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
