SDL_CreateRGBSurface is black?

Hi i’m new here and my english isn’t good, but i have the following code:

Code:

SDL_Surface * tile = SDL_CreateRGBSurface(
SDL_SWSURFACE,
tilesize[0],
tilesize[1],
this._tileset.format.BitsPerPixel,
0, 0, 0, 0
);

for (ushort y = 0; y < height; y++) {
for (ushort x = 0; x < width; x++) {
SDL_Rect rect = {
cast(ushort) (x * 16),
cast(ushort) (y * 16),
16, 16
};

	SDL_BlitSurface(this._tileset, &rect, tile, null);
	if (!tile) {
		writeln("Tile konnte nicht aus dem Tileset geladen werden");
		exit(0);
	}

	this._tiles ~= tile;
}

}

The tileset grafic is ok and the code give me no error, the lopp runs correct, but if i try to take one of the tiles to blit them on the screen, i get a black rectangle.
How is that possible? I think that SDL_CreateRGBSurface create the failure, but what think the others and can anyone help me?

I have dissolved the problem, i have add simply
Code:
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff

to SDL_CreateRGBSurface.
But now i can get the individual tile but not the total map.
For this i have the following code:

Code:

SDL_Surface * map = SDL_CreateRGBSurface(
SDL_SWSURFACE,
cast(ushort) (5 * 16),
cast(ushort) (5 * 16),
32,
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff
);

ushort gid = std.conv.to!(ushort)(item_child.tag.attr[“gid”]);
SDL_Surface * tile = tileset.getTile(gid);
if (!tile) {
writefln(“Tile ‘%d’ konnte nicht geladen werden”, gid);
exit(0);
}

ushort[2] pos = [
cast(ushort) (column * 16),
cast(ushort) (line * 16)
];
SDL_Rect rect = {
pos[0], pos[1],
16, 16
};

SDL_BlitSurface(map, null, tile, &rect);

column += 1;
if (column >= 5) {
column = 0;
line += 1;
}

What’s now the problem? :confused:

Your code lacks error checking. Almost every SDL function can return an
error. See the SDL documentation for the different function signatures and
how to detect these errors (http://www.libsdl.org/cgi/docwiki.cgi) You
should detect these and try obtain the value of “SDL_GetError()”, which
might hint at what is going on.

Regards,
– Brian.On 11 July 2010 23:28, mutable wrote:

What’s now the problem? :confused: