Jump to content
  • Advertisement
  • Remove ads and support GameDev.net for only $3. Learn more: The New GDNet+: No Ads!

  • 07/05/00 06:24 PM
    Sign in to follow this  

    8-Bit Indexed Color Translucency

    Graphics and GPU Programming

    Myopic Rhino
    This article is on how to use 256 indexed color translucency. It does not work on 16-bit or 32-bit color due to memory constraints. It involves building a 256 by 256 unsigned char table, which contains the result of every color combination. The table would be extremely large with 16-bit or 32-bit color. The first index for the table (which is in the form of a 2D array) is the translucency color. The second index for the table is the color behind the translucent pixel. This is a function that shows how to use this translucency technique. (The translucency actually should not be in a function or method, even an inline method.) DON'T ACTUALLY USE THIS FUNCTION! IF A FUNCTION CALL WAS USED TO DRAW EACH SINGLE PIXEL IN A SINGLE SOLIDCOLOR POLYGON, IT WOULD BE HORRENDOUSLY SLOW!


    [size="5"]Variables
    • x: the pixel's x coordinate
    • y: the pixel's y coordinate
    • c: the pixel's translucent color
    • b: the target graphic's base address
    • r: the target graphic's row bytes (includes padding, if there is any)
    • t: a pointer to the mixing table
      [size="5"]Implementation

      void Polygon3D::DrawTranslucentPixel(unsigned long x, unsigned long y,
      unsigned char c, unsigned char *b,
      unsigned long r, unsigned char *t)
      {
      *(unsigned char*)(b+x+y*r) = t[c][*(unsigned char*)(b+x+y*r)];
      }



      Report Article
    Sign in to follow this  


    User Feedback


    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!