Accumulator
Accumulator

Reputation: 903

Draw Completely White Texture in OpenGL

What I want to do is draw a texture like normal in OpenGL, but completely white. I tried doing glColor3f(2.f, 2.f, 2.f) but that doesn't work. I just want to draw the shape of a certain texture but without color and just white, so I'm trying to draw a texture but white...

To clarify the desired result: I want the RGB part of all colors sampled from the texture to be white, while the alpha value is the one sampled from the texture. So if the value in the texture is (R, G, B, A), I want the sampled color to be (1.0f, 1.0f, 1.0f, A).

Upvotes: 2

Views: 2783

Answers (3)

Reto Koradi
Reto Koradi

Reputation: 54592

To turn the color from the texture white, but still use the alpha value sampled from the texture, you can use:

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

With the GL_ADD texture env mode, the incoming fragment color (which the second call above sets to white) will be added to the color sampled from the texture to obtain the output color. Since output colors are clamped to the range [0.0, 1.0], the color components from the texture do not matter, since they will be added to 1.0 before the result is clamped to 1.0. So the RGB color part of the output will always be white.

The less obvious part is what happens to the alpha value. According to the spec, the alpha value from the incoming fragment and the alpha value sampled from the texture are multiplied for the GL_ADD texture env mode. With the fragment alpha set to 1.0, this means that the resulting value is the alpha value from the texture, which is what you wanted.

Upvotes: 2

Nico Cvitak
Nico Cvitak

Reputation: 471

Create a 1x1 white RGBA bitmap in code.

GLubyte texData[] = { 255, 255, 255, 255 };

Copy data to texture.

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);

Upvotes: 0

Blindy
Blindy

Reputation: 67382

Use a pixel shader and set each fragment's color to white.

Upvotes: 2

Related Questions