extract image loading
This commit is contained in:
parent
9ece614c73
commit
3840fb0321
5 changed files with 91 additions and 40 deletions
43
slutpet.c
43
slutpet.c
|
@ -1,11 +1,10 @@
|
|||
#define SDL_MAIN_USE_CALLBACKS
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include "stb_image.h"
|
||||
|
||||
#include "fns.h"
|
||||
#include "dat.h"
|
||||
#include "fns.h"
|
||||
|
||||
void
|
||||
SDL_AppQuit(void *as, SDL_AppResult res)
|
||||
|
@ -14,18 +13,7 @@ SDL_AppQuit(void *as, SDL_AppResult res)
|
|||
|
||||
st = as;
|
||||
if (st) {
|
||||
if (st->test) {
|
||||
if (st->test->tex) {
|
||||
babble("free test texture...");
|
||||
SDL_DestroyTexture(st->test->tex);
|
||||
}
|
||||
if (st->test->data) {
|
||||
babble("free test img data...");
|
||||
SDL_free(st->test->data);
|
||||
}
|
||||
babble("free test img...");
|
||||
SDL_free(st->test);
|
||||
}
|
||||
free_image(st->test);
|
||||
babble("free state...");
|
||||
SDL_free(st);
|
||||
}
|
||||
|
@ -71,7 +59,6 @@ SDL_AppResult
|
|||
SDL_AppInit(void **as, int argc, char **argv)
|
||||
{
|
||||
State *st;
|
||||
SDL_Surface *sur;
|
||||
|
||||
babble("init sdl...");
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||
|
@ -100,31 +87,9 @@ SDL_AppInit(void **as, int argc, char **argv)
|
|||
}
|
||||
|
||||
babble("create test image...");
|
||||
st->test = SDL_calloc(1, sizeof(Image));
|
||||
st->test = load_image(st->ren, "test.png");
|
||||
if (!st->test) {
|
||||
fuck("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) {
|
||||
fuck("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) {
|
||||
fuck("surface creation fail: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
st->test->tex = SDL_CreateTextureFromSurface(st->ren, sur);
|
||||
if (!st->test->tex) {
|
||||
fuck("surface creation fail: %s", SDL_GetError());
|
||||
SDL_DestroySurface(sur);
|
||||
fuck("img creation fail: %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue