Narek
Narek

Reputation: 39901

Texel data in case of GL_LUMINANCE when glTexImage2D is called

Usually a texel is an RGBA value. What data does a texel represent in the following code:

const int TEXELS_W = 2, TEXELS_H = 2;
GLubyte texels[] = {
    100, 200,  0,  0,
    200,  250,  0,  0
};
glBindTexture(GL_TEXTURE_2D, textureId);
glTexImage2D(
    GL_TEXTURE_2D,
    0,                  // mipmap reduction level
    GL_LUMINANCE,
    TEXELS_W,
    TEXELS_H,
    0,                  // border (must be 0)
    GL_LUMINANCE,
    GL_UNSIGNED_BYTE,
    texels);

Upvotes: 1

Views: 211

Answers (2)

Nicol Bolas
Nicol Bolas

Reputation: 474436

GLubyte texels[] = {
    100, 200,  0,  0,
    200,  250,  0,  0
};

OpenGL will only read 4 of these values. Because GL_UNPACK_ALIGNMENT defaults to 4, OpenGL expects each row of pixel data to be aligned to 4 bytes. So the two 0's in each row are just padding, because the person who wrote this code didn't know how to change the alignment.

So OpenGL will read 100, 200 as the first row, then skip to the next 4 byte boundary and read 200, 250 as the second row.

Upvotes: 4

genpfault
genpfault

Reputation: 52166

GL_LUMINANCE:

Each element is a single luminance value. The GL converts it to floating point, then assembles it into an RGBA element by replicating the luminance value three times for red, green, and blue and attaching 1 for alpha. Each component is then multiplied by the signed scale factor GL_c_SCALE, added to the signed bias GL_c_BIAS, and clamped to the range [0,1] (see glPixelTransfer).

Upvotes: 1

Related Questions