/*
- Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
SDL_RenderPresent(renderer);
}
-int SDL_main(int argc,char** argv)
+int main(int argc,char** argv)
{
Uint8 num_pictures;
LoadedPicture* pictures;
SDL_Renderer *renderer;
SDL_Color black = {0,0,0,0xff};
SDL_Event event;
- int event_pending = 0;
int should_exit = 0;
unsigned int current_picture;
int button_down;
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if(argc < 2) {
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument.");
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument.");
exit(-1);
}
if(SDL_VideoInit(NULL) == -1) {
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video.");
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video.");
exit(-2);
}
num_pictures = argc - 1;
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture)*num_pictures);
+ if (!pictures) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate memory.");
+ exit(1);
+ }
for(i=0;i<num_pictures;i++)
pictures[i].surface = NULL;
for(i=0;i<num_pictures;i++) {
pictures[i].surface = SDL_LoadBMP(argv[i+1]);
pictures[i].name = argv[i+1];
if(pictures[i].surface == NULL) {
- j = 0;
for(j=0;j<num_pictures;j++)
SDL_FreeSurface(pictures[j].surface);
SDL_free(pictures);
SDL_VideoQuit();
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file: %s", argv[i+1]);
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file: %s", argv[i+1]);
exit(-3);
}
SDL_FreeSurface(pictures[i].surface);
SDL_free(pictures);
SDL_VideoQuit();
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape.");
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape.");
exit(-4);
}
renderer = SDL_CreateRenderer(window,-1,0);
SDL_FreeSurface(pictures[i].surface);
SDL_free(pictures);
SDL_VideoQuit();
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create rendering context for SDL_Shape window.");
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create rendering context for SDL_Shape window.");
exit(-5);
}
for(i=0;i<num_pictures;i++) {
pictures[i].texture = SDL_CreateTextureFromSurface(renderer,pictures[i].surface);
if(pictures[i].texture == NULL) {
- j = 0;
- for(j=0;j<num_pictures;i++)
+ for(i=0;i<num_pictures;i++)
if(pictures[i].texture != NULL)
SDL_DestroyTexture(pictures[i].texture);
for(i=0;i<num_pictures;i++)
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_VideoQuit();
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create texture for SDL_shape.");
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create texture for SDL_shape.");
exit(-6);
}
}
- event_pending = 0;
should_exit = 0;
- event_pending = SDL_PollEvent(&event);
current_picture = 0;
button_down = 0;
texture_dimensions.h = 0;
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
while(should_exit == 0) {
- event_pending = SDL_PollEvent(&event);
- if(event_pending == 1) {
+ while (SDL_PollEvent(&event)) {
if(event.type == SDL_KEYDOWN) {
button_down = 1;
if(event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == 0) {
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
}
- if(event.type == SDL_QUIT)
+ if (event.type == SDL_QUIT) {
should_exit = 1;
- event_pending = 0;
+ break;
+ }
}
render(renderer,pictures[current_picture].texture,texture_dimensions);
SDL_Delay(10);