Reputation: 199
I am currently using SDL to draw an image to the screen, it loads the image with no errors. But when I go to draw the image to the screen, nothing is shown. Here is my code:
Image load Function:
SDL_Surface *d2Sprite::Load(char *file)
{
SDL_Surface *temp = NULL;
SDL_Surface *opt = NULL;
if((temp = SDL_LoadBMP(file)) == NULL)
{
cout << "Unable to load image '" << file << "'. " << SDL_GetError() << endl;
return NULL;
}
opt = SDL_DisplayFormatAlpha(temp);
SDL_FreeSurface(temp);
return opt;
}
Drawing Function:
bool d2Sprite::Draw(SDL_Surface *dest, SDL_Surface *src, int x, int y)
{
if(dest == NULL || src == NULL)
{
cout << "Unable draw sprite! " << SDL_GetError() << endl;
return false;
}
SDL_Rect destR;
destR.x = x;
destR.y = y;
SDL_BlitSurface(src, NULL, dest, &destR);
return true;
}
Upvotes: 0
Views: 663
Reputation: 19
Are you calling SDL_Flip() after all of your calls to Draw()? You need this to flip your back buffer (where the blitting takes place) and the front buffer (what is shown on the screen).
Upvotes: 1
Reputation: 400129
You are not setting the width and height of the rectangle used for blitting, destR
.
You should inspect the return value of the blir operation to figure out if it succeeded.
Also, you might have issues with the alpha blending, since you enable alpha for the surface but don't set it before doing so. See the SDL_BlitSurface()
documentation.
Upvotes: 1