Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: How to use single channel alpha texture?

  1. #1
    Junior Member Newbie
    Join Date
    May 2017
    Posts
    7

    How to use single channel alpha texture?

    I have create a single channel alpha image:

    Code :
    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:

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

    or

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

    in glsl:
    Code :
    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;.

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    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 or on any other tutorial about texturing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •