Problem with a BLITing function

Hi everyone.

i have this peace of code, and my problem is in the set() function that i created:

Code:
SDL_Surface* window = SDL_SetVideoMode(1024, 768, 32, 0);
SDL_Surface* img = SDL_LoadBMP(“ship.bmp”);
SDL_Surface* bg = SDL_LoadBMP(“background.bmp”);

int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);

for (int i = 0; i < 400; ++i)
{
    //SDL_BlitSurface(bg, &imgRect, window, &destRect);
    set(bg, window, 0, 0);
    set(img, window, 40, 700-i);
    SDL_UpdateRect(window, 0, 0, 0, 0);
}
SDL_Quit();

}

heres the function:

Code:
int set(SDL_Surface* i, SDL_Surface* dest, int destX, int destY)
{
SDL_Rect imgRect;
imgRect.x = 0;
imgRect.y = 0;
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;

SDL_BlitSurface(i, &imgRect, dest, &destRect);

}

the problem is that in main, the program only blits the bg image once, and in all the other loops the bg image is not blited. But the img image blits fine in every loop.
what am i doing wrong here??

when i use the blit function by itself it works fine, for example:

Code:
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);

SDL_Rect imgRect;
imgRect.x = 0;
imgRect.y = 0;
SDL_Rect destRect;
destRect.x = 0;
destRect.y = 0;

for (int i = 0; i < 400; ++i)
{
    SDL_BlitSurface(bg, &imgRect, window, &destRect);
    set(img, window, 40, 700-i);
    SDL_UpdateRect(window, 0, 0, 0, 0);
}
SDL_Quit();

}

like this, bg is blited in every loop cicle, but i want to be able to use my function.

Any ideas why it isnt working??[/code][/quote]

[…]

Code:
int set(SDL_Surface* i, SDL_Surface* dest, int destX, int destY)
{
SDL_Rect imgRect;
imgRect.x = 0;
imgRect.y = 0;
SDL_Rect destRect;
destRect.x = destX;
destRect.y = destY;

SDL_BlitSurface(i, &imgRect, dest, &destRect);

}
[…]

It seems like you’re never setting the .w and .h fields of any rects, which
means SDL_BlitSurface() gets random garbage for width and height of the source
rect. :-)On Wednesday 27 October 2010, at 18.43.06, “ShiroAisu” wrote:


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://olofsonarcade.com http://kobodeluxe.com |
’---------------------------------------------------------------------’

Oh… yes i forgot lol, i was conssidering the SDL_Rect to have a constructor :stuck_out_tongue: my bad.

Also, you should probably initialize SDL before you use SDL_SetVideoMode for
portability’s sake. You’re using it at the global scope, before main().

Jonny DOn Wed, Oct 27, 2010 at 1:10 PM, ShiroAisu wrote:

Oh… yes i forgot lol, i was conssidering the SDL_Rect to have a
constructor [image: Razz] my bad.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Oh… yes i forgot lol, i was conssidering the SDL_Rect to have a
constructor [image: Razz] my bad.

You might want to use an SDL wrapper if you’re used to programming with C++
rather than C (SDLmm, etc).On 27 October 2010 13:10, ShiroAisu wrote: