Skip to content

Instantly share code, notes, and snippets.

@nothings
Created March 23, 2018 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothings/f37d19dd99f0922dec53cf8499a4c3bd to your computer and use it in GitHub Desktop.
Save nothings/f37d19dd99f0922dec53cf8499a4c3bd to your computer and use it in GitHub Desktop.
// What I'm trying to do: store a 1-byte alpha texture:
GLenum swizzle[4] = { GL_ONE, GL_ONE, GL_ONE, GL_RED };
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width,height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
// above draws (1,1,1,1)
// works as expected: storing to red channel of an RGBA texture and using swizzle into the alpha
GLenum swizzle[4] = { GL_ONE, GL_ONE, GL_ONE, GL_RED };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width,height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
// ^^^^^^^^
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
// displays as (1,1,1,r) as expected
// works as expected: using GL_RED in R,G,B channels of R8
GLenum swizzle[4] = { GL_RED, GL_RED, GL_RED, GL_ONE };
// ^^^^^^ ^^^^^^ ^^^^^^ ^^^^^^
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width,height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
// draws as (r,r,r,1)
// doesn't work: setting alpha swizzle to 0 in R8
GLenum swizzle[4] = { GL_RED, GL_RED, GL_RED, GL_ZERO };
// ^^^^^^^
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width,height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
// draws same as previous, (r,r,r,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment