You are not logged in.

#1 2010-08-02 22:22:24

marc_max
Member

Masking an image?

Hi,
as my english is not my main language and I don't think I will be able to explain it correctly, I'll post an image that I hope is self-explanatory smile

http://a.imageshack.us/img594/1092/maskz.jpg

This is what I want. Basically, I want to draw only some parts of an image, based on another mask image. How can I do this with GRRLIB? I have been searching through documentation and boards, but I did not find anything related to this.

Offline

 

#2 2010-08-03 01:24:19

Crayon
Bad Mother Fucker

Re: Masking an image?

Right now there is no way to do that in GRRLIB. But you can make a function to do that very easily with GRRLIB_GetPixelFromtexImg. I don't know any better way to do it.

If you need help, just ask...

Offline

 

#3 2010-08-03 10:45:31

NoNameNo
Administrator

Re: Masking an image?

in fact crayon is right grrlib can't do logic between texture for now, but you can easily get this effect using :

GX_SetBlendMode

http://www.devkitpro.org/libogc/gx_8h.h … ea182c8eb6

have a look at the last param (logical operation)
i already coded something similar using this.

regards,

crayon : perhaps we can provide preparametered logic fonction via an update of GRRLIB_SetBlend  and a new function
GRRLIB_TexLogic(GRRLIB_texImg src1, GRRLIB_texImg src2, operation, GRRLIB_texImg dst);

NNN

Offline

 

#4 2010-08-03 12:25:25

marc_max
Member

Re: Masking an image?

Thanks for your answers smile
I already saw GetPixelFromtex and SetPixelTotex but I thought it was going to be a very inefficient code. But at least it's a solution for now smile

This is the code:

Code:

void Graficos_MascaraImagen(){
    int x,y;
    for(x=0;x<192;x++){
        for(y=0;y<112;y++){
            u32 masc=GRRLIB_GetPixelFromtexImg(x, y, GFX_Mask);
            if(masc==RGBA(0,0,0,255)){
                GRRLIB_SetPixelTotexImg(x, y, GFX_Tetris, RGBA(0,0,0,0));
            }
        }
    }
}

This is only a test, but it works. Now I'm going to make it universal for any texture and any size.
Any suggestion to make it cleaner?

@NoNameNo, can you explain more detailed the SetBlendMode method? Some code would be very helpful smile

Offline

 

#5 2010-08-03 12:57:06

NoNameNo
Administrator

Re: Masking an image?

in fact if you dont need "real" time effect, GetPixelFromtex and SetPixelTotex fit well since you can pre calculate your need at start of you app, then use all your precalculated stuff.

if you really need real time effect on big textures, you surely need a little GX help using GX_SetBlendMode with logical operation.

in fact simply  draw your original (or mask order can be important acording to the operation you selected)*

then use :
GX_SetBlendMode(GX_BM_LOGIC, GX_BL_ZERO, GX_BL_ZERO, and use the operation you want here )
list of operation : http://www.devkitpro.org/libogc/group__logicop.html

now draw your mask (or original order can be important acording to the operation you selected)*
use screen2texture to catch the result in a new texture.
then reset the blending mode to grrlib default using :
GRRLIB_SetBlend(GRRLIB_BLEND_ALPHA);

and voila...

wink

Offline

 

#6 2010-08-03 15:11:19

marc_max
Member

Re: Masking an image?

Thank you smile
I'll stay with the first method, because I even calculate it before starting up GRRLIB. I still don't like it (maybe I'm too perfectionist) but the other method looks even more dirty to me.

Time for another question... On another topic!

Offline

 

#7 2010-08-04 00:22:37

NoNameNo
Administrator

Re: Masking an image?

for info i coded my best candy eyes demo effect tonight making some research about what i said about blending mode and mask wink stay tunned to see it soon wink

thx marc_max wink

Offline

 

Board footer

Powered by FluxBB