#include <SDL3/SDL.h>
#if _WIN32 // PLATFORM_WINDOWS
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow) {
if (!SDL_Init(SDL_INIT_VIDEO)) {
// SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError());
MessageBoxA(0, SDL_GetError(), "Couldn't initialize SDL", MB_OK);
return 3;
}
SDL_Window* window;
SDL_Renderer* renderer;
if (!SDL_CreateWindowAndRenderer("SDL3 Draw a filled rectangle that grows and shrinks constantly", WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE, &window, &renderer)) {
// SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s", SDL_GetError());
MessageBoxA(0, SDL_GetError(), "Couldn't create window and renderer", MB_OK);
return 3;
}
SDL_Event event;
while (1) {
SDL_PollEvent(&event);
if (event.type == SDL_EVENT_QUIT) {
break;
}
SDL_FRect rect;
const Uint64 now = SDL_GetTicks();
// a rectangle that grows and shrinks constantly
const float direction = ((now % 2000) >= 1000) ? 1.0f : -1.0f;
const float scale = ((float)(((int)(now % 1000)) - 500) / 500.0f) * direction;
// clear the windows with black color
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer); // start with a blank canvas
// draw a single filled rectangle
rect.x = 200;
rect.y = 100;
rect.w = 200 + (200 * scale);
rect.h = 100 + (100 * scale);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); // green
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer); // put it all on the screen
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
#endif