SDL window open
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
/build/
|
||||||
|
/wschod
|
||||||
|
/perf.data*
|
||||||
|
/massif.out*
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# To launch with debug messages: G_MESSAGES_DEBUG=all ./librefront
|
||||||
|
|
||||||
|
SRC := $(shell find src -name '*.c')
|
||||||
|
OBJ := $(patsubst src/%.c, build/%.o, $(SRC))
|
||||||
|
DEP := $(OBJ:.o=.d)
|
||||||
|
|
||||||
|
CC := gcc
|
||||||
|
LD := gcc
|
||||||
|
STD := gnu23
|
||||||
|
RM := rm -f
|
||||||
|
|
||||||
|
DEBUG ?= 1
|
||||||
|
|
||||||
|
CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP `pkg-config --cflags sdl3 sdl3-image glib-2.0`
|
||||||
|
LDFLAGS := -std=$(STD) -lm `pkg-config --libs sdl3 sdl3-image glib-2.0`
|
||||||
|
|
||||||
|
TARGET := librefront
|
||||||
|
|
||||||
|
ifeq ($(DEBUG),1)
|
||||||
|
CFLAGS += -g -DDEBUG
|
||||||
|
LDFLAGS += -g
|
||||||
|
else
|
||||||
|
CFLAGS += -O2 -DNDEBUG
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(OBJ)
|
||||||
|
$(LD) $^ -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
build/%.o: src/%.c
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -r build/ $(TARGET) $(OBJ) $(DEP) perf.data* massif.out*
|
||||||
|
|
||||||
|
-include $(DEP)
|
||||||
@@ -4,7 +4,7 @@ Fast, multithreaded, multicore, GPU, CUDA, raytracing, NVIDIA game
|
|||||||
|
|
||||||
# TODOs
|
# TODOs
|
||||||
|
|
||||||
- [ ] Basic SDL window open
|
- [X] Basic SDL window open
|
||||||
- [ ] Map structure programmed
|
- [ ] Map structure programmed
|
||||||
- [ ] Loading a map from a file
|
- [ ] Loading a map from a file
|
||||||
- [ ] Displaying a map on the screen
|
- [ ] Displaying a map on the screen
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
let
|
||||||
|
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-25.05";
|
||||||
|
pkgs = import nixpkgs { config = {}; overlays = []; };
|
||||||
|
in
|
||||||
|
pkgs.mkShellNoCC {
|
||||||
|
packages = with pkgs; [
|
||||||
|
sdl3
|
||||||
|
sdl3-image
|
||||||
|
glib
|
||||||
|
|
||||||
|
gcc
|
||||||
|
pkg-config
|
||||||
|
cloc
|
||||||
|
valgrind
|
||||||
|
gdb
|
||||||
|
cpulimit
|
||||||
|
linuxKernel.packages.linux_6_12.perf
|
||||||
|
];
|
||||||
|
}
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
#define SDL_MAIN_USE_CALLBACKS 1
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <SDL3/SDL_main.h>
|
||||||
|
#include <glib-2.0/glib.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
SDL_Window *sdl_window;
|
||||||
|
SDL_Renderer *sdl_renderer;
|
||||||
|
|
||||||
|
SDL_AppResult
|
||||||
|
SDL_AppInit (void **appstate, int argc, char **argv)
|
||||||
|
{
|
||||||
|
UNUSED (appstate, argc, argv);
|
||||||
|
|
||||||
|
setenv ("GIO_USE_VFS", "local", 1);
|
||||||
|
setenv ("GSETTINGS_BACKEND", "memory", 1);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
setenv ("G_MESSAGES_DEBUG", "all", 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_SetAppMetadata ("LibreFront", "0.1",
|
||||||
|
"https://git.cfpi-fpsi.eu:8443/chopin-interactive/librefront");
|
||||||
|
|
||||||
|
if (!SDL_Init (SDL_INIT_VIDEO))
|
||||||
|
{
|
||||||
|
g_error ("Couldn't initialize SDL: %s", SDL_GetError ());
|
||||||
|
}
|
||||||
|
|
||||||
|
sdl_window = SDL_CreateWindow ("LibreFront", 800, 600, SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
|
if (!sdl_window)
|
||||||
|
{
|
||||||
|
g_error ("Couldn't create window: %s", SDL_GetError ());
|
||||||
|
}
|
||||||
|
|
||||||
|
sdl_renderer = SDL_CreateRenderer (sdl_window, NULL);
|
||||||
|
|
||||||
|
if (!sdl_renderer)
|
||||||
|
{
|
||||||
|
g_error ("Couldn't create renderer: %s", SDL_GetError ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_AppResult
|
||||||
|
SDL_AppEvent (void *appstate, SDL_Event *event)
|
||||||
|
{
|
||||||
|
UNUSED (appstate);
|
||||||
|
|
||||||
|
if (event->type == SDL_EVENT_QUIT)
|
||||||
|
{
|
||||||
|
return SDL_APP_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_AppResult
|
||||||
|
SDL_AppIterate (void *appstate)
|
||||||
|
{
|
||||||
|
UNUSED (appstate);
|
||||||
|
|
||||||
|
SDL_RenderClear (sdl_renderer);
|
||||||
|
SDL_RenderPresent (sdl_renderer);
|
||||||
|
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_AppQuit (void *appstate, SDL_AppResult result)
|
||||||
|
{
|
||||||
|
UNUSED (appstate, result);
|
||||||
|
|
||||||
|
SDL_DestroyRenderer (sdl_renderer);
|
||||||
|
SDL_DestroyWindow (sdl_window);
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define UNUSED(...) (UNUSED_1 (__VA_ARGS__, 0))
|
||||||
|
#define UNUSED_1(arg, ...) (void) arg, UNUSED_2 (__VA_ARGS__, 0)
|
||||||
|
#define UNUSED_2(arg, ...) (void) arg, UNUSED_3 (__VA_ARGS__, 0)
|
||||||
|
#define UNUSED_3(arg, ...) (void) arg
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
GLib log levels:
|
||||||
|
|
||||||
|
g_debug
|
||||||
|
g_info
|
||||||
|
g_message
|
||||||
|
g_warning
|
||||||
|
g_critical
|
||||||
|
g_error
|
||||||
|
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user