# Texture2d from Data without clamping

**URL:** <https://discourse.libcinder.org/t/texture2d-from-data-without-clamping/285>\
**Category:** Using Cinder\
**Created:** [September 26, 2016, 10:14pm UTC](https://discourse.libcinder.org/t/texture2d-from-data-without-clamping/285 "2016-09-26T22:14:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![balachandran\_c](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@balachandran\_c](https://discourse.libcinder.org/u/balachandran_c)\
**Post date:** [September 26, 2016, 10:14pm UTC](https://discourse.libcinder.org/t/texture2d-from-data-without-clamping/285/1 "2016-09-26T22:14:43Z")

</div>

Hi,

I am trying to create a texture from data as shown below:

> gl::Texture2d::Format format;  
> gl::Texture2dRef texDepthSpace = gl::Texture2d::create( &dsPoints[0], GL\_RG, kColorWidth, kColorHeight, format.dataType( GL\_FLOAT ) );

Where dsPoints is a vector of { float X, float Y }. In my shader, the values seem to be clamped at 1.0. How can I prevent clamping?

Thank you,  
Bala.

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [September 27, 2016, 1:42am UTC](https://discourse.libcinder.org/t/texture2d-from-data-without-clamping/285/2 "2016-09-27T01:42:30Z")

</div>

GL\_RG is an 8-bit per channel format. The values are treated as normalized “floats” where a value of 255 becomes 1.0 and 127 is roughly 0.5. If you want the values to be treated as unsigned chars, use GL\_RG8UI. For signed chars, use GL\_RG8I. For 32-bit floats, use GL\_RG32F, but be advised that using more than 32 bits in total (in this case 64 bits) may cause some performance degradation.

See also:  
[https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glTexImage2D.xml](https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glTexImage2D.xml)

---

<div class="post-metadata">

**Author:** ![balachandran\_c](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@balachandran\_c](https://discourse.libcinder.org/u/balachandran_c)\
**Post date:** [September 27, 2016, 4:42am UTC](https://discourse.libcinder.org/t/texture2d-from-data-without-clamping/285/3 "2016-09-27T04:42:23Z")

</div>

I had tried using GL\_RG32F where I have used GL\_RG. But, then the texture value that I read becomes zero. In my fragment shader:

> uniform sampler2D uDsMap;  
> in vec2 TexCoord;  
> void main( void )  
> {  
> vec2 dsc = texture( uDsMap, vec2( TexCoord.x, 1.0 - TexCoord.y ) ).rg;  
> if( dsc.r == 0.0 )  
> oColor = vec4( 1.0, 0.0, 0.0, 1.0 );  
> }

I get a fully red image. But if I use GL\_RG, I can get the values. Looking at glTexImage2D:

> <https://github.com/cinder/Cinder/blob/master/src/cinder/gl/Texture.cpp#L1194>

It uses “mInternalFormat” ( GL\_RGBA ) where GL\_RG32F should go (according to my understanding of the api docs). And GL\_RG32F is not one of the acceptable symbolic values for dataFormat. I assume I am overlooking something simple.

Thank you for your time!

---

<div class="post-metadata">

**Author:** ![balachandran\_c](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@balachandran\_c](https://discourse.libcinder.org/u/balachandran_c)\
**Post date:** [September 27, 2016, 4:54am UTC](https://discourse.libcinder.org/t/texture2d-from-data-without-clamping/285/4 "2016-09-27T04:54:18Z")

</div>

Oops. Got it working. I needed to use the set the `internalFormat` of the texture to make it work.

> gl::Texture2d::Format format;  
> format.setInternalFormat( GL\_RG32F );  
> gl::Texture2dRef texDepthSpace = gl::Texture2d::create( &dsPoints[0], GL\_RG, kColorWidth, kColorHeight, format.dataType( GL\_FLOAT ) );

Thanks!
