linux sdl 显示图像

http://hi.baidu.com/guzhou_diaoke/item/236f5337bc9417fd2784f415


/*
 * sdl image
 * guzhoudiaoke@126.com
 * 2011-11-22 22:19
 */

#include <stdio.h>
#include <SDL/SDL.h>

int main(int argc, char **argv)
{
    SDL_Surface *screen, *image1, *image2;
    SDL_Rect location1, location2;
    int delay = 4;

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        perror("SDLInit");
        return 1;
    }
    printf("SDL initialized.\n");
    
    screen = SDL_SetVideoMode(800, 600, 0, 0);
    if (screen == NULL) {
        printf("Problem: %s\n", SDL_GetError());
        return 1;
    }
    printf("Video mode set.\n");

    SDL_WM_SetCaption("SDL test image", "testing");
    image1 = SDL_LoadBMP("image1.bmp");
    if (image1 == NULL) {
        printf("Problem: %s\n", SDL_GetError());
        return 1;
    }
    printf("image1 loaded.\n");

    image2 = SDL_LoadBMP("image2.bmp");
    if (image2 == NULL) {
        printf("Problem: %s\n", SDL_GetError());
        return 1;
    }
    printf("image2 loaded.\n");

    location1.x = (screen->w - image1->w) / 2;
    location1.y = (screen->h - image1->h) / 2;
    location1.w = image1->w;
    location1.h = image1->h;


    location2.x = (screen->w - image2->w) / 2;
    location2.y = (screen->h - image2->h) / 2;
    location2.w = image2->w;
    location2.h = image2->h;

    if (SDL_BlitSurface(image1, NULL, screen, &location1) < 0) {
        printf("Problem: %s\n", SDL_GetError());
        return 1;
    }
    SDL_UpdateRects(screen, 1, &location1);
    SDL_Delay(delay * 1000);

    if (SDL_BlitSurface(image2, NULL, screen, &location2) < 0) {
        printf("Problem: %s\n", SDL_GetError());
        return 1;
    }
    SDL_UpdateRects(screen, 1, &location2);
    SDL_Delay(delay * 1000);
    SDL_Quit();

    return 0;
}

 

Makefile:

  1 all : sdl_image
  2
  3 sdl_image: sdl_image.c
  4         g++ -I/usr/include/SDL -o $@ $< -L/usr/lib -lSDL

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值