Thanks for the replies! I didn't know that the registers where available in the documentation, so thanks to point this out! It would be nice if them could be also added to the documentation in the future. And also I didn't realize about the variables should be declared volatile.
I've tried with the example that zeromus suggested, and I modified it a little for testing the blending capabilites in the following ways:
1) now the 3 sprites are of bitmap type
2) I simplified it a little to avoid unnecessay code for the test (so no orientation, for instance). Here is the code:
Code: Select all
#include <cstdio>
#include <nds.h>
//a simple sprite structure
//it is generally preferred to separate your game object
//from OAM
typedef struct
{
u16* gfx;
SpriteSize size;
SpriteColorFormat format;
int rotationIndex;
int paletteAlpha;
int x;
int y;
}MySprite;
int main(int argc, char** argv) {
//three bitmap sprites
MySprite sprites[] = {
{0, SpriteSize_32x32, SpriteColorFormat_Bmp, -1, 0, 20, 5},
{0, SpriteSize_32x32, SpriteColorFormat_Bmp, -1, 8, 20, 70},
{0, SpriteSize_32x32, SpriteColorFormat_Bmp, -1, 15, 20, 126}
};
videoSetModeSub(MODE_0_2D);
consoleDemoInit();
REG_BLDALPHA_SUB = (8) | (8<<8); // Change the factors as needed
REG_BLDCNT_SUB = BLEND_ALPHA |
BLEND_SRC_SPRITE |
BLEND_DST_BG0 |BLEND_DST_BG1 | BLEND_DST_BG2 | BLEND_DST_BG3 | BLEND_DST_SPRITE | BLEND_DST_BACKDROP;
//initialize the sub sprite engine with 1D mapping 128 byte boundary
//and no external palette support
oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false);
vramSetBankD(VRAM_D_SUB_SPRITE);
//allocate some space for the sprite graphics
for(int i = 0; i < 3; i++)
sprites[i].gfx = oamAllocateGfx(&oamSub, sprites[i].size, sprites[i].format);
//ugly positional printf
printf("\x1b[1;1HDirect Bitmap: RED");
printf("\x1b[9;1HDirect Bitmap: GREEN");
printf("\x1b[16;1HDirect Bitmap: BLUE");
//fill bmp sprite with the color red
dmaFillHalfWords(ARGB16(1,31,0,0), sprites[0].gfx, 32*32*2);
//fill the 256 color sprite with index 1 (2 pixels at a time)
dmaFillHalfWords(ARGB16(1,0,31,0), sprites[1].gfx, 32*32*2);
//fill the 16 color sprite with index 1 (4 pixels at a time)
dmaFillHalfWords(ARGB16(1,0,0,31), sprites[2].gfx, 32*32*2);
while(1)
{
for(int i = 0; i < 3; i++)
{
oamSet(
&oamSub, //sub display
i, //oam entry to set
sprites[i].x, sprites[i].y, //position
0, //priority
sprites[i].paletteAlpha, //alpha (since we just have bmp sprites)
sprites[i].size,
sprites[i].format,
sprites[i].gfx,
-1, // no rotation
true, //double the size of rotated sprites
false, //don't hide the sprite
false, false, //vflip, hflip
false //apply mosaic
);
//oamSub.oamMemory[i].colorMode = (ObjColMode)1;
//oamSub.oamMemory[i].blendMode = (ObjBlendMode)3;
}
swiWaitForVBlank();
//send the updates to the hardware
oamUpdate(&oamSub);
}
return 0;
}
However, if you try it (I'm trying on No$GBA) you'll see all the sprites share the same alpha blending level, even I assigned to them different values in the array construction (0,8 and 15). Commenting the REG_BLDALPHA_SUB line just makes the sprites completely black, but I think this is just the case where the blending coeficients are both 0.
So the problem is that I still can't get a different alpha level for each sprite. (I also played directly modifying colorMode and blendMode, but nothing). Could you tell me how to do that?