0

I use the Cinder Library and want to create a texture, filled with RGBA values which I saved in an array. There is no helpfull explanation on the internet.

  • Have a look at the surface basic sample: https://github.com/cinder/Cinder/blob/master/samples/SurfaceBasic/src/SurfaceBasicApp.cpp – num3ric Feb 12 '15 at 04:34

1 Answers1

0

I've not used cinder before but a quick perusal of the documentation seems to suggest you can load a texture either form a file or from a Surface.

So looking at the docs it would seem you create a surface as follows:

cinder::Surface8u surf( 128, 128, SurfaceChannelOrder::RGBA );

You can then fill it using the getData function as follows:

uint8_t* pCols = surf.getData();
for( int y = 0; y < 128; y++ )
{
    for( int x = 0; x < 128; x++ )
    {
        // Fill each pixel with red.
        const idx = (y * (128 * 4)) + (x * 4);
        pCols[idx + 0] = 0xff;
        pCols[idx + 1] = 0x00;
        pCols[idx + 2] = 0x00;
        pCols[idx + 3] = 0xff;
    }
}

You would then load the texture from the surface as follows:

cinder::gl::Texture texture( surf );
Goz
  • 61,365
  • 24
  • 124
  • 204