init
This commit is contained in:
commit
a8df5c16fd
2 changed files with 100 additions and 0 deletions
18
Makefile
Normal file
18
Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
CC=gcc
|
||||
CFLAGS=-O1 -DDEBUG -g -ggdb -std=c23
|
||||
LIBS=`pkg-config sdl3 --cflags --libs`
|
||||
|
||||
OBJ = main.o
|
||||
|
||||
all: mobiground
|
||||
|
||||
%.o: %.c # Add all .o and .c files to compiler
|
||||
$(CC) -c -o $@ $< $(CFLAGS) # compile, generate, all output, prerequisite implicit rule, compile flags.
|
||||
|
||||
mobiground: $(OBJ)
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -f *.o mobiground
|
82
main.c
Normal file
82
main.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
#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");
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, 0);
|
||||
if (!renderer)
|
||||
{
|
||||
panic("SDL_CreateRenderer");
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 64, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
while (!loopShouldStop)
|
||||
{
|
||||
SDL_Event e;
|
||||
SDL_zero(e);
|
||||
while (SDL_PollEvent(&e))
|
||||
{
|
||||
switch (e.type)
|
||||
{
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
switch (e.key.mod)
|
||||
{
|
||||
case SDL_KMOD_LCTRL:
|
||||
switch (e.key.key)
|
||||
{
|
||||
case SDLK_Q:
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Hello OOPS!", "OOPS!", window);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_EVENT_QUIT:
|
||||
loopShouldStop = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in a new issue