Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Change <code>GL_RGBA8</code> (which makes a grayscale image with <strong>no alpha channel</strong>) to <code>GL_INTENSITY</code>:</p> <pre><code>glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, 16, 16, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer); </code></pre> <p>The <code>GL_RGBA8</code> format, created from <code>GL_LUMINANCE</code>, gives pixels of the form <code>(Y, Y, Y, 1)</code>, but <code>GL_INTENSITY</code> with <code>GL_LUMINANCE</code> gives <code>(Y, Y, Y, Y)</code>.</p> <p>You will also want to change your blend mode to assume premultiplied alpha, e.g. change</p> <pre><code>glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); </code></pre> <p>to:</p> <pre><code>glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); </code></pre> <p><strong>Alternative:</strong></p> <p>You can also use <code>GL_ALPHA</code>, and then use your ordinary blending mode for non-premultiplied alpha:</p> <pre><code>glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 16, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer); </code></pre> <p><strong>Alternative #2:</strong></p> <p>You can keep using <code>GL_LUMINANCE</code>, and change the blending mode.</p> <pre><code>glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); </code></pre> <p>This has the drawback that you can't color the texture without using something like <code>glBlendColor</code> (which is not part of the OpenGL headers that ship with MSVC, so you have to use GLEW or something like that):</p> <pre><code>glBlendColor(...); glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); </code></pre> <p><strong>Alternative #3:</strong></p> <p>Use OpenGL 3, and change your fragment shader to handle single-channel textures in the desired way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload