I've been having problems when working with transparency when doing image processing...
The game consists of two boards (one for now). A board is a grid of 6x12 pieces, but 8x14 for padding. The pieces are connected when neighboring like pieces. The drawing process is done for each piece, on a temporary bitmap. Then it is mask_blitted onto the video. All BMP versions of the images are in 256 colors, I am also running the game in 32bit color.
1. Here is my game, no image processing: http://zyklus.acaro.org/host/puyo/debug00.jpg (boring)
2. This is the image map, and its mask: http://zyklus.acaro.org/host/puyo/debug05.jpg
The mask is green for a reason, it will be inverted later.
3. This is the board, showing neighbors: http://zyklus.acaro.org/host/puyo/debug01.jpg
4. Result of multiplying 1 with 3: http://zyklus.acaro.org/host/puyo/debug02.jpg (better, but need to fix that black area to be transparent)
5. This is the mask I want to use: http://zyklus.acaro.org/host/puyo/debug03.jpg (why is the magenta yellow?)
6. Invert 5 and mask_blit onto 4:
http://zyklus.acaro.org/host/puyo/debug04.jpg
I get the mask that I want, but it destroys everything else X|
Any ideas?
EDIT: here is some code:
1 | |
2 | #define TILE_GET_CONNECTORS(x) (((x)&(15<<8))>>8) |
3 | |
4 | struct v2 { float x, y; }; |
5 | typedef unsigned int word; |
6 | typedef unsigned char byte; |
7 | |
8 | . |
9 | . |
10 | . |
11 | |
12 | void CBoard::DrawBlockProc( v2 &v, word tile ) |
13 | { |
14 | BITMAP *bmp = g_pGame->GetGfx()->GetRamPage(); |
15 | // RamPage is a temporary ram bitmap for post-image processing... blitted onto video later. |
16 | byte n = 0, color = tile & 0xFF; |
17 | |
18 | // Draw the base: |
19 | if ( color == 0 ) // Empty space here, nothing to do |
20 | return; |
21 | if ( (--color) >= m_iNumberOfTileImages ) // If color is 1, it indexes tile_bitmap 0 |
22 | rectfill( m_pBmpTemp, 0, 0, m_iBlocksz, m_iBlocksz, makecol( 64, 64, 64 ) ); |
23 | else |
24 | { |
25 | n = TILE_GET_CONNECTORS(tile); |
26 | drawing_mode( DRAW_MODE_COPY_PATTERN, m_pBmpTileImgs[color], -v.x, -v.y ); |
27 | rectfill( m_pBmpTemp, 0, 0, m_iBlocksz, m_iBlocksz, -1 ); |
28 | drawing_mode( DRAW_MODE_SOLID, NULL, 0, 0 ); |
29 | } |
30 | |
31 | // Multiply imagemap: |
32 | set_multiply_blender( 0, 0, 0, 255 ); |
33 | draw_trans_sprite( m_pBmpTemp, m_pBmpTileMap[n], 0, 0 ); |
34 | |
35 | // Draw mask: |
36 | set_invert_blender( 0, 0, 0, 255 ); |
37 | draw_trans_sprite( m_pBmpTemp, m_pBmpTileMask[n], 0, 0 ); |
38 | |
39 | // Blit onto "video": |
40 | solid_mode(); |
41 | masked_blit( m_pBmpTemp, bmp, 0, 0, v.x, v.y, m_iBlocksz, m_iBlocksz ); |
42 | } |
I get the mask that I want, but it destroys everything else X|
Any ideas?
Try playing around with the last parameter of set_invert_blender(). 128 would be a good value to try.
I've already tried that, and here's how it looked:
http://zyklus.acaro.org/host/puyo/debug06.jpg
What I don't understand is why, when I try to draw a masked bitmap with draw_sprite, the magenta changes into yellow
Is there any way I can tell a specific bitmap to ignore or change it's transparency color?
EDIT:
Ah, nvm; problem solved. It was a discreet problem and a slight programming error.
Apparently, when the mask was loaded into the bitmap, it ignored pixels with the mask color; I expected it to load the whole thing XD. Well, just a simple rectfill( ... makecol( 255, 0, 255 ); fixed the problem.