/*
- 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_Window *window;
SDL_Renderer *renderer;
+SDL_Surface *surface;
int done;
void
{
SDL_Event e;
while (SDL_PollEvent(&e)) {
- if (e.type == SDL_QUIT || e.key.keysym.sym == SDLK_f) {
+
+ /* Re-create when window has been resized */
+ if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
+
+ SDL_DestroyRenderer(renderer);
+
+ surface = SDL_GetWindowSurface(window);
+ renderer = SDL_CreateSoftwareRenderer(surface);
+ /* Clear the rendering surface with the specified color */
+ SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
+ SDL_RenderClear(renderer);
+ }
+
+ if (e.type == SDL_QUIT) {
done = 1;
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
SDL_UpdateWindowSurface(window);
}
int
-SDL_main(int argc, char *argv[])
+main(int argc, char *argv[])
{
- SDL_Surface *surface;
-
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL */
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
return 1;
}
/* Create window and renderer for given surface */
- window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 720, 1280, SDL_WINDOW_SHOWN);
+ window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
if(!window)
{
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
return 1;
}
- SDL_SetWindowTitle(window, "chess board");
- const char* windowtitle = SDL_GetWindowTitle(window);
- if(SDL_strcmp(windowtitle, "chess board") != 0)
- {
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Set Window title fail : %s\n",SDL_GetError());
- }
- if(SDL_SetWindowBrightness(window, 0.5f) == -1)
- {
- SDLTest_Log(SDL_LOG_CATEGORY_APPLICATION, "Set Window Brightness is not supported ");
- }
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
if(!renderer)
{
- SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
return 1;
}