[OpenLayer] Drawing white instead of images
GrantG

I am working on a 2d tile map system and am having some problems when drawing the tiles. I am loading the tile sheet from an Allegro datafile and am splitting up the tiles within the program.

The problem is all the tiles show up as white blocks.

Here is the tile set loading function. I figured something must be wrong here.

1void CTileHandler::LoadTileSet(string file)
2{
3 DATAFILE *tileData = load_datafile(file.c_str());
4 stringstream tileInfo((char*)tileData[0].dat);
5 int width, height, tileWidth, tileHeight;
6 string name;
7 tileInfo >> name;
8 tileInfo >> width;
9 tileInfo >> height;
10 tileInfo >> tileWidth;
11 tileInfo >> tileHeight;
12 Bitmap tileSheet((BITMAP*)tileData[1].dat);
13 
14 TileSet *newSet = new TileSet;
15 int xOff = 0, yOff = 0;
16 for(int n = 0; n < height; n++)
17 {
18 for(int n2 = 0; n2 < width; n2++)
19 {
20 newSet->tiles.push_back(new Bitmap(tileSheet, Rect(xOff, yOff, tileWidth, tileHeight)));
21 xOff += tileWidth;
22 }
23 xOff = 0;
24 yOff += tileHeight;
25 }
26 m_tileSets[name] = newSet;
27}

CursedTyrant

Here's what's wrong:

OpenLayer's manual said:

Bitmap(const Bitmap &other, const Rect &area );

//Construct a sub-bitmap of an area of the given Bitmap.

Sub bitmaps usually require original Bitmaps to exist in memory (and your does not). Your bitmap does not exist outside of your loading function.

Try this:

Bitmap *tilesheet = new Bitmap((BITMAP *)tileData[1].dat);

Don't forget to release and delete it when quitting.

But, in case that doesn't work, a few things from the top of my mind:

  • attach OL's log

  • try setting Canvas::SetPixelWriteMode(COLOR_AND_ALPHA);

  • make sure the images are power of 2 if your card doesn't support non-power-of-two textures (vide log)

Fladimir da Gorf

Does it work if you load the image directly from the image file?

OICW

Maybe something went wrong with antialising? I remember that when I switched it off, it drawn only white rectancles instead of sprites - which was very weird. Also make sure that you have proper color depth.

GrantG

Well I fixed it. I thought when making a sub-bitmap it actually copied the data over, I guess that wasn't the case. Also just doing that didn't work.

I had to do.
Bitmap((BITMAP *)tileData[1].dat, false, true);

Since by images didn't have alpha channels, otherwise they were being drawn completely transparent.

Thread #590000. Printed from Allegro.cc