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.

Beginners > Displaying problem in MODE4

#71814 - Miles_wy_1 - Tue Feb 14, 2006 5:46 pm

[Images not permitted - Click here to view it]
I want to diplay the picture above.But it turned out like this:
[Images not permitted - Click here to view it]
I dont know Y.
this is my source code:

#include "gba.h"
#include "dragon.h"
int main()
{
int y,x;
SetMode(MODE_4|BG2_ENABLE);
for (x=0;x<256 ;x++ )
{
BG_PaletteMem[x]=dragonPalette[x];
}
for (y=0;y<160 ;y++ )
{
for (x=0;x<120; x++)
{
FrontBuffer[(y)*120+(x)]=dragonData[(y)*120+(x)];
}
}
return 0;
}
I know it's a very simple program,but it troubled me a lot.
all the pointers are type of U16,is there any significant aspect that i ignored?

#71827 - kusma - Tue Feb 14, 2006 7:11 pm

it looks to me like you're trying to display a tiled image in a linear framebuffer. how did you convert the bitmap?

#71877 - tonkinfash - Wed Feb 15, 2006 1:34 am

I'm presuming that the dragon image is also an array of unisgned shorts...

#71899 - Miles_wy_1 - Wed Feb 15, 2006 6:13 am

kusma wrote:
it looks to me like you're trying to display a tiled image in a linear framebuffer. how did you convert the bitmap?


I use a tool named Bmp2head to convert the bitmap.It's downloaded from GBAdev.org.
The "dragon.h" has two arrays like this:
const u16 dragonData[] = {
0x3a3a,0x3a3a,0x3a3a,0x3a3a,...
}
const u16 dragonPalette[] = {
0x7fff,0x67ff,0x4bff,0x7f3f,...
}

Wow,wait~
I just read the README file of BMP2HEAD.It says"The program splits the image into 8x8 tiles when it saves it as a Header file, so it can be loaded into the GBA in a simple way."I think that's the solution....
BTW,like your suggestion,how can I display a picture in a linear framebuffer.Is there any tools that help?It seems that all the converters change pictures into tiled image...

#71904 - gauauu - Wed Feb 15, 2006 6:53 am

Cearn's Wingit and Usenti have very configurable exporters. You can export to just about anything you want.

Also, you might want to read up in the faq or do a search here about why it's bad to put graphics data in header files. If your tool spits out C code, it's best to at least turn them into .c files and compile/link them separately.

#71912 - Miles_wy_1 - Wed Feb 15, 2006 8:39 am

Problem Soluted!~Thanks in advance!