questions about libnds

Post Reply
User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

questions about libnds

Post by vuurrobin » Sat May 16, 2009 12:36 am

hello everybody

I have some questions about the libnds sprite functions, and some documentation 'bugs'.

first the questions:

1. I always thought you needed to enable which background you want to use and if you want to use sprites when calling videoSetMode(). however, I found that it also works without enabling backgrounds and sprites. is it because it may or may not be already enabled, like powerOn(). or is it something else?

2. the oamInit() documentation says that I should use 'SpriteMapping_Bmp_1D_128 or SpriteMapping_Bmp_1D_256' if I want to mix tiled and bitmap sprites. well, I tried it, making sure that grit converted my image into bitmap form. but the sprite was completely disorted (like I kinda expected). I didn't saw a way to tell the engine that my sprite was in fact a bitmap sprite instead of a tiled sprite. how should I do it.

3. there is a oamSetMosaic() function, but it only works for the main engine. I asume there should be a oamSetMosaicSub() function, but I cant find it (its not in the documentation). could you create it if its not created yet and properly document it?

4. I've heard it is possible to alpha blend sprites, but I coudn't find a way to do it. is there a function to enable alpha blending?

5. there is 1 palette with 256 colors per main/sub sprites and backgrounds (so 4 normal palettes in total), and the only way to get more palettes is to use vram as extended palettes, right? is there a limit on how many extended palettes I can have? and which vram banks can I use best for it.

6. I know that you can rotate and scale a sprite using oamRotateScale(). but when I look at toncs page on affine transformation it says that you can also shear a sprite. is it possible to do this with the current funcions? if not, could you include a function so people could set the affine transformation themselfs. something like this:

Code: Select all

/**
 * @brief allows you to directly sets the affine transformation matrix
 * 
 * with this, you have more freedom to set the matrix, but it might be more difficult to use if 
 * you're not used to affine transformation matrix. this will erase the previous matrix stored at rotId.
 * 
 * @param oam	the oam engine, must be &oamMain or &oamSub
 * @param rotId	the id of the rotscale item you want to change, must be 0-31
 * @param hdx	the horizontal x value?
 * @param hdy	the horizontal y value?
 * @param vdx	the vertical x value?
 * @param vdy	the vertical y value?
 */
void oamAffineTransformation(OamState* oam, int rotId, int hdx, int hdy, int vdx, int vdy)
{
	sassert(rotId >= 0 && rotId < 32, "oamAffineTransformation() rotId is out of bounds, must be 0-31")	

	oam->oamRotationMemory[rotId].hdx = hdx >>12;
	oam->oamRotationMemory[rotId].hdy = hdy >>12;
	oam->oamRotationMemory[rotId].vdx = vdx >>12;
	oam->oamRotationMemory[rotId].vdy = vdy >>12;
}
7. with oamSet(), we can update all the sprites attributes in 1 time. but sometimes it would be easier to just update 1 thing at a time. I looked at the source of the oamSet function, and I think its possible to create funcions to update just 1 thing. could you create those funcions, or that I create them and you could include them. or am I not seeing something that would make this impossible.


the documentation 'bugs':

the enums POWER_ALL_2D and POWER_ALL aren't documented in system.h
the function videoSetMode() is doxygen documentated in video.h, but it doesn't apear in the documentation.
the function (or macro?) intToFixed() isn't documentated, as wel as de BIT() macro.
the documentation says that the return type of oamCountFragments() is void, while it actually is int.
the description of oamFreeGfx() is the same as oamGetGfxPtr(), which I dont think is right (probably a copy paste mistake).
the description of oamSetMosaic() says 'sets sprite mosaic', which makes you think that is't sprite specific.
could you change it so it says that the effect go's for every sprite that has mosaic turned on.
lcdMainOnBottom(), lcdMainOnTop() and lcdSwap() aren't in the documentation

and you don't need to specify the function if the function follows directly after the doxygen comment.



also, is there a place where I can download the libnds sourcecode in 1 go? I looked here, but it seems you can only download 1 file at a time, which means it would take forever to download everything.

greets

vuurrobin

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: questions about libnds

Post by Sylus101 » Sat May 16, 2009 3:27 am

I'll try to answer what I can...

1. As far as I know you don't need to do anything with backgrounds to use sprites... I can say most initializations are handled for you now, so make sure to focus the current examples as old tutorials include some things you can skip now.

2. Not sure here, sorry... I too don't see any way to mix tiled and bmp sprites...

3. Again, never used the mosaic feature...

4. The palette parameter for oamSet() instead supplies the alpha blending value for bmp sprites. 0 for completely transparent to 15 for opaque.

5. You're right on the 4 normal palettes and using VRAM for extended palettes. For what can be used for what, I would defer to the gbatek docs:
http://nocash.emubase.de/gbatek.htm#dsmemorycontrolvram

6. I've only used rotation... sorry.

7. I'm pretty sure Wintermute nor dovoto are planning on creating any additional functions, but as you can surely see you're welcome to look at the source and write your own.

I'll skip the bugs... but you should be able to use an svn client and download the source... see here http://sourceforge.net/scm/?type=svn&group_id=114505

I'm not sure how to just get libnds, though... last I tried I got all of DKP.
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

Re: questions about libnds

Post by vuurrobin » Thu May 21, 2009 10:13 pm

thanks for all the anwsers, Sylus101.

1. if its taken care of by libnds, then I don't have to worry about it. I just wanted to make sure that I dont get undefined behavior later on.

2. I figured out how to get bmp sprites. you need to use 'SpriteColorFormat_Bmp' when specefying the bitdebth with oamSet(). also make sure to convert your image correctly.

3. I looked at the code for setting the mosaic on the main engine, and modefied it to work on the sub engine. and from what I could find, the function doesn't exist in the current libnds. I'll post the code, so dovoto or wintermute (or another maintainter, if there are more) can add it to libnds.

Code: Select all

/**
 *    \brief sets sprite mosaic
 *    \param dx (0-15) horizontal mosaic value
 *    \param dy (0-15) horizontal mosaic value
 */
static inline void oamSetMosaicSub(unsigned int dx, unsigned int dy)
{
	sassert(dx < 16 && dy < 16, "Mosaic range is 0 to 15");

	SUB_MOSAIC_CR &= ~(0xFF00);
	SUB_MOSAIC_CR |= (dx << 8)| (dy << 12);
}
however, it seams that the dx parameter doesn't work (it has no effect, no matter what value you use). this is also an bug in the oamSetMosaic() function for the main engine, so the register probably isn't modefied right.


4. I tried different values for the palette parameter when using bmp sprites, but it didn't had any effect. also, I could already specify which color to be transparant when converting the image. and I thought that you coudn't give different alpha values for different sprites, that you could specify 1 value for alpha blending per engine and specify whether a sprite needed to be alpha blended or not.

5. I think I get it...

6. AFAIK, the only way to use shearing is with a function like the one I created. which is ok, but it would be nice if it was included in libnds

7. I'll see if I can write my own then.


thanks for the link. I managed to get the code using a scm client.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests