Load single color channel to OpenGL texture

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
lechoo

Load single color channel to OpenGL texture

Post 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?
Post Reply