Page 1 of 1

transparency not working?

Posted: Mon Sep 14, 2009 9:20 pm
by vuurrobin
hello,

I'm trying to display an image converted with grit on a background. everything works, exept instead of displaying transparency (or better said, not displaying magenta) it displays magenta (although it does seem darker than usual). I'm doing everything like before, exept I'm also creating a map with it.

these are the grit options:

Code: Select all

#-------------------------------------------------------
# Set the warning/log level to 3
#-------------------------------------------------------
-W3


#-------------------------------------------------------
# Set the bit depth to 4
#-------------------------------------------------------
-gB4


#-------------------------------------------------------
# graphics in tile format
#-------------------------------------------------------
-gt


#include map
-m


#-------------------------------------------------------
# tile reduction by tiles, palette and hflip/vflip
#-------------------------------------------------------
-mRtpf


#-------------------------------------------------------
# Tell grit to include a palette (the first index in it will be transparent)
#-------------------------------------------------------
-p


#-------------------------------------------------------
# Set the transparent color to (rrggbb hex)
#-------------------------------------------------------
-gTFF00FF
this is the code I use to display it:

Code: Select all

//debug mode (sassert) will be turned off when defined
//#define NDEBUG

#include <DSOL.hpp>


//generated with grit
#include "vuurrobin.h"
const uint      vuurrobinBGLayer    = 0;
const BgType    vuurrobinBGType     = BgType_Text4bpp;
const BgSize    vuurrobinBGSize     = BgSize_T_256x256;


int main()
{
	DSOL::init2d();


    int bg = bgInit(vuurrobinBGLayer, vuurrobinBGType, vuurrobinBGSize, 0, 1);

	dmaCopy(vuurrobinMap, bgGetMapPtr(bg), vuurrobinMapLen);
	dmaCopy(vuurrobinTiles, bgGetGfxPtr(bg), vuurrobinTilesLen);
	dmaCopy(vuurrobinPal, BG_PALETTE, vuurrobinPalLen);


    //update everything and loop forever
    DSOL::sleepForever();

	return 0;
}
and this is the image:
http://vuurrobin.100webcustomers.com/st ... rrobin.png

does anybody see what I'm doing wrong here, some grit option I forgot or the image not saved right or something.

Re: transparency not working?

Posted: Tue Sep 15, 2009 3:56 am
by Sylus101
The link isn't working, there's a space in there causing it to not load, but I was able to get to the stuff directory and then view the image okay.

Okay... here's what I THINK is happening... I'm pretty sure though.

You would use the -gT parameter if the image was 16 bit (this is what I'm not totally sure on). Since the image is already 256 color, it would automatically use palette color 0 as transparent and would work fine totally without that option. If the magenta was a different palette color, say slot 5, you'd use the option -pT5 instead.

Re: transparency not working?

Posted: Wed Sep 16, 2009 1:20 am
by WinterMute
Looks like the webhost forbids hotlinking, nothing wrong with the URL.

The -gT parameter will work fine with paletted images - it searches the palette for the color you specify. You both missed the output from grit

Code: Select all

WARNING:   tru/pal -> pal conversion with transp color option.
    looking for color FF00FF in palette.
STATUS:   Palette transparency: pal[0].
STATUS: Work-DIB creation complete: 256x192@8.
Which indicates that things are working as expected.

On the DS palette index 0, as well as being transparent, specifies the backdrop color which is displayed when all pixels at a given location are transparent. You'll see this in action by adding another layer.

Code: Select all


#include <nds.h>

#include "vuurrobin.h"

const u32      vuurrobinBGLayer    = 0;
const BgType    vuurrobinBGType     = BgType_Text4bpp;
const BgSize    vuurrobinBGSize     = BgSize_T_256x256;

int main(void) {

	videoSetMode(MODE_0_2D);
	vramSetBankA(VRAM_A_MAIN_BG);

	int bg0 = bgInit(0, vuurrobinBGType, vuurrobinBGSize, 0, 1);
	int bg1 = bgInit(1, vuurrobinBGType, vuurrobinBGSize, 1, 1);

	dmaCopy(vuurrobinMap, bgGetMapPtr(bg0), vuurrobinMapLen);
	dmaCopy(vuurrobinMap, bgGetMapPtr(bg1), vuurrobinMapLen);
	dmaCopy(vuurrobinTiles, bgGetGfxPtr(bg0), vuurrobinTilesLen);
	dmaCopy(vuurrobinPal, BG_PALETTE, vuurrobinPalLen);
	
	swiWaitForVBlank();
	bgSetScroll(bg1, 30, 25);
	bgUpdate();

	while(1) swiWaitForVBlank();

	return 0;
}


If the transparency wasn't working as you claim then this code would show only a single image. If you want a different backdrop color then you can set it manually after copying the palette ( BG_PALETTE[0]=0; ) or set the first palette entry in the image to the desired color, leaving out the -gT/-pT options and letting grit use the default.

Re: transparency not working?

Posted: Thu Sep 17, 2009 5:31 pm
by vuurrobin
I tried the code and you're right, 2 images appears. and setting the background palette index 0 changed the color (and changing the sub palette changed the color of the bottom screen).

I'll post a message in suggestions about some functions to set the backdrop color.

thanks Wintermute and Sylus101/Maximus (why didn't you changed your name here to?).