mobiground/main.c

65 lines
1.5 KiB
C
Raw Normal View History

2024-11-12 17:08:03 +05:00
#include <stdio.h> // for fprintf()
#include <stdlib.h> // for exit()
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h> // only include this one in the source file with main()!
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
static void panic ( const char *text ) __attribute__((noreturn));
void panic ( const char *text )
{
fprintf(stderr, "ERROR: %s. %s\n", text, SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
exit(1);
}
int main( int argc, char* argv[] )
{
const int WIDTH = 640;
const int HEIGHT = 480;
bool loopShouldStop = false;
if (!SDL_Init(SDL_INIT_VIDEO))
{
panic("SDL_Init failed");
}
window = SDL_CreateWindow("Hello SDL", WIDTH, HEIGHT, 0);
if (!window)
{
panic("SDL_CreateWindow");
2024-11-12 17:08:03 +05:00
}
renderer = SDL_CreateRenderer(window, "opengl");
2024-11-12 17:08:03 +05:00
if (!renderer)
{
panic("SDL_CreateRenderer");
2024-11-12 17:08:03 +05:00
}
int orange = 0;
2024-11-12 17:08:03 +05:00
while (!loopShouldStop)
{
SDL_Event e;
SDL_zero(e);
while (SDL_PollEvent(&e))
{
if (e.type == SDL_EVENT_KEY_DOWN && e.key.mod == SDL_KMOD_LCTRL && e.key.key == SDLK_Q)
loopShouldStop = true;
2024-11-12 17:08:03 +05:00
}
SDL_SetRenderDrawColor(renderer, 0, orange, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
orange = (orange + 1) % 256;
2024-11-12 17:08:03 +05:00
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
exit(0);
}