SDL - Rendermap

Hello,

I am writing on a function that is going to render my map but somehow it is not returning anything. I have really no idea why it is not working. All the other function which are used in it are working so it must be a problem with that function. I am looking for the failure but I can't find one.
Thanks for your help!

Christoph

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//Render Map
SDL_Surface* render_map( SDL_Surface *chipset )
{
	//Init of graph coordinats
	int x;
	int y;
	
	//SDL_Surface
	SDL_Surface *temp_map = NULL;

	//Map array
	int map_offset [15][6]=
							{
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2},
								{4,5,3,0,1,2},
								{1,2,3,0,1,2},
								{1,2,3,0,1,2}
							};

	//Rect
	SDL_Rect set[6];

	//Sprite map left corner top
	set[0].x = 0;
	set[0].y = 0;
	set[0].w = 32;
	set[0].h = 32;

	//Sprite map left corner bottom
	set[3].x = 0;
	set[3].y = 32;
	set[3].w = 32;
	set[3].h = 32;

	//Sprite map middle top
	set[1].x = 32;
	set[1].y = 0;
	set[1].w = 32;
	set[1].h = 32;

	//Sprite map middle bottom
	set[4].x = 32;
	set[4].y = 32;
	set[4].w = 32;
	set[4].h = 32;

	//Sprite map right corner top
	set[2].x = 64;
	set[2].y = 0;
	set[2].w = 32;
	set[2].h = 32;

	//Sprite map right corner bottom
	set[5].x = 64;
	set[5].y = 64;
	set[5].w = 32;
	set[5].h = 32;
	
	//Loop for map drawing
	for(y=0; y<MAP_HEIGHT; y++)
	{
		for(x=0 ; x<MAP_WIDTH; x++)
		{	
			switch(map_offset[y][x])
				{
					case 1  : apply_surface(x*32, y*32, chipset, temp_map, &set[0]); break;
					case 2  : apply_surface(x*32, y*32, chipset, temp_map, &set[1]); break;
					case 3  : apply_surface(x*32, y*32, chipset, temp_map, &set[2]); break;
					case 4  : apply_surface(x*32, y*32, chipset, temp_map, &set[3]); break;
					case 5  : apply_surface(x*32, y*32, chipset, temp_map, &set[4]); break;
					case 6  : apply_surface(x*32, y*32, chipset, temp_map, &set[5]); break;
					default : break;
				}
		}
	}

	//Return the rendered image
	return temp_map;
}
Is this the prototype? void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
Note that that will not change temp_map but what is pointed by temp_map
Try this instead:
1
2
3
4
5
6
7
//SDL_Surface* render_map( SDL_Surface *chipset );
SDL_Surface render_map( SDL_Surface *chipset );

//SDL_Surface *temp_map = NULL;
SDL_Surface temp_map;
//apply_surface(x*32, y*32, chipset, temp_map, &set[0]);
apply_surface(x*32, y*32, chipset, &temp_map, &set[0]);
Yes you are right about the prototype and I see what I did wrong. Pretty dumb its clear now to me. Thanks! But there is still the problem that I don't get an image so I think there must be something still wrong -.- .
Okay I know now that the error happens when I blit the surface on to the temp_map. but I have no idea at all why...

Okay I found out what was wrong. I can just blit on the screen I have no idea why I would be very happy if somebody can explain that to me!


I solved the problem my self. My fault was that I didn't create the surface with SDL_CreateRGBSurface. And my second problem was how to color that new surface I will post my solution maybe it will help somebody too.

If you have any question feel free to ask.

Creation of the surface
 
SDL_Surface* map = SDL_CreateRGBSurface( SDL_SWSURFACE, TILES_WIDTH * MAP_WIDTH, TILES_HEIGHT * MAP_HEIGHT, 32, 0, 0, 0, 0  );


Function to colorkey the new surface
1
2
3
4
5
6
7
8
9
10
//ColorKey Empty Surface
void colorkey_surface( SDL_Surface *keying )
{
	//Fill the Surface with the color to key
	SDL_FillRect( keying, &keying->clip_rect, SDL_MapRGB( keying->format, 255, 0, 255 ) );

	//Clean the color
	SDL_SetColorKey( keying, SDL_SRCCOLORKEY, SDL_MapRGB( keying->format, 255, 0, 255 ) );

}

Last edited on
Topic archived. No new replies allowed.