# Extract/set Channel \<--\> Texture; quickly fades out

**URL:** <https://discourse.libcinder.org/t/extract-set-channel-texture-quickly-fades-out/1725>\
**Category:** Using Cinder\
**Created:** [October 2, 2020, 9:07am UTC](https://discourse.libcinder.org/t/extract-set-channel-texture-quickly-fades-out/1725 "2020-10-02T09:07:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![totalgee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/totalgee/32/274_2.png) [@totalgee](https://discourse.libcinder.org/u/totalgee)\
**Post date:** [October 2, 2020, 9:07am UTC](https://discourse.libcinder.org/t/extract-set-channel-texture-quickly-fades-out/1725/1 "2020-10-02T09:07:57Z")

</div>

Hi there, I’m trying to repeatedly modify a texture, however it seems to quickly “fade out”. I expect this is maybe to do with gamma correction, or something about the format/linearity of the Channel data being different from the Texture format…? But it’s a pretty basic example – how can I get the following simple example to extract a Channel and set it back into a Texture while keeping the data intact?

```auto
    ci::Channel chan(256, 256);

    // Initialize it so that it has a vertical gradient, from white to black (top-bottom)
    auto iter = chan.getIter();
    uint8_t v = 255;
    while (iter.line()) {
        while (iter.pixel()) {
            iter.v() = v;
        }
        --v;
    }

    mTex = gl::Texture2d::create(chan);
    // If you draw mTex here, it will look correct (white at top. black at bottom)

    // Extract the data as a Channel, then immediately set it back (unchanged)
    ci::Channel extractChan(mTex->createSource());
    mTex->update(extractChan);
    // If you draw mTex here, it will be very dark (likely a gamma-conversion issue?)

```

I’m sure I’m missing something basic…but don’t see it from reading through the docs/API.

Thanks,  
Glen.

---

<div class="post-metadata">

**Author:** ![totalgee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/totalgee/32/274_2.png) [@totalgee](https://discourse.libcinder.org/u/totalgee)\
**Post date:** [October 2, 2020, 12:03pm UTC](https://discourse.libcinder.org/t/extract-set-channel-texture-quickly-fades-out/1725/2 "2020-10-02T12:03:18Z")

</div>

I think the problem seems to be that the constructor `ImageSourceTexture()` doesn’t recognize a single-channel 8-bit source as special, so it uses the default case with CM\_RGB color model and GL\_RGBA format.

After much investigation, I just tested using Channel32f instead of Channel (aka Channel8u), and Texture `internalFormat` of `GL_R32F` with `dataType` of `GL_FLOAT`) and that seems to work. But the 8-bit case greyscale seems like a “common” (or at least useful) case that should work, no?

Anyhow, at least now I’ve got a workaround…

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [October 16, 2020, 8:14pm UTC](https://discourse.libcinder.org/t/extract-set-channel-texture-quickly-fades-out/1725/3 "2020-10-16T20:14:44Z")

</div>

Any specific reason you’re not using the good ol ping pong method? ImageSourceTexture::createSource() is extremely expensive, ive only ever used it to debug and save a texture to file.

Cheers,  
Rich

---

<div class="post-metadata">

**Author:** ![totalgee](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/totalgee/32/274_2.png) [@totalgee](https://discourse.libcinder.org/u/totalgee)\
**Post date:** [October 16, 2020, 9:38pm UTC](https://discourse.libcinder.org/t/extract-set-channel-texture-quickly-fades-out/1725/4 "2020-10-16T21:38:26Z")

</div>

Thanks for the reply. I’m just creating the texture once, then I want to update it. So my issue is not with performance, but with the way the 8-bit data is interpreted incorrectly (as RGB colour) for single-channel textures.

Or maybe I misunderstand what you’re proposing with your ping pong comment (I do know about that technique for double buffering). My data is not colour info, It’s numerical data produced by my program (actually audio data) that I want to use on the GPU as a texture (with interpolation, etc).

Thanks, maybe I misread your suggestion, please let me know. In any case, it works as I want with the 32f version, so I’m happy – I just thought it seemed like a bug with single component 8-bit textures, but maybe not.

G.
