Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1390679
  • 博文数量: 430
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4388
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-24 18:04
文章存档

2013年(1)

2008年(2)

2007年(14)

2006年(413)

分类: LINUX

2006-05-26 10:19:18

  • SDL只提供了SDL_LoadBMP(),但在SDL的示例文档中有一个用于加载图片的函数库。

    SDL_BlitSurface()将图片blit进图形帧缓冲,从而显示图片。SDL_BlitSurface()自动对blit矩形进行裁边,blit矩形在调用SDL_UpdateRects()时被用作更新屏幕变化了的部分。

提示 #1:
如果你需要多次显示某个图片,你可以调用 SDL_DisplayFormat()将图片转换成屏幕的格式,从而提高blit的速度。

提示 #2:
许多sprite的图片要求透明背景,你可以用SDL_SetColorKey()来设置透明色,从而实现透明效果的blit(也就是带colorkey的blit)。 

例程:
void ShowBMP(char *file, SDL_Surface *screen, int x, int y)
{
    SDL_Surface *image;
    SDL_Rect dest;

    /* 将BMP文件加载到一个surface*/
    image = SDL_LoadBMP(file);
    if ( image == NULL ) {
        fprintf(stderr, "无法加载 %s: %s\n", file, SDL_GetError());
        return;
    }

    /* Blit到屏幕surface。onto the screen surface.
       这时不能锁住surface。
     */
    dest.x = x;
    dest.y = y;
    dest.w = image->w;
    dest.h = image->h;
    SDL_BlitSurface(image, NULL, screen, &dest);

    /* 刷新屏幕的变化部分 */
    SDL_UpdateRects(screen, 1, &dest);
}
阅读(754) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~