PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Transparency questions

1. Does PF support blitting with alpha-mask surface? I.e. One surface is to blit and another is to define the transparency for each local pixel from first surface? For example, I want to show upper half from attached image blended according to lower half:
Attachments:
B1_size24.png
2. I feel I'm doing something wrong setting color key for a surface. I have a surface with 0хff00ff color to be set as transparent, and when I set it via

s->SetColorMask(Color( 255, 0, 255));

and blit to another surface I have black color instead of transparency:
Attachments:
test.jpg
Also, I have useful function in my GapiDraw projects which sets transparent color automatically, like the following code for PF. But this doesn't work. I guess I need to convert color data somehow, could smbdy tell me how?

void pickTransparent(Surface* s, int x, int y) {
Rasterizer r(s);
Pixel p = r.GetPixel(x, y);
s->SetColorMask(p);
}

Thank you.
1. search the forum re: 1 (not built in but I think someone posted for this) re: 2, are you sure the graphic background pixels are ff00ff? (are they JPG etc) and 3. I don't understand.
3 is simple:
- as I know, for example, the pixel in xy=(0, 0) is considered to be transparent, I get the color of this pixel and set is as color mask.
2:
here is the image. taken from font examle.
Attachments:
menufont.gif
how are u printing the font to screen?

the fact that you are getting a black background suggests that the transparency is working properly (i.e there is no magenta)

are you assembling the printed string on another surface before blitting to the final screen? if so, you need to make sure you set the transparency colour of that surface before blitting to the final screen (i.e set it's transparency colour to 0x0)
muff wrote:how are u printing the font to screen?

the fact that you are getting a black background suggests that the transparency is working properly (i.e there is no magenta)

are you assembling the printed string on another surface before blitting to the final screen? if so, you need to make sure you set the transparency colour of that surface before blitting to the final screen (i.e set it's transparency colour to 0x0)


I am blitting to the display's backbuffer, so all should be OK with it.
Finally I solved the problem (I think). In font example there were GetDC()/ReleaseDC() functions called to make access for GDI operations with surface. After call to ReleaseDC(), the transparent color of the surface somehow stopped to be transparent/masked.. When I picked the color again and set it as a mask, I got the correct result.
Thank you anyway.

Maybe somebody can show me an example describing the issue I wrote in topic starter post (masked alpha blending)?
If you're using Gersen's font code, you'll need to make sure it uses FF00FF as the transparent color. If I remember correctly, it defaults to using black. Just search for SetColorMask in font.cpp.

-John
Presto,
I'm using code by Jason Chong as a base. Mask can be of any color.
3 would be something like:

display->SetRenderTarget(surface);
colormask = display->Getpixel(0,0);
display->SetRenderTarget(NULL);
surface->SetColorMask(colormask);

1 is mentioned a lot here, and implemented by fast_rx, and IIRC included into bigben patch http://www.pocketmatrix.com/forums/view ... hp?t=21765.
Hi no pockets.

As for transparency - I use one function to load sprites - it sets the Color(255,0,255) by default, it is a good practice to have all images with the same color for transparency.

In my game I use the same bitmapped font principle as you do, so everything should be OK with it. As for proper PocketFrog implementation, please search for gersen's font class example.

To blit the images with partial transparency patch your PocketFrog with the latest bugfix, load two surfaces (one is your surface another is your masking grayscale surface). And use the following function:

Code:

pDisplay->Blit(X, Y, S_surface, S_surface_mask, &Rect;( sX1, sY1, sX2, sY2) );


Hope it helps ;)
BIGBEN wrote:Hi no pockets.

To blit the images with partial transparency patch your PocketFrog with the latest bugfix, load two surfaces (one is your surface another is your masking grayscale surface). And use the following function:

Hope it helps ;)


Thanks, already found it. Works fine :)

One thing there - a kind of flexibility lack - I can pass only one srcRect (used for both image surface and for alpha surface). Therefore I can't put image pixels and alpha pixels in single surface. Not a big problem at all, mentioning it just for having a bunch of images prepared like one in the first post of this topic.