Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Masking to show player color....problem please help

  1. #1
    Intern Newbie
    Join Date
    Jul 2006
    Posts
    39

    Masking to show player color....problem please help

    OpenGL,Ortho,2D game:

    Ok i have these units in my 2d game i want to display using various player colors.However the unit image is just 1 image.The pixels where player color should appear are known/marked out by a specific color.The unit image is displayed as a textured quad. I want to use only the unit image & say some mask to display any player color in the unit image.

    So i thought the mask could be white only where player color should be present(black otherwise) & of same dimension as the unit image.

    Now if i multiply a texture of dimensions=unit image but color=player color with mask, i will get a black image with the player color present in the exact positions i want them in the unit image. Now how to superimpose this image on the unit image to get the player colors there as well?.

    Anyone has a better idea on how to do this whole thing? i want masks of 1 bit depth only.How to store such masks in video memory so they occupy 1 bit depth only...textures have to be 8bpp at least i think

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: Masking to show player color....problem please help

    Yes, GPU is free to choose internal format of texture so even if you create 1-bit texture it will most likely be stored as 8-bit.

    As for combining player image with masked player color I have two suggestions for you:

    1.
    Put mask to alpha-only texture - when rendering use alpha blending or alpha test (or both):
    Code :
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glAlphaFunc(GL_GREATER, 0.01f);
    glEnable(GL_BLEND);
    glEnable(GL_ALPHA_TEST);
    2.
    Put mask to luminance only texture (this is what you currently do), and use the following blend function:
    Code :
    glBlendFunc(GL_ONE, GL_ONE);
    glEnable(GL_BLEND);
    Additionally, texture with player image should have black pixels where mask is white (it should be pre-multiplied by inverse of mask).

    First solution will be faster if your players occupy lots of pixels on the screen since it skips invisible pixels using alpha test.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •