开发者

SDL Image Split screen

Trying to display two images on screen each take up one half of the screen. Here is the code I am 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's on s开发者_如何学Ccreen...
sleep(5);

//close SDL
SDL_Quit();

I'm hoping to achieve a split screen effect with two static images. However all that happens is the first image is being displayed on one half of the screen, the other is blank.

I have tried messing around with the Rect x & y and it seems the position of the image doesn't change but instead the size of the viewing rectangle does. Any ideas?


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

The source rectangle, which is the second parameter, is what part of the source surface (in this case, your image) to draw.

The destination rectangle, which is the fourth parameter, is where to draw on the destination surface.

You're passing the same rectangle for both, which probably isn't what you want. If you just want to display the whole image, pass NULL for the source rectangle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜