说明
- 基于 SDL2.0 和 vs2017 开发 。
- 有多种方法可以显示BMP图片,本文只是一种。
SDL显示BMP流程
- 获取窗口。
- 获取窗口对应surface。
- 获取bmp对应surface。
- 将bmp的surface画在窗口的surface上。
- 更新窗口。
- 显示窗口。
示例代码
#include "stdafx.h"
#include "SDL.h"
#include "SDL_version.h"
#define IMG_PATH "D:\\11.bmp"
#undef main
int main(int argc,char **argv)
{
printf("\n");
printf("Hello SDL\n");
SDL_version compiled;
SDL_VERSION(&compiled);
printf("SDL version %d.%d.%d ...\n",compiled.major, compiled.minor, compiled.patch);
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return 1;
SDL_Window *window;
SDL_Surface *surface;
SDL_Surface *surfaceBMP;
window = SDL_CreateWindow("SDL_bmp_title",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,800,600,0);
surface = SDL_GetWindowSurface(window);
surfaceBMP = SDL_LoadBMP(IMG_PATH);
SDL_BlitSurface(surfaceBMP,NULL,surface,NULL);
SDL_UpdateWindowSurface(window);
SDL_ShowWindow(window);
SDL_Delay(5000);
SDL_FreeSurface(surfaceBMP);
SDL_FreeSurface(surface);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}