sprite from image not showing

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

sprite from image not showing

Post by vuurrobin » Tue May 05, 2009 12:41 am

hello everybody

I'm trying to put a sprite on the screen from an image thats processed by grit. I modify'd the simple sprite example, but the image is somehow not showing.

here is my code:

Code: Select all

#include <nds.h>

#include "vuurrobin.h"//generated by grit

int main()
{
    powerOn(POWER_ALL_2D);
	videoSetMode(MODE_0_2D);

	vramSetBankA(VRAM_A_MAIN_SPRITE);
	oamInit(&oamMain, SpriteMapping_1D_32, false);
	u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_64x64, SpriteColorFormat_256Color);


    dmaCopyHalfWords(3, vuurrobinTiles, gfx, vuurrobinTilesLen);
    dmaCopyHalfWords(3, vuurrobinPal, SPRITE_PALETTE, vuurrobinPalLen);


    /*
	for(int i = 0; i < 32 * 32 / 2; i++)
	{
		gfx[i] = BIT(0) | BIT(8);
	}

	SPRITE_PALETTE[1] = RGB15(31,0,0);
    //*/


    oamSet(&oamMain,            //main graphics engine context
        0,                      //oam index (0 to 127)
        10, 10,                 //x and y pixle location of the sprite
        0,                      //priority, lower renders last (on top)
        0,					    //this is the palette index if multiple palettes or the alpha value if bmp sprite
        SpriteSize_64x64,
        SpriteColorFormat_256Color,
        gfx,                    //pointer to the loaded graphics
        -1,                     //sprite rotation data
        false,                  //double the size when rotating?
        false,			        //hide the sprite?
        false,                  //vflip
        false,                  //hflip
        false	                //apply mosaic
        );


    swiWaitForVBlank();
    oamUpdate(&oamMain);


	return 0;
}
if I use the commented out for loop instead of the dmacopy's, it does show the red box, so there has to be something wrong with the dmacopy's (or the generated data), but I cant figure out what.

the image is a 64*64 png image with the following grit rule file:

Code: Select all

# Set the warning/log level to 3
-W3

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

# Tile the image
-gt

# Set the bit depth to 4 (16 colors)
-gB4
is there anything wrong with it, or are there any options which I could add to process the image better, because it gives me a: "WARNING: No explicit symbol name. In overwrite mode, so using dst title."

does anybody know what I am doing wrong?

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

Re: sprite from image not showing

Post by Sylus101 » Tue May 05, 2009 1:33 am

I'm not sure about the grit rule, but you're missing a normal game loop. After the oamSet() change what you have to this...

Code: Select all

while(1){
   oamUpdate(&oamMain);
   swiWaitForVBlank();
}
Oh, and your grit rule mentions using only 4bit, 16 colors and you initialized the sprite with 256 colors. That would be an issue as well.
-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: sprite from image not showing

Post by vuurrobin » Tue May 05, 2009 1:07 pm

you don't need an 'game' loop, perse. I wait for vblank, update the oam and then the main function ends, in which the ds probably enters an endless do-nothing loop, untill you turn the power off. It has worked every time so far, so that can't be the problem.

however, changing the grit rule file to use 8 bits instead of 4 fixed the problem. I really should stop directly copying grit rule files and make my own, or triple checking them.

thanks a lot :)

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

Re: sprite from image not showing

Post by Sylus101 » Tue May 05, 2009 2:22 pm

You did mention that the drawn in red box showed up, so I suppose I should have figured that it'd be okay without the loop. I just wasn't sure what the DS behavior was after main() ends.

Glad I could help anyway, lol.
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

eKid
Posts: 65
Joined: Sat Dec 06, 2008 6:07 pm
Contact:

Re: sprite from image not showing

Post by eKid » Tue May 05, 2009 7:33 pm

I think last time I checked main() returning isn't handled, so you'll get undefined behavior. You should use "while(1) swiWaitForVBlank();" or perhaps "swiIntrWait(0,0);" instead.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests