PDA

View Full Version : SDL tutorial in C



swappo1
March 24th, 2009, 03:29 AM
Hello,

I am trying to convert an SDL tutorial from lazy foo from C++ to C but I don't know C++. I have the following written in C++ and I am not sure how to convert the SDL_Rect* clip = NULL into something C will accept. Here is the function and output. Any ideas?

SDL_Rect clip[4];
..........................
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL)
{
SDL_Rect offset;

offset.x = x;
offset.y = y;

SDL_BlitSurface(source, clip, destination, &offset);

lazyfoo6.c:17: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
lazyfoo6.c:95: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token

Simian Man
March 24th, 2009, 03:32 AM
That is a default parameter. Just remove it and wherever the apply_surface function is called with a missing parameter, substitute NULL for it.

Hope that makes sense.

swappo1
March 24th, 2009, 03:54 AM
If I understand you correctly, I should remove the = NULL from the function and prototype and use NULL for last argument of apply_surface. Then I wouldn't blit the sprites to the surface. I am not sure why SDL_Rect* clip is even set to NULL in the first place. Here is where apply_surface is called.

apply_surface(0, 0, dots, screen, &clip[0]);
apply_surface(540, 0, dots, screen, &clip[1]);
apply_surface(0, 480, dots, screen, &clip[2]);
apply_surface(540, 480, dots, screen, &clip[3]);
If I remove = NULL from the function and prototype, all I get is a white screen when I should have four sprites blitted to the corners of the white screen.

swappo1
March 24th, 2009, 04:45 AM
Okay, I found the problem and it was unrelated to = NULL.