OpenGL ES 1.1: How to change the color of a texture without losing brightness?

I have particles that I want to be able to change the color of the code, so any color can be used. Therefore, I have only one texture, which basically has brightness.

I used glColor4f(1f, 0f, 0f, 1f);to apply color.

Each blendfunc that I tried that came close to work ends, as in the last picture below. I still want to maintain brightness, as in the middle picture. (This is similar to the Overlay or Soft Light filters in Photoshop if the color layer was on top of the texture layer.)

Any ideas on how to do this without programmable shaders? In addition, since these are particles, I don’t want a black box behind him, I want him to add to the stage.

alt text

+5
2

, , :

glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

glActiveTexture( GL_TEXTURE0 );
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, spriteTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

glActiveTexture( GL_TEXTURE1 );
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, spriteTexture);    
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );

, , :

final_color.rgba = original_color.rgba * color.rgba + original_color.rgba;

, , , .

- , GL_COMBINE GL_ADD (+ GL_COMBINE_RGB GL_COMBINE_ALPHA).

, . alt text

+9

! -. .

, GL , GL_ADD.

iOS, Apple libs . . Texture2D kCGImageAlphaPremultipliedLast.

, , . :

uint8* LoadRGBAImage(const char* pImageFileName) {
    Image* pImage = LoadImageData(pImageFileName);
    if (pImage->eFormat != FORMAT_RGBA)
        return NULL;

    // allocate a buffer to store the pre-multiply result
    // NOTE that in a real scenario you'll want to pad pDstData to a power-of-2
    uint8* pDstData = (uint8*)malloc(pImage->rows * pImage->cols * 4);
    uint8* pSrcData = pImage->pBitmapBytes;
    uint32 bytesPerRow = pImage->cols * 4;

    for (uint32 y = 0; y < pImage->rows; ++y) {
        byte* pSrc = pSrcData + y * bytesPerRow;
        byte* pDst = pDstData + y * bytesPerRow;
        for (uint32 x = 0; x < pImage->cols; ++x) {
            // modulate src rgb channels with alpha channel
            // store result in dst rgb channels
            uint8 srcAlpha = pSrc[3];
            *pDst++ = Modulate(*pSrc++, srcAlpha);
            *pDst++ = Modulate(*pSrc++, srcAlpha);
            *pDst++ = Modulate(*pSrc++, srcAlpha);
            // copy src alpha channel directly to dst alpha channel
            *pDst++ = *pSrc++;
        }
    }

    // don't forget to free() the pointer!
    return pDstData;
}

uint8 Modulate(uint8 u, uint8 uControl) {
    // fixed-point multiply the value u with uControl and return the result
    return ((uint16)u * ((uint16)uControl + 1)) >> 8;
}

libpng .

, , , RGBA OpenGL. glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); , . ( ) , . , glBlendFunc (GL_SRC_ALPHA, GL_ONE); , .

Ozirus. "" RGB , , RGB / .

, premultiply Overlay, Ozirus - .

.

http://en.wikipedia.org/wiki/Alpha_compositing

" "

+2

All Articles