PHPz2017-04-17 15:53:27
I have been struggling for a long time, here is the correct posture, and I am still studying drawing lines. Please give me some advice and criticism from a master who has used SDL. Don’t pity me for being a delicate flower
static SDL_Texture *texture = 0;
///更新界面
void render(SDL_Renderer *renderer) {
/* fill background in with black */
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
/* update screen */
SDL_RenderPresent(renderer);
}
///初始化纹理
void initializeTexture(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");
}
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);
}
void loadBMP(void) {
SDL_Window *window;
SDL_Renderer *renderer;
/* 初始化 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);
/* 设置渲染器 */
renderer = SDL_CreateRenderer(window, -1, 0);
initializeTexture(renderer);
int done = 0;
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
}
render(renderer);
SDL_Delay(1000);
}
/* cleanup */
SDL_DestroyTexture(texture);
/* shutdown SDL */
SDL_Quit();
}
怪我咯2017-04-17 15:53:27
Excuse me, what did you use to package the SDL static library? According to the official documentation, the packaging will prompt that gcc cannot be used