static SDL_Texture *texture = 0;
///更新界面
void ren(SDL_Renderer *renderer) {
/* fill background in with black */
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
/* update screen */
SDL_RenderPresent(renderer);
}
///初始化纹理
void initializeText(SDL_Renderer *renderer) {
SDL_Surface *bmp_surface;
/* load the bmp */
bmp_surface = SDL_LoadBMP("space.bmp");
if (bmp_surface == NULL) {
fatalError("could not load bmp");
}
SDL_DrawLineB(bmp_surface, 0, 0, 200, 350, 0x80808);
texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
if (texture == 0) {
fatalError("could not create texture");
}
// SDL_SetColorKey(bmp_surface, 1,
// SDL_MapRGB(bmp_surface->format, 0, 0, 255));
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
// /* free up allocated memory */
SDL_FreeSurface(bmp_surface);
}
int main(int argc, char *argv[]) {
SDL_Window *window;
SDL_Renderer *render;
/* 初始化 SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fatalError("Could not initialize SDL");
}
/* 创建window */
window = SDL_CreateWindow("加载背景图", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
/* 设置渲染器 */
render = SDL_CreateRenderer(window, -1, 0);
initializeText(render);
int done = 0;
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
}
ren(render);
SDL_Delay(1000);
}
/* cleanup */
SDL_DestroyTexture(texture);
/* shutdown SDL */
SDL_Quit();
return 0;
}