Blending sprites
Posted: Tue Aug 17, 2010 12:29 am
Hello,
I'm learning about libnds, and now I'm facing sprite blending. I could get the sprites to blend all at once, but I need to enable/disable the effect on each one. I don't know if this is possible, or maybe I missed it in the provided examples. Anyway, I'm finding this blending topic a little difficult, so I wanted to ask if the way I'm approaching it is correct:
1) Activate alpha blending. For that I use the following code, since I didn't found any function to do that tasks (the offset 0x1000 just for the subengine). The register information comes from http://nocash.emubase.de/gbatek.htm
2) Well, I couldn't get anywhere else. The documentation states that in bitmap sprites the palette index of oamSet is used as alpha factor, but I coudln't get any change in that way (just using the up global value worked). Then I checked the oamSet function in sprite.c and found the following code:
I've tried changing myself the blendMode option directly for different kinds of tiles (bitmap and 8bit palette), but nothing worked. Has anyone a solution for this or knows if it is possible to achieve?
I'm learning about libnds, and now I'm facing sprite blending. I could get the sprites to blend all at once, but I need to enable/disable the effect on each one. I don't know if this is possible, or maybe I missed it in the provided examples. Anyway, I'm finding this blending topic a little difficult, so I wanted to ask if the way I'm approaching it is correct:
1) Activate alpha blending. For that I use the following code, since I didn't found any function to do that tasks (the offset 0x1000 just for the subengine). The register information comes from http://nocash.emubase.de/gbatek.htm
Code: Select all
u16* mem_BLDCNT_SUB = (u16*)(0x04000050 + 0x1000);
*mem_BLDCNT_SUB = BIT(4) | BIT(6) | BIT(11); // Alpha blend objects with bg_layer 3
u16* mem_BLDALPHA_SUB = (u16*)(0x04000052 + 0x1000);
*mem_BLDALPHA_SUB = (8) | (16<<8); // Change the factors as needed
Code: Select all
// format is of type SpriteColorFormat
if(format != SpriteColorFormat_Bmp) {
oam->oamMemory[id].colorMode = format;
} else {
oam->oamMemory[id].blendMode = format;
}