Sign in to follow this  
ICUP

SDL_BlitSurface Question

Recommended Posts

Here is Lazyfoo's apply surface function
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;
    
    //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &offset );
}
Here is Focus On SDL's example program for blitting surfaces
....

g_SrcRect.w = g_DstRect.w = g_pBitmapSurface->w;
	g_SrcRect.h = g_DstRect.h = g_pBitmapSurface->h;
	g_SrcRect.x = g_SrcRect.y = 0;

	for ( ;; )
	{
		if ( SDL_PollEvent( &g_Event ) == 0 )
		{
			g_DstRect.x = rand() % ( SCREEN_WIDTH - g_DstRect.w );
			g_DstRect.y = rand() % ( SCREEN_HEIGHT - g_DstRect.h );
			SDL_BlitSurface( g_pBitmapSurface, &g_SrcRect, g_pDisplaySurface, &g_DstRect );
			SDL_UpdateRect( g_pDisplaySurface, 0, 0, 0, 0 );
		}
...

Lazyfoo's BlitSurface call passes NULL for the source rect. While Focus on SDL's call to BlitSurface passes the source rect. I passed a NULL to SDL_BlitSurface in Focus On SDL's example program. There was no difference. Is there any reason why Lazyfoo passes a NULL while FoSDL decides to pass the source rect?

Share this post


Link to post
Share on other sites
One more question actually. So, if you have no reason to clip from an image, if you pass in NULL, I'm guessing the sources rect is filled in with default values?

Share this post


Link to post
Share on other sites
Quote:
One more question actually. So, if you have no reason to clip from an image, if you pass in NULL, I'm guessing the sources rect is filled in with default values?


SDL_BlitSurface documentation
Quote:
The width and height in srcrect determine the size of the copied rectangle. Only the position is used in the dstrect (the width and height are ignored). Blits with negative dstrect coordinates will be clipped properly.

If srcrect is NULL, the entire surface is copied. If dstrect is NULL, then the destination position (upper left corner) is (0, 0).

The final blit rectangle is saved in dstrect after all clipping is performed (srcrect is not modified).


The source rectangle will be filled internally by SDL based on the dimensions of the source surface. The destination rectangle is the only one that will be modified by SDL.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this