Results 1 to 8 of 8

Thread: Masking

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Gouda -> Netherlands
    Posts
    24

    Masking

    Hey there..

    I've searched on this subject here and didnt find anything really usefull, so here's a new post on it

    I currently use a second jpg texture to load an alpha channel and want to use another approach.

    Loading TGA textures will just increase my texture size, so thats not what i want eigther.

    I was thinking about checking each rgb value of my jpg and assigning an alpha value of 0 to it when it is pink for example, while loading the texture in my code.

    Could anyone help me on my way?

    I think i should:

    put alpha testing on;
    for loop thru texture.data;
    create alpha channel (how??);
    store new texture data;

    thx in advance

    cya

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Masking

    Hello.
    I just wanted to say that using TGA's is not so bad at all.
    You know, when you have loaded the imagefile into memory it takes the same space in every format.

    [Or were you hinting at that the alpha-channel is to big? Then of course you are right. TGA are nice though ]

    Ummm sorry that I could not really help you.

    EDIT:
    Now I noticed that you want to create an alpha channel during runtime. Hey, I would really go for a TGA. Because it's easy.
    If you are worried about the space your textures take on your harddrive you could use something like zlib to store it.

    Hope that helps

    [This message has been edited by B_old (edited 11-11-2002).]
    I may not be good looking but I sure am dumb.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Gouda -> Netherlands
    Posts
    24

    Re: Masking

    ofcourse, in raw format its almost the same, but im talking about discspace/dowload space

    thx anyway

  4. #4
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Masking

    Like I said. Compress it.

    EDIT:
    You even end up with better quality

    [This message has been edited by B_old (edited 11-11-2002).]
    I may not be good looking but I sure am dumb.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Gouda -> Netherlands
    Posts
    24

    Re: Masking

    ok thx for your reply, but i said in my post i didnt want to use TGA, so please dont try to work around my problem.

    I want to mask a certain color period .

    I know its certainly possible.

    I might want to try TGA anyway, but i still want to know how to create an alpha channel from withing OpenGL

    -xill

  6. #6
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Posts
    164

    Re: Masking

    Very well then. I just wanted to help you.
    I guess you did not know, but I use TGA myself.
    Well, OK. I will shut my mouth know and don't trouble you any further.
    Sorry that I could not help you with your actual problem.
    I may not be good looking but I sure am dumb.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Masking

    Basic pseudo-code for what you want is fairly easy.

    Code :
    unsigned char* pNewData;
     
    pImg = LoadJPEG("image.jpg");
     
    pNewData = new unsigned char[pImg->w*pImg->h*4);
     
    for (int y=0;y<pImg->h;y++)
    {
        for (int x=0;x<pImg->w;x++)
        {
           int iIndex = y*pImg->w+x;
     
           pNewData[iIndex*4] = pImg->data[iIndex*3];
           pNewData[iIndex*4 + 1] = pImg->data[iIndex*3 + 1];
           pNewData[iIndex*4 + 2] = pImg->data[iIndex*3 + 2];
     
           if (pImg->data[iIndex*3] == 0 &amp;&amp;
               pImg->data[iIndex+3+1] == 0 &amp;&amp;
               pImg->data[iIndex+3+2] == 0)
           {
                desiredAlpha = 128;
           }
           else
           {
                desiredAlpha = 255;
           }
     
           pNewData[iIndex*4 + 3] = desiredAlpha;  
        }
    }
    The above code will basically find any pixel that is black, and give it an alpha of 128, and give every other pixel a value of 255.

    You could modify the above to use any specific color you wanted, or you could modify it to use a range of colors, or pretty much anything you wanted.

    Edit: My pseudo code was assigning float values to unsigned chars. Not good.

    [This message has been edited by Deiussum (edited 11-11-2002).]
    Deiussum
    Software Engineer and OpenGL enthusiast

  8. #8
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Gouda -> Netherlands
    Posts
    24

    Re: Masking

    ok thx mate you rule.

Similar Threads

  1. masking
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-11-2006, 03:58 AM
  2. Masking + Fog.....
    By PhotonMan in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-05-2004, 08:55 AM
  3. Masking + Fog
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-30-2004, 10:06 AM
  4. Masking?
    By imported_zedus in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-07-2002, 11:10 AM
  5. Masking
    By Crunch in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-09-2000, 05:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean