Browse Source

Update sprite loading code

The sprites are now loaded using a utility function in IZ_video.
feature/data-structs
TheoryOfNekomata 2 years ago
parent
commit
8fddede051
66 changed files with 188 additions and 22 deletions
  1. +8
    -0
      CMakeLists.txt
  2. +0
    -0
      assets_src/gfx/props.cdr
  3. +0
    -0
      assets_src/gfx/weapons-rigged.cdr
  4. +0
    -0
      assets_src/gfx/weapons-src.cdr
  5. +0
    -0
      assets_src/sfx/env/car_suspension.wav
  6. +0
    -0
      assets_src/sfx/env/shake_spring.wav
  7. +0
    -0
      assets_src/sfx/weapons/guns/hg-dblberettam9/0_deploy_var0.wav
  8. +0
    -0
      assets_src/sfx/weapons/guns/hg-dblberettam9/1_unload_var0.wav
  9. +0
    -0
      assets_src/sfx/weapons/guns/hg-dblberettam9/6_clip_out_start_var0.wav
  10. +0
    -0
      assets_src/sfx/weapons/guns/hg-dblberettam9/8_clip_in_start_var0.wav
  11. +0
    -0
      assets_src/sfx/weapons/guns/hg-dblberettam9/9_clip_in_end_var0.wav
  12. +0
    -0
      assets_src/sfx/weapons/guns/hg-dblberettam9/c_ready_var0.wav
  13. +0
    -0
      assets_src/sfx/weapons/guns/rifle-coltm4a1/0_deploy_var0.wav
  14. +0
    -0
      assets_src/sfx/weapons/guns/rifle-coltm4a1/1_unload_var0.wav
  15. +0
    -0
      assets_src/sfx/weapons/guns/rifle-coltm4a1/6_clip_out_start_var0.wav
  16. +0
    -0
      assets_src/sfx/weapons/guns/rifle-coltm4a1/8_clip_in_start_var0.wav
  17. +0
    -0
      assets_src/sfx/weapons/guns/rifle-coltm4a1/c_ready_var0.wav
  18. +0
    -0
      assets_src/sfx/weapons/guns/rifle-kalashak47/0_deploy_var0.wav
  19. +0
    -0
      assets_src/sfx/weapons/guns/rifle-kalashak47/1_unload_var0.wav
  20. +0
    -0
      assets_src/sfx/weapons/guns/rifle-kalashak47/6_clip_out_start_var0.wav
  21. +0
    -0
      assets_src/sfx/weapons/guns/rifle-kalashak47/8_clip_in_start_var0.wav
  22. +0
    -0
      assets_src/sfx/weapons/guns/rifle-kalashak47/c_ready_var0.wav
  23. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/3_pump_start_var0.wav
  24. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/4_pump_end_var0.wav
  25. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/TODO_1_unload_var0.wav
  26. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/a_shell_in_var0.wav
  27. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/a_shell_in_var1.wav
  28. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/a_shell_in_var2.wav
  29. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var0.wav
  30. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var1.wav
  31. +0
    -0
      assets_src/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var2.wav
  32. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5a3/0_deploy_var0.wav
  33. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5a3/1_unload_var0.wav
  34. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5a3/5_init_reload_var0.wav
  35. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5a3/6_clip_out_start_var0.wav
  36. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5a3/7_clip_in_start_var0.wav
  37. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5a3/c_ready_var0.wav
  38. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5k/0_deploy_var0.wav
  39. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5k/1_unload_var0.wav
  40. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5k/5_init_reload_var0.wav
  41. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5k/6_clip_out_start_var0.wav
  42. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5k/7_clip_in_start_var0.wav
  43. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp5k/c_ready_var0.wav
  44. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp7/1_unload_var0.wav
  45. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp7/6_clip_out_start_var0.wav
  46. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp7/7_clip_in_start_var0.wav
  47. +0
    -0
      assets_src/sfx/weapons/guns/smg-hkmp7/c_ready_var0.wav
  48. +0
    -0
      assets_src/sfx/weapons/shells/12gauge/var0.wav
  49. +0
    -0
      assets_src/sfx/weapons/shells/12gauge/var1.wav
  50. +0
    -0
      assets_src/sfx/weapons/shells/12gauge/var2.wav
  51. +0
    -0
      assets_src/sfx/weapons/shells/5-56/var0.wav
  52. +0
    -0
      assets_src/sfx/weapons/shells/5-56/var1.wav
  53. +0
    -0
      assets_src/sfx/weapons/shells/5-56/var2.wav
  54. +0
    -0
      assets_src/sfx/weapons/shells/7-62/var0.wav
  55. +0
    -0
      assets_src/sfx/weapons/shells/7-62/var1.wav
  56. +0
    -0
      assets_src/sfx/weapons/shells/7-62/var2.wav
  57. +0
    -0
      assets_src/sfx/weapons/shells/9mm/var0.wav
  58. +0
    -0
      assets_src/sfx/weapons/shells/9mm/var1.wav
  59. +0
    -0
      assets_src/sfx/weapons/shells/9mm/var2.wav
  60. +0
    -0
      assets_src/sfx/weapons/shells/hk40/var0.mp3
  61. +0
    -0
      assets_src/sfx/weapons/shells/hk40/var1.mp3
  62. +0
    -0
      assets_src/sfx/weapons/shells/hk40/var2.mp3
  63. +126
    -0
      src/packages/asset-inv/main.c
  64. +21
    -19
      src/packages/game/IZ_app_video.c
  65. +24
    -2
      src/packages/game/output/video/IZ_video.c
  66. +9
    -1
      src/packages/game/output/video/IZ_video.h

+ 8
- 0
CMakeLists.txt View File

@@ -221,6 +221,14 @@ add_executable(
src/packages/server/IZ_subsystem.h
)

add_executable(
asset-inv
dependencies/minIni/dev/minIni.h
dependencies/minIni/dev/minIni.c
src/packages/common/IZ_common.h
src/packages/asset-inv/main.c
)

target_link_libraries(
server
SDL2main


assets/gfx/props.cdr → assets_src/gfx/props.cdr View File


assets/gfx/weapons-rigged.cdr → assets_src/gfx/weapons-rigged.cdr View File


assets/gfx/weapons-src.cdr → assets_src/gfx/weapons-src.cdr View File


assets/sfx/env/car_suspension.wav → assets_src/sfx/env/car_suspension.wav View File


assets/sfx/env/shake_spring.wav → assets_src/sfx/env/shake_spring.wav View File


assets/sfx/weapons/guns/hg-dblberettam9/0_deploy_var0.wav → assets_src/sfx/weapons/guns/hg-dblberettam9/0_deploy_var0.wav View File


assets/sfx/weapons/guns/hg-dblberettam9/1_unload_var0.wav → assets_src/sfx/weapons/guns/hg-dblberettam9/1_unload_var0.wav View File


assets/sfx/weapons/guns/hg-dblberettam9/6_clip_out_start_var0.wav → assets_src/sfx/weapons/guns/hg-dblberettam9/6_clip_out_start_var0.wav View File


assets/sfx/weapons/guns/hg-dblberettam9/8_clip_in_start_var0.wav → assets_src/sfx/weapons/guns/hg-dblberettam9/8_clip_in_start_var0.wav View File


assets/sfx/weapons/guns/hg-dblberettam9/9_clip_in_end_var0.wav → assets_src/sfx/weapons/guns/hg-dblberettam9/9_clip_in_end_var0.wav View File


assets/sfx/weapons/guns/hg-dblberettam9/c_ready_var0.wav → assets_src/sfx/weapons/guns/hg-dblberettam9/c_ready_var0.wav View File


assets/sfx/weapons/guns/rifle-coltm4a1/0_deploy_var0.wav → assets_src/sfx/weapons/guns/rifle-coltm4a1/0_deploy_var0.wav View File


assets/sfx/weapons/guns/rifle-coltm4a1/1_unload_var0.wav → assets_src/sfx/weapons/guns/rifle-coltm4a1/1_unload_var0.wav View File


assets/sfx/weapons/guns/rifle-coltm4a1/6_clip_out_start_var0.wav → assets_src/sfx/weapons/guns/rifle-coltm4a1/6_clip_out_start_var0.wav View File


assets/sfx/weapons/guns/rifle-coltm4a1/8_clip_in_start_var0.wav → assets_src/sfx/weapons/guns/rifle-coltm4a1/8_clip_in_start_var0.wav View File


assets/sfx/weapons/guns/rifle-coltm4a1/c_ready_var0.wav → assets_src/sfx/weapons/guns/rifle-coltm4a1/c_ready_var0.wav View File


assets/sfx/weapons/guns/rifle-kalashak47/0_deploy_var0.wav → assets_src/sfx/weapons/guns/rifle-kalashak47/0_deploy_var0.wav View File


assets/sfx/weapons/guns/rifle-kalashak47/1_unload_var0.wav → assets_src/sfx/weapons/guns/rifle-kalashak47/1_unload_var0.wav View File


assets/sfx/weapons/guns/rifle-kalashak47/6_clip_out_start_var0.wav → assets_src/sfx/weapons/guns/rifle-kalashak47/6_clip_out_start_var0.wav View File


assets/sfx/weapons/guns/rifle-kalashak47/8_clip_in_start_var0.wav → assets_src/sfx/weapons/guns/rifle-kalashak47/8_clip_in_start_var0.wav View File


assets/sfx/weapons/guns/rifle-kalashak47/c_ready_var0.wav → assets_src/sfx/weapons/guns/rifle-kalashak47/c_ready_var0.wav View File


assets/sfx/weapons/guns/sg-ithacam37/3_pump_start_var0.wav → assets_src/sfx/weapons/guns/sg-ithacam37/3_pump_start_var0.wav View File


assets/sfx/weapons/guns/sg-ithacam37/4_pump_end_var0.wav → assets_src/sfx/weapons/guns/sg-ithacam37/4_pump_end_var0.wav View File


assets/sfx/weapons/guns/sg-ithacam37/TODO_1_unload_var0.wav → assets_src/sfx/weapons/guns/sg-ithacam37/TODO_1_unload_var0.wav View File


assets/sfx/weapons/guns/sg-ithacam37/a_shell_in_var0.wav → assets_src/sfx/weapons/guns/sg-ithacam37/a_shell_in_var0.wav View File


assets/sfx/weapons/guns/sg-ithacam37/a_shell_in_var1.wav → assets_src/sfx/weapons/guns/sg-ithacam37/a_shell_in_var1.wav View File


assets/sfx/weapons/guns/sg-ithacam37/a_shell_in_var2.wav → assets_src/sfx/weapons/guns/sg-ithacam37/a_shell_in_var2.wav View File


assets/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var0.wav → assets_src/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var0.wav View File


assets/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var1.wav → assets_src/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var1.wav View File


assets/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var2.wav → assets_src/sfx/weapons/guns/sg-ithacam37/b_shell_feed_var2.wav View File


assets/sfx/weapons/guns/smg-hkmp5a3/0_deploy_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5a3/0_deploy_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5a3/1_unload_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5a3/1_unload_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5a3/5_init_reload_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5a3/5_init_reload_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5a3/6_clip_out_start_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5a3/6_clip_out_start_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5a3/7_clip_in_start_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5a3/7_clip_in_start_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5a3/c_ready_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5a3/c_ready_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5k/0_deploy_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5k/0_deploy_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5k/1_unload_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5k/1_unload_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5k/5_init_reload_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5k/5_init_reload_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5k/6_clip_out_start_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5k/6_clip_out_start_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5k/7_clip_in_start_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5k/7_clip_in_start_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp5k/c_ready_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp5k/c_ready_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp7/1_unload_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp7/1_unload_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp7/6_clip_out_start_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp7/6_clip_out_start_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp7/7_clip_in_start_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp7/7_clip_in_start_var0.wav View File


assets/sfx/weapons/guns/smg-hkmp7/c_ready_var0.wav → assets_src/sfx/weapons/guns/smg-hkmp7/c_ready_var0.wav View File


assets/sfx/weapons/shells/12gauge/var0.wav → assets_src/sfx/weapons/shells/12gauge/var0.wav View File


assets/sfx/weapons/shells/12gauge/var1.wav → assets_src/sfx/weapons/shells/12gauge/var1.wav View File


assets/sfx/weapons/shells/12gauge/var2.wav → assets_src/sfx/weapons/shells/12gauge/var2.wav View File


assets/sfx/weapons/shells/5-56/var0.wav → assets_src/sfx/weapons/shells/5-56/var0.wav View File


assets/sfx/weapons/shells/5-56/var1.wav → assets_src/sfx/weapons/shells/5-56/var1.wav View File


assets/sfx/weapons/shells/5-56/var2.wav → assets_src/sfx/weapons/shells/5-56/var2.wav View File


assets/sfx/weapons/shells/7-62/var0.wav → assets_src/sfx/weapons/shells/7-62/var0.wav View File


assets/sfx/weapons/shells/7-62/var1.wav → assets_src/sfx/weapons/shells/7-62/var1.wav View File


assets/sfx/weapons/shells/7-62/var2.wav → assets_src/sfx/weapons/shells/7-62/var2.wav View File


assets/sfx/weapons/shells/9mm/var0.wav → assets_src/sfx/weapons/shells/9mm/var0.wav View File


assets/sfx/weapons/shells/9mm/var1.wav → assets_src/sfx/weapons/shells/9mm/var1.wav View File


assets/sfx/weapons/shells/9mm/var2.wav → assets_src/sfx/weapons/shells/9mm/var2.wav View File


assets/sfx/weapons/shells/hk40/var0.mp3 → assets_src/sfx/weapons/shells/hk40/var0.mp3 View File


assets/sfx/weapons/shells/hk40/var1.mp3 → assets_src/sfx/weapons/shells/hk40/var1.mp3 View File


assets/sfx/weapons/shells/hk40/var2.mp3 → assets_src/sfx/weapons/shells/hk40/var2.mp3 View File


+ 126
- 0
src/packages/asset-inv/main.c View File

@@ -0,0 +1,126 @@
#include <stdio.h>
#include "minIni.h"
#include "../common/IZ_common.h"

// #ifdef WIN64
#include <windows.h>
// #endif

i32 IZ_ReadAsset(const char* current_dir, const char* ini_filename) {
WIN32_FIND_DATA fd_file;
char current_path[2048];
sprintf(current_path, "%s\\*.*", current_dir);
HANDLE h_find = FindFirstFile(current_path, &fd_file);

if (h_find == INVALID_HANDLE_VALUE) {
return -1;
}

do {
if (strcmp(fd_file.cFileName, ".") == 0) {
continue;
}

if (strcmp(fd_file.cFileName, "..") == 0) {
continue;
}

sprintf(current_path, "%s\\%s", current_dir, fd_file.cFileName);

if (fd_file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
fprintf(stderr, "Invalid asset component: %s\n", current_path);
continue;
}

char final_current_dir[2048];
memcpy(final_current_dir, current_dir, 2048);

u16 i = 0;
char c = current_dir[i];
while (c != '\0') {
final_current_dir[i] = c == '\\' ? '/' : c;
i += 1;
c = current_dir[i];
}

ini_putl(final_current_dir, fd_file.cFileName, fd_file.nFileSizeLow, ini_filename);
} while(FindNextFile(h_find, &fd_file));

FindClose(h_find);

return 0;
}

i32 IZ_ReadAssetPack(const char* current_dir, const char* ini_filename) {
WIN32_FIND_DATA fd_file;
char current_path[2048];
sprintf(current_path, "%s\\*.*", current_dir);
HANDLE h_find = FindFirstFile(current_path, &fd_file);

if (h_find == INVALID_HANDLE_VALUE) {
return -1;
}

do {
if (strcmp(fd_file.cFileName, ".") == 0) {
continue;
}

if (strcmp(fd_file.cFileName, "..") == 0) {
continue;
}

sprintf(current_path, "%s\\%s", current_dir, fd_file.cFileName);

if (fd_file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
IZ_ReadAsset(current_path, ini_filename);
continue;
}

fprintf(stderr, "Invalid asset: %s\n", current_path);
} while(FindNextFile(h_find, &fd_file));

FindClose(h_find);

return 0;
}

i32 IZ_ReadAllAssetPacks(const char* current_dir, const char* ini_filename) {
ini_remove(ini_filename);

WIN32_FIND_DATA fd_file;
char current_path[2048];
sprintf(current_path, "%s\\*.*", current_dir);
HANDLE h_find = FindFirstFile(current_path, &fd_file);

if (h_find == INVALID_HANDLE_VALUE) {
return -1;
}

do {
if (strcmp(fd_file.cFileName, ".") == 0) {
continue;
}

if (strcmp(fd_file.cFileName, "..") == 0) {
continue;
}

sprintf(current_path, "%s\\%s", current_dir, fd_file.cFileName);

if (fd_file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
IZ_ReadAssetPack(current_path, ini_filename);
continue;
}

fprintf(stderr, "Invalid asset pack: %s\n", current_path);
} while(FindNextFile(h_find, &fd_file));

FindClose(h_find);

return 0;
}

i32 main(void) {
return IZ_ReadAllAssetPacks("assets", "assets.ini");
}

+ 21
- 19
src/packages/game/IZ_app_video.c View File

@@ -104,6 +104,8 @@ void IZ_VideoUpdateForDebugNet(IZ_VideoState* video_state, IZ_NetClientState* ne
}
}

static f32 degrees = 0;

void IZ_VideoUpdate(IZ_VideoState* video_state) {
struct IZ_App* app = video_state->user_data;
u64 ticks = IZ_AppGetTicks(app);
@@ -122,29 +124,29 @@ void IZ_VideoUpdate(IZ_VideoState* video_state) {
// TODO draw sprites
}

FILE* f = fopen("assets/gfx/beretta-test.svg", "r");
static const u16 sprite_length_bytes = 15316 + 1;
static const f32 sprite_size = 271.25f;
u8 sprite[sprite_length_bytes] = "";
fread(sprite, 1, sprite_length_bytes, f);
SDL_SetRenderDrawBlendMode(video_state->renderer, SDL_BLENDMODE_ADD);
SDL_Surface* test_surface = IMG_LoadSVG_RW(SDL_RWFromConstMem(sprite, sprite_length_bytes));
if (test_surface) {
SDL_Texture* test_texture = SDL_CreateTextureFromSurface(video_state->renderer, test_surface);
SDL_RenderCopyExF(video_state->renderer, test_texture, NULL, &(SDL_FRect) {
.x = 0,
.y = 0,
.w = sprite_size,
.h = sprite_size,
}, 180, &(SDL_FPoint) {
.x = sprite_size / 2,
.y = sprite_size / 2,
IZ_LoadedSprite loaded_sprite = {
.texture = NULL,
.original_width = 0,
.original_height = 0,
};
IZ_VideoLoadTexture(video_state, "assets/default/weapon-servant", "sprite.svg", &loaded_sprite);
if (loaded_sprite.texture) {
f32 draw_width = loaded_sprite.original_width / 2;
f32 draw_height = loaded_sprite.original_height / 2;
SDL_RenderCopyExF(video_state->renderer, loaded_sprite.texture, NULL, &(SDL_FRect) {
.x = 160,
.y = 120,
.w = draw_width,
.h = draw_height,
}, degrees++, &(SDL_FPoint) {
.x = draw_width / 2,
.y = draw_height / 2,
}, SDL_FLIP_NONE);
SDL_DestroyTexture(test_texture);

IZ_VideoTeardownTexture(&loaded_sprite);
// our goal is to render the svg files and apply custom transforms to some SVG groups if ever.
// TODO perhaps we can parse the SVG for easier transforms?
}
SDL_FreeSurface(test_surface);

IZ_VideoUpdateForDebugTicks(video_state, ticks);
IZ_VideoUpdateForDebugInput(video_state, input_state);


+ 24
- 2
src/packages/game/output/video/IZ_video.c View File

@@ -94,7 +94,29 @@ void IZ_VideoTeardown(IZ_VideoState* state) {
SDL_DestroyWindow(state->window);
}

void IZ_VideoLoadTexture(IZ_VideoState* state, const char* path, SDL_Texture** out) {
out = NULL;
void IZ_VideoLoadTexture(IZ_VideoState* state, const char* dir, const char* filename, IZ_LoadedSprite* out) {
char full_path[2048];
sprintf(full_path, "%s/%s", dir, filename);
FILE* f = fopen(full_path, "r");
u32 sprite_length_bytes = ini_getl(dir, filename, 0, "assets.ini");
u8* sprite = malloc(sprite_length_bytes + 1);
fread(sprite, 1, sprite_length_bytes, f);
SDL_SetRenderDrawBlendMode(state->renderer, SDL_BLENDMODE_ADD);
SDL_Surface* test_surface = IMG_LoadSVG_RW(SDL_RWFromConstMem(sprite, sprite_length_bytes));
free(sprite);
if (test_surface) {
out->texture = SDL_CreateTextureFromSurface(state->renderer, test_surface);
out->original_width = test_surface->w;
out->original_height = test_surface->h;
SDL_FreeSurface(test_surface);
}
}

void IZ_VideoTeardownTexture(IZ_LoadedSprite* sprite) {
if (!sprite->texture) {
return;
}
SDL_DestroyTexture(sprite->texture);
sprite->original_width = 0;
sprite->original_height = 0;
}

+ 9
- 1
src/packages/game/output/video/IZ_video.h View File

@@ -30,6 +30,12 @@ typedef enum {
IZ_VIDEO_SPRITE_PRIORITY_HIGHEST,
} IZ_VideoSpritePriority;

typedef struct {
SDL_Texture* texture;
f32 original_width;
f32 original_height;
} IZ_LoadedSprite;

// TODO properly define sprites
typedef struct {
SDL_Texture* texture;
@@ -70,7 +76,9 @@ IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, void*, const char*, u8, co
IZ_ProcedureResult IZ_VideoSaveConfig(IZ_VideoState*, const char*);

// TODO implement
void IZ_VideoLoadTexture(IZ_VideoState*, const char*, SDL_Texture**);
void IZ_VideoLoadTexture(IZ_VideoState*, const char*, const char*, IZ_LoadedSprite*);

void IZ_VideoTeardownTexture(IZ_LoadedSprite*);

void IZ_VideoTeardown(IZ_VideoState*);



Loading…
Cancel
Save