Page 1 of 1

Load single color channel to OpenGL texture

Posted: 2010-06-22T05:10:40-07:00
by lechoo
To load all channels I'm doing this:

Code: Select all

im.read(filename);
im.write(&blob, "RGB", 8);
glTexImage2D(GL_TEXTURE_2D, 0, 3, im.columns(), im.rows(), 0, GL_RGB, GL_UNSIGNED_BYTE, blob.data());
Loading single channel should look like this:

Code: Select all

im.read(filename);
im.write(&blob, "R", 8);
glTexImage2D(GL_TEXTURE_2D, 0, 1, im.columns(), im.rows(), 0, GL_RED, GL_UNSIGNED_BYTE, blob.data());
Bu it works only for red channel, if I try same with green or blue channel I'm getting black image.

Code: Select all

im.read(filename);
im.write(&blob, "G", 8);
glTexImage2D(GL_TEXTURE_2D, 0, 1, im.columns(), im.rows(), 0, GL_GREEN, GL_UNSIGNED_BYTE, blob.data());
Is this the right way to do it?