Use BMP instead of JPG and remove SDL image
This commit is contained in:
@@ -5,12 +5,11 @@ project(HansTheGatherer)
|
|||||||
# Option to switch real platform vs. SDL implementation...
|
# Option to switch real platform vs. SDL implementation...
|
||||||
|
|
||||||
find_package(SDL3 CONFIG REQUIRED)
|
find_package(SDL3 CONFIG REQUIRED)
|
||||||
find_package(SDL3_image CONFIG REQUIRED)
|
|
||||||
find_package(flecs CONFIG REQUIRED)
|
find_package(flecs CONFIG REQUIRED)
|
||||||
find_package(spdlog CONFIG REQUIRED)
|
find_package(spdlog CONFIG REQUIRED)
|
||||||
|
|
||||||
add_executable(HansTheGatherer main.cpp assets.cpp)
|
add_executable(HansTheGatherer main.cpp assets.cpp)
|
||||||
|
|
||||||
target_link_libraries(HansTheGatherer SDL3::SDL3 SDL3_image::SDL3_image flecs::flecs spdlog::spdlog)
|
target_link_libraries(HansTheGatherer SDL3::SDL3 flecs::flecs spdlog::spdlog)
|
||||||
|
|
||||||
set_property(TARGET HansTheGatherer PROPERTY CXX_STANDARD 20)
|
set_property(TARGET HansTheGatherer PROPERTY CXX_STANDARD 20)
|
||||||
|
|||||||
15
assets.cpp
15
assets.cpp
@@ -2,16 +2,15 @@
|
|||||||
#include "audio.hpp"
|
#include "audio.hpp"
|
||||||
#include "sdl_types.hpp"
|
#include "sdl_types.hpp"
|
||||||
|
|
||||||
#include <SDL3_image/SDL_image.h>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
static constexpr uint8_t BACKGROUND_DATA[] = {
|
static constexpr uint8_t BACKGROUND_DATA[] = {
|
||||||
#embed "assets/images/jungle.jpg"
|
#embed "assets/images/jungle.bmp"
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr uint8_t FRUITS_DATA[] = {
|
static constexpr uint8_t FRUITS_DATA[] = {
|
||||||
#embed "assets/images/fruits.jpg"
|
#embed "assets/images/fruits.bmp"
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr uint8_t BACKGROUND_MUSIC_DATA[] = {
|
static constexpr uint8_t BACKGROUND_MUSIC_DATA[] = {
|
||||||
@@ -21,9 +20,15 @@ static constexpr uint8_t BACKGROUND_MUSIC_DATA[] = {
|
|||||||
SDL_Texture *load_texture(uint8_t const *data, size_t size,
|
SDL_Texture *load_texture(uint8_t const *data, size_t size,
|
||||||
SDL_Renderer *renderer) {
|
SDL_Renderer *renderer) {
|
||||||
auto *iostream = SDL_IOFromConstMem(data, size);
|
auto *iostream = SDL_IOFromConstMem(data, size);
|
||||||
SDL_Texture *texture = IMG_LoadTexture_IO(renderer, iostream, false);
|
SDL_Surface *surface = SDL_LoadBMP_IO(iostream, false);
|
||||||
|
if (surface == nullptr) {
|
||||||
|
spdlog::error("Failed to load SDL surface!\nCause: {}", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||||
if (texture == nullptr) {
|
if (texture == nullptr) {
|
||||||
spdlog::error("Failed to load SDL texture!\nCause: {}", SDL_GetError());
|
spdlog::error("Failed to create texture from surface!\nCause: {}",
|
||||||
|
SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
|
|||||||
BIN
assets/images/fruits.bmp
Normal file
BIN
assets/images/fruits.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 228 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB |
BIN
assets/images/jungle.bmp
Normal file
BIN
assets/images/jungle.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 165 KiB |
4
main.cpp
4
main.cpp
@@ -82,7 +82,7 @@ int main() {
|
|||||||
Position{.x = WINDOW_WIDTH / 2 - 32, .y = WINDOW_HEIGHT - 32})
|
Position{.x = WINDOW_WIDTH / 2 - 32, .y = WINDOW_HEIGHT - 32})
|
||||||
.set<Sprite>(Sprite{.texture = &texture_assets->fruits,
|
.set<Sprite>(Sprite{.texture = &texture_assets->fruits,
|
||||||
.texture_atlas_index = 212})
|
.texture_atlas_index = 212})
|
||||||
.set<Size>(Size{.w = 64, .h = 16})
|
.set<Size>(Size{.w = 72, .h = 32})
|
||||||
.add<Basket>();
|
.add<Basket>();
|
||||||
|
|
||||||
world.system<Game const, TextureAssets const>("SpawnFruits")
|
world.system<Game const, TextureAssets const>("SpawnFruits")
|
||||||
@@ -101,7 +101,7 @@ int main() {
|
|||||||
.set<Sprite>(Sprite{.texture = &texture_assets.fruits,
|
.set<Sprite>(Sprite{.texture = &texture_assets.fruits,
|
||||||
.texture_atlas_index =
|
.texture_atlas_index =
|
||||||
static_cast<uint16_t>(game.ticks % 228)})
|
static_cast<uint16_t>(game.ticks % 228)})
|
||||||
.set<Size>(Size{.w = 16, .h = 16});
|
.set<Size>(Size{.w = 32, .h = 32});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,6 @@
|
|||||||
"dependencies": [
|
"dependencies": [
|
||||||
"spdlog",
|
"spdlog",
|
||||||
"sdl3",
|
"sdl3",
|
||||||
{
|
|
||||||
"name": "sdl3-image",
|
|
||||||
"features": ["jpeg"]
|
|
||||||
},
|
|
||||||
"spdlog",
|
"spdlog",
|
||||||
"flecs"
|
"flecs"
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user