View Full Version : What is texture swizzling?

01-18-2012, 11:09 AM

I need to understand what is texture swizzling and what can be achieved by this feature?
What should happen when we pass the token TEXTURE_SWIZZLE_R to TexParameteriv ?

It would be good if I could get some sample code for reference. I have already referred to http://www.opengl.org/registry/specs/ARB/texture_swizzle.txt. (http://www.opengl.org/registry/specs/ARB/texture_swizzle.txt)

Thanks in advance.

01-18-2012, 12:04 PM
This thing went into GL 3.3

Swizzling means remapping.
For example, you can swap the red and green component.
Or, you can swap the red and green component and have blue and alpha set to 1.

glBindTexture(target, id);
glTexParameteri(target, GL_TEXTURE_SWIZZLE_R, GL_GREEN);
glTexParameteri(target, GL_TEXTURE_SWIZZLE_G, GL_RED);
glTexParameteri(target, GL_TEXTURE_SWIZZLE_B, GL_ONE);
glTexParameteri(target, GL_TEXTURE_SWIZZLE_A, GL_ONE);

Also, read the part about "2) What is the demand for this extension?"

Alfonse Reinheart
01-18-2012, 12:49 PM
Did you check the wiki (http://www.opengl.org/wiki/Texture#Swizzle_mask)?

01-18-2012, 10:23 PM
That was great help.