SDL Image Split screen

Trying to display two images on a screen takes about half the screen. Here is the code I'm using:

SDL_Init(SDL_INIT_VIDEO);
SDL_Surface* pScreen = SDL_SetVideoMode(1280,720,16, SDL_FULLSCREEN );
SDL_ShowCursor(SDL_DISABLE);
//load two images
SDL_Surface* pImage1 = IMG_Load("/media/x01.JPG");
SDL_Surface* pImage2 = IMG_Load("/media/x02.JPG");

//create two rectangles for left and right of screen
SDL_Rect leftR;
SDL_Rect rightR;
leftR.x = 600;
leftR.y = 0;
leftR.w = 640;
leftR.h = 720;
rightR.x = 640;
rightR.y = 0;
rightR.w = 640;
rightR.h = 720;

//display
SDL_BlitSurface(pImage1,&leftR,pScreen,&leftR);
SDL_BlitSurface(pImage2,&rightR,pScreen,&rightR);
SDL_Flip(pScreen);

//free image surfaces
SDL_FreeSurface(pImage1);
SDL_FreeSurface(pImage2);

//wait to see what on screen...
sleep(5);

//close SDL
SDL_Quit();

I hope to get a split screen effect with two static images. However, all that happens is the first image displayed on one half of the screen, the other is blank.

I tried to combine with Rect x and y, and it seems that the position of the image does not change, but instead the size of the view rectangle. Any ideas?

+3
source share
1 answer

SDL_BlitSurface accepts two rectangles, one for the source and one for the destination.

The source rectangle , which is the second parameter, is part of the portion of the original image (in this case, your image).

destination, , .

, , , , . , NULL .

+5

All Articles