Compare commits
No commits in common. "51d85c011b718af9fb465e650a94a866769443a2" and "8ec5f46e610a6b9483fca08a8d4420d176c8e9cb" have entirely different histories.
51d85c011b
...
8ec5f46e61
5 changed files with 7 additions and 8061 deletions
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
CFLAGS := $(CFLAGS) `pkg-config --cflags --libs sdl3`
|
CFLAGS := $(CFLAGS) `pkg-config --cflags --libs sdl3`
|
||||||
LDFLAGS := $(LDFLAGS) -lm
|
LDFLAGS := $(LDFLAGS)
|
||||||
|
|
||||||
all: slutpet
|
all: slutpet
|
||||||
|
|
||||||
|
|
11
dat.h
11
dat.h
|
@ -1,16 +1,5 @@
|
||||||
typedef struct Image Image;
|
|
||||||
struct Image {
|
|
||||||
int w;
|
|
||||||
int h;
|
|
||||||
int bpp;
|
|
||||||
unsigned char *data;
|
|
||||||
SDL_Texture *tex;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct State State;
|
typedef struct State State;
|
||||||
struct State {
|
struct State {
|
||||||
SDL_Window *win;
|
SDL_Window *win;
|
||||||
SDL_Renderer *ren;
|
SDL_Renderer *ren;
|
||||||
|
|
||||||
Image *test;
|
|
||||||
};
|
};
|
||||||
|
|
4
readme
4
readme
|
@ -1,5 +1 @@
|
||||||
horny desktop pet thing.
|
horny desktop pet thing.
|
||||||
|
|
||||||
i think it's probably best to use some sort of extension language.
|
|
||||||
i want people to be able to create their own pets without having to
|
|
||||||
figure out how to recompile.
|
|
||||||
|
|
59
slutpet.c
59
slutpet.c
|
@ -1,8 +1,6 @@
|
||||||
#define SDL_MAIN_USE_CALLBACKS
|
#define SDL_MAIN_USE_CALLBACKS
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
#include "stb_image.h"
|
|
||||||
|
|
||||||
#include "dat.h"
|
#include "dat.h"
|
||||||
|
|
||||||
|
@ -13,18 +11,10 @@ SDL_AppQuit(void *as, SDL_AppResult res)
|
||||||
|
|
||||||
st = as;
|
st = as;
|
||||||
if (st) {
|
if (st) {
|
||||||
if (st->test) {
|
SDL_Log("destroy renderer...");
|
||||||
if (st->test->tex) {
|
SDL_DestroyRenderer(st->ren);
|
||||||
SDL_Log("free test texture...");
|
SDL_Log("destroy window...");
|
||||||
SDL_DestroyTexture(st->test->tex);
|
SDL_DestroyWindow(st->win);
|
||||||
}
|
|
||||||
if (st->test->data) {
|
|
||||||
SDL_Log("free test img data...");
|
|
||||||
SDL_free(st->test->data);
|
|
||||||
}
|
|
||||||
SDL_Log("free test img...");
|
|
||||||
SDL_free(st->test);
|
|
||||||
}
|
|
||||||
SDL_Log("free state...");
|
SDL_Log("free state...");
|
||||||
SDL_free(st);
|
SDL_free(st);
|
||||||
}
|
}
|
||||||
|
@ -49,13 +39,6 @@ SDL_AppEvent(void *as, SDL_Event *ev)
|
||||||
SDL_AppResult
|
SDL_AppResult
|
||||||
SDL_AppIterate(void *as)
|
SDL_AppIterate(void *as)
|
||||||
{
|
{
|
||||||
State *st = as;
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(st->ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
|
|
||||||
SDL_RenderClear(st->ren);
|
|
||||||
|
|
||||||
SDL_RenderTexture(st->ren, st->test->tex, NULL, NULL);
|
|
||||||
SDL_RenderPresent(st->ren);
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +46,6 @@ SDL_AppResult
|
||||||
SDL_AppInit(void **as, int argc, char **argv)
|
SDL_AppInit(void **as, int argc, char **argv)
|
||||||
{
|
{
|
||||||
State *st;
|
State *st;
|
||||||
SDL_Surface *sur;
|
|
||||||
|
|
||||||
SDL_Log("init sdl...");
|
SDL_Log("init sdl...");
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
|
@ -90,39 +72,6 @@ SDL_AppInit(void **as, int argc, char **argv)
|
||||||
return SDL_APP_FAILURE;
|
return SDL_APP_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Log("create test image...");
|
|
||||||
st->test = SDL_calloc(1, sizeof(Image));
|
|
||||||
if (!st->test) {
|
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"mem alloc fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
st->test->data = stbi_load("test.png", &st->test->w, &st->test->h,
|
|
||||||
&st->test->bpp, 4);
|
|
||||||
if (!st->test->data) {
|
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"mem alloc fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
sur = SDL_CreateSurfaceFrom(st->test->w, st->test->h,
|
|
||||||
SDL_PIXELFORMAT_RGBA32, st->test->data,
|
|
||||||
st->test->w * 4);
|
|
||||||
if (!sur) {
|
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"surface creation fail: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
st->test->tex = SDL_CreateTextureFromSurface(st->ren, sur);
|
|
||||||
if (!st->test->tex) {
|
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"surface creation fail: %s", SDL_GetError());
|
|
||||||
SDL_DestroySurface(sur);
|
|
||||||
return SDL_APP_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Log("it work");
|
SDL_Log("it work");
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
7988
stb_image.h
7988
stb_image.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue