PDA

View Full Version : How to use single channel alpha texture?



hyppoo
07-19-2017, 06:31 AM
I have create a single channel alpha image:


mask1 = new unsigned char[720* 480];

for(unsigned int i = 0; i < 480; i++) {
for(unsigned int j = 0; j < 720; j++) {
mask1[i * 480 + j] = alpha;
}
}

and load it using:


glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 720, 480, 0, GL_ALPHA,
GL_UNSIGNED_BYTE, mask1);

or


glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 720, 480, 0, GL_RED,
GL_UNSIGNED_BYTE, mask1);

in glsl:

vec4 color.r = texture(alpha_mask, v_texCoord).a;

v_texCoord is the four corner (0,0 -> 1,1), but the output image is much smaller;.

Silence
07-20-2017, 12:51 AM
If you want your texture to match the size of the image, you have to make the geometry matches the image size. For example, drawing a rectangle of 720*480 pixels on the screen. This requires to use an orthographic projection matching the size of your window (and viewport).

For more information go on a tutorial (https://learnopengl.com/) or on any other tutorial about texturing.