[OpenLayer] Drawing white instead of images
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.
|1||void CTileHandler::LoadTileSet(string file)|
|3|| DATAFILE *tileData = load_datafile(file.c_str());|
|4|| stringstream tileInfo((char*)tileData.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.dat);|
|14|| TileSet *newSet = new TileSet;|
|15|| int xOff = 0, yOff = 0;|
|16|| for(int n = 0; n < height; n++)|
|18|| for(int n2 = 0; n2 < width; n2++)|
|20|| newSet->tiles.push_back(new Bitmap(tileSheet, Rect(xOff, yOff, tileWidth, tileHeight)));|
|21|| xOff += tileWidth;|
|23|| xOff = 0;|
|24|| yOff += tileHeight;|
|26|| m_tileSets[name] = newSet;|
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.
Bitmap *tilesheet = new Bitmap((BITMAP *)tileData.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:
Fladimir da Gorf
Does it work if you load the image directly from the image file?
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.
Thread #590000. Printed from Allegro.cc
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.dat, false, true);
Since by images didn't have alpha channels, otherwise they were being drawn completely transparent.