Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [OpenLayer] Drawing white instead of images

Credits go to CursedTyrant for helping out!
This thread is locked; no one can reply to it. rss feed Print
[OpenLayer] Drawing white instead of images
GrantG
Member #8,173
December 2006
avatar

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
Member #7,080
April 2006
avatar

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)

---------
Signature.
----
[My Website] | [My YouTube Channel]

Fladimir da Gorf
Member #1,565
October 2001
avatar

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

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

OICW
Member #4,069
November 2003
avatar

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.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

GrantG
Member #8,173
December 2006
avatar

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.

Go to: