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 > Tiles loading odd

#20081 - CyberSlag5k - Sat May 01, 2004 5:21 pm

I'm attempting to load some tiles into vram, only they are not loading correctly. Every other pixel appears white:

[Images not permitted - Click here to view it]

I was thinking the problem was that the data is stored in a 0xXX format instead of 0xXXXX but even switching converting the data for the first tile produced the same result for that tile.

to no avail. So perhaps the problem lies elsewhere? My data file looks like this:

Code:

const short towerMap[1024] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
,
1, 1, 2, 3, 1, 1, 106, 1, 3, 3, 1, 1, 1, 1, 1, 1,
1, 1, 1, 106, 106, 106, 1, 1, 1, 1, 36, 1, 1, 1, 1, 1
,
1, 106, 1, 3, 1, 1, 1, 1, 1, 3, 3, 3, 1, 1, 1, 1,
1, 106, 1, 1, 1, 1, 1, 1, 17, 1, 36, 36, 4, 1, 1, 1 ......

const unsigned short towerPalette[256] = {
0x7FFF, 0x67FF, 0x4FFF, 0x33FF, 0x1BFF, 0x03FF, 0x7F3F, 0x673F,
0x4F3F, 0x333F, 0x1B3F, 0x033F, 0x7E7F, 0x667F, 0x4E7F, 0x327F,
0x1A7F, 0x027F, 0x7D9F, 0x659F, 0x4D9F, 0x319F, 0x199F, 0x019F,.....

const unsigned char towerTiles[18496] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE3, 0xE3, 0xE5, 0xE6, 0xE6, 0xE3, 0xE6, 0xE5, ....



I load the data in as such:

Code:

   for(int i = 0; i < 256; i++)
        BGPaletteMem[i] = towerPalette[i];

   for(int i = 0; i < 9248*2; i++)
      tileData[i] = towerTiles[i];

   for(int i = 0; i < 512; i++)
      mapData[i] = (towerMap[i];


Halving the conditional value in the for loop that loads the tile data has no effect. I'm kind of at a loss here and don't know what else to try...

Any help would be appreciated.
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20085 - KRoot - Sat May 01, 2004 6:49 pm

The reason that this happens is because you can only send 16 bits to VRAM at a time. To send the data to VRAM, you have to do a type conversion to 16 bits like this:

Code:
   u16* temp;      //temporary storage pointer

   for(int i = 0; i < 256; i++)
        BGPaletteMem[i] = towerPalette[i];

   temp = (u16*)towerTiles;
   for(int i = 0; i < 9248*2; i++)
      tileData[i] = temp[i];

   temp = (u16*)towerMap;
   for(int i = 0; i < 512; i++)
      mapData[i] = temp[i];


That should solve the problem.

#20086 - CyberSlag5k - Sat May 01, 2004 6:57 pm

Quote:

The reason that this happens is because you can only send 16 bits to VRAM at a time.


I was unaware of that.

That fixed the problem, thank you.
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20087 - sajiimori - Sat May 01, 2004 7:13 pm

The map array is already short[], so no change necessary there.

Also, if tileData is still u16*, the problem isn't quite as KRoot explained it (though the solution still works, of course). You're reading a byte at a time from towerTiles, and writing 2 bytes at a time to tileData. The compiler automatically pads the byte with zeros to extend it to 16 bits, so every other pixel is 0, which is transparent.

When you have transparent pixels that see through to "nothing", the backdrop's color is the first color of the background palette, which is white in your case.

#20098 - CyberSlag5k - Sun May 02, 2004 12:22 am

Quote:
You're reading a byte at a time from towerTiles, and writing 2 bytes at a time to tileData.


I figured something like that was happening. I tried several solutions. Heh, I even tried adding each tileData element to itself each time I loaded. As I think about it, though, it would have made more sense to copy the element, bit shift it two to the left and then OR the two.

Ahh well. I'm still having some problems with my map but I'm sorting it out. I"ll probly get frustrated in and post a question on it in about an hour. Just so you guys can look forward to that :)
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...