make window test
much of this is based on cross-referencing from the sdl3 snake demo: https://examples.libsdl.org/SDL3/demo/01-snake/ i need to work out an elegant system for logging. probably involving macro wonk.
This commit is contained in:
parent
10f98381cc
commit
b320df0121
3 changed files with 64 additions and 8 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
slutpet
|
5
dat.h
Normal file
5
dat.h
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
typedef struct State State;
|
||||||
|
struct State {
|
||||||
|
SDL_Window *win;
|
||||||
|
SDL_Renderer *ren;
|
||||||
|
};
|
64
slutpet.c
64
slutpet.c
|
@ -1,27 +1,77 @@
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#define SDL_MAIN_USE_CALLBACKS
|
#define SDL_MAIN_USE_CALLBACKS
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
|
|
||||||
|
#include "dat.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
SDL_AppQuit(void *appstate, SDL_AppResult result)
|
SDL_AppQuit(void *as, SDL_AppResult res)
|
||||||
{
|
{
|
||||||
|
State *st;
|
||||||
|
|
||||||
|
st = as;
|
||||||
|
if (st) {
|
||||||
|
SDL_Log("destroy renderer...");
|
||||||
|
SDL_DestroyRenderer(st->ren);
|
||||||
|
SDL_Log("destroy window...");
|
||||||
|
SDL_DestroyWindow(st->win);
|
||||||
|
SDL_Log("free state...");
|
||||||
|
SDL_free(st);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("bye!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult
|
SDL_AppResult
|
||||||
SDL_AppEvent(void *appstate, SDL_Event *event)
|
SDL_AppEvent(void *as, SDL_Event *ev)
|
||||||
{
|
{
|
||||||
|
switch (ev->type) {
|
||||||
|
case SDL_EVENT_QUIT:
|
||||||
|
SDL_Log("quit requested");
|
||||||
return SDL_APP_SUCCESS;
|
return SDL_APP_SUCCESS;
|
||||||
|
break; /* unreachable; here for visual symmetry */
|
||||||
|
}
|
||||||
|
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult
|
SDL_AppResult
|
||||||
SDL_AppIterate(void *appstate)
|
SDL_AppIterate(void *as)
|
||||||
{
|
{
|
||||||
return SDL_APP_SUCCESS;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult
|
SDL_AppResult
|
||||||
SDL_AppInit(void **appstate, int argc, char **argv)
|
SDL_AppInit(void **as, int argc, char **argv)
|
||||||
{
|
{
|
||||||
return SDL_APP_SUCCESS;
|
State *st;
|
||||||
|
|
||||||
|
SDL_Log("init sdl...");
|
||||||
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
|
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"sdl init fail: %s", SDL_GetError());
|
||||||
|
return SDL_APP_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("alloc state...");
|
||||||
|
st = SDL_calloc(1, sizeof(State));
|
||||||
|
if (!st) {
|
||||||
|
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"mem alloc fail: %s", SDL_GetError());
|
||||||
|
return SDL_APP_FAILURE;
|
||||||
|
}
|
||||||
|
*as = st;
|
||||||
|
|
||||||
|
SDL_Log("create win+render...");
|
||||||
|
if (!SDL_CreateWindowAndRenderer("slutpet", 320, 240,
|
||||||
|
SDL_WINDOW_TRANSPARENT | SDL_WINDOW_BORDERLESS,
|
||||||
|
&st->win, &st->ren)) {
|
||||||
|
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"win creation fail: %s", SDL_GetError());
|
||||||
|
return SDL_APP_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Log("it work");
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue