gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Bitmap error

#130636 - ShadowX - Wed Jun 06, 2007 12:47 am

I tried to draw a bitmap in GBA using C.
Look what happens:
http://img529.imageshack.us/img529/6895/errorhl8.png

I used this code:
Code:

int main()
{
    u16 loop,x;
    SetMode( MODE_4 | BG2_ENABLE );
    for (loop=0;loop<256;loop++)
    {
       BG_PaletteMem[loop]=palette[loop];
    }
    for (x=0;x<(240*160);x++)
    {
        FrontBuffer[x]=bitmap[x];
    }
    return 0;
}

#130638 - Lick - Wed Jun 06, 2007 12:52 am

Try copying in shorts instead of bytes.

Code:
unsigned short *FrontBuffer = ....;

for (x=0; x<240*160/2; x++)
{
    FrontBuffer = ((unsigned short*)bitmap)[x];
}

_________________
http://licklick.wordpress.com

#130671 - gmiller - Wed Jun 06, 2007 12:54 pm

as Lick said do the copy in shorts because video memory must be written 16 bits at a time.

#130672 - ScottLininger - Wed Jun 06, 2007 2:12 pm

Just from the image, it looks like you might be writing some sprites or other tiles into your vram in the wrong spot. Try commented out any code besides your image writing routine.

-Scott

#130682 - ShadowX - Wed Jun 06, 2007 4:35 pm

Are you sure that is's not necessary the array's number?

I tried to convert the image using other tool.
The result: http://img394.imageshack.us/img394/5223/errornd4.png

#130752 - Cearn - Thu Jun 07, 2007 1:45 pm

It may help if we could see the original image, the declaration of the data array and which tool(s) and which settings you used to convert the image.

#130757 - ShadowX - Thu Jun 07, 2007 3:54 pm

Original image in 256 colors: http://www.aaronrogers.com/ham/Day4/gfx/bg.bmp

I used "BMP2GBA" in second post.

If I try to convert using a CommandLine tool it shows the window. And close.

#130918 - tepples - Sat Jun 09, 2007 5:33 am

ShadowX wrote:
If I try to convert using a CommandLine tool it shows the window. And close.

Q: I've downloaded a program, but when I double-click its icon in Windows Explorer, a window filled with black opens and closes so quickly that I cannot read it. How do I use this program?

Answered in FAQ.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#130953 - Cearn - Sat Jun 09, 2007 3:51 pm

ShadowX wrote:
Original image in 256 colors: http://www.aaronrogers.com/ham/Day4/gfx/bg.bmp
Right, so it's not just the image that goes wonky, it's the palette as well.
ShadowX wrote:
I used "BMP2GBA" in second post.
There are several tools of that name; you're to have to be a little more specific :P. Also try gfx2gba or grit/usenti. Those tools are pretty common and known to work properly.

Post the first few lines of the palette and bitmap arrays, that should show a few things. Most importantly, are they 'const' arrays?

As the others have indicated, VRAM needs to be written to in 16bit chunks (well, that or 32bit). I expect that bitmap is already 16bit so the datatype should be a problem, but what is is that you copy too much: 240x160 is the size of the bitmap in bytes, not halfwords. Divide by two to get the number of halfwords (see Lick's post). Better yet, just use memcpy().

#130975 - ShadowX - Sat Jun 09, 2007 8:15 pm

"Grit" works!
Can "Grit" convert to GBA sprite?

#130987 - Cearn - Sat Jun 09, 2007 9:17 pm

Yes. Sprite (aka object) graphics are just a special-case of tiled graphics. Objects effectively make use of tiled tiles (i.e., tiles made up of tiles; meta-tiles), use the Meta/Obj settings to whatever size meta-tiles you need. Note that the units of the meta-tiles are in tiles, though, not pixels