sdl学习心的(有错误请指出)

本文记录了使用SDL库的学习心得,包括初始化SDL库的不同子系统,如视频、音频、定时器等;介绍了导入PNG图片、设置颜色键及转换显示格式的方法;还提及加载图片的不同函数,以及使用SDL_rect变量时遇到的问题。
  记录一些学习心得
  1 when you use SDL lib at first,you must initialize it.example code:
      if(SDL_Init(SDL_INIT_VIDEO)<0){
                    fprintf(stderr,"don't error init sdl:%s/n",SDL_GetError());
                    exit(1);
              }     
         atexit(SDL_Quit);
       SDL_INIT_VIDEO  initializes the video subsystem
       SDL_INIT_AUDIO  initializes the audio subsystem
       SDL_INIT_TIMER  initializes the time   subsystem
       SDL_INIT_JOYSTICK  initializes the joystick subsystem  joystick:操作杆
       SDL_INIT_EVERYTHING initializes all of above
   2
       SDL_Surface *tmp;
       tmp=IMG_Load("image/gameover.png");  //导入一张PNG图片
       SDL_SetColorKey(tmp,SDL_SRCCOLORKEY,SDL_MapRGB(tmp->format,255,0,255)); //将游戏图片中RGB为255,0,255的颜色变为transparent pixel.
       tmp=SDL_DisplayFormat(tmp); //convert a surface to the display format
  
    3   load a picture,you can use IMG_Load function to load a picture for png format. code like:
        Surface *backgroud;        // declares a Surface variable backgroud;
        background=IMG_Load("image/background.png");  //load a png picture
 SDL_SetColorKey(ge->background,SDL_SRCCOLORKEY,SDL_MapRGB(ge->background->format,255,0,255));
        background=SDL_DisplayFormat(ge->background);
        or uses  SDL_LoadBMP function
         image = SDL_LoadBMP(file);
       
if ( image == NULL ) {
           
fprintf(stderr, "无法加载 %s: %s/n", file, SDL_GetError());
           
return;
             
}
    4 about SDL_rect.
      you can declare a SDL_rect variable,but don't declare a SDL_rect pointer,i don't know why,who can tell me why to do. when i do like do this
                            SDL_rect *dest;
                            dest->x=100;     // complie code,run, a error at the line.
 
       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值