mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-06 17:09:06 +01:00
Use SDL3_Image + multiple bug fixes
This commit is contained in:
parent
42c3d9d215
commit
79f946a4a5
5 changed files with 46 additions and 5 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "story-editor/libs/SDL_image"]
|
||||
path = story-editor/libs/SDL_image
|
||||
url = git@github.com:libsdl-org/SDL_image.git
|
||||
|
|
@ -107,6 +107,9 @@ include_directories(${sdl3_SOURCE_DIR}/include)
|
|||
# set(BUILD_SHARED_LIBS FALSE)
|
||||
# # END ADDITION
|
||||
|
||||
add_subdirectory(libs/SDL_image)
|
||||
include_directories(libs/SDL_image/include)
|
||||
|
||||
# FetchContent_MakeAvailable(SDL2_image)
|
||||
set(SRCS
|
||||
|
||||
|
|
@ -255,7 +258,7 @@ target_compile_definitions(${STORY_EDITOR_PROJECT} PUBLIC cimg_display=0)
|
|||
|
||||
target_compile_definitions(${STORY_EDITOR_PROJECT} PUBLIC "$<$<CONFIG:DEBUG>:DEBUG>")
|
||||
|
||||
target_link_directories(${STORY_EDITOR_PROJECT} PUBLIC ${sdl3_BINARY_DIR} ${curl_BINARY_DIR})
|
||||
target_link_directories(${STORY_EDITOR_PROJECT} PUBLIC ${sdl3_BINARY_DIR} ${curl_BINARY_DIR} ${CMAKE_BINARY_DIR}/libs/SDL_image)
|
||||
|
||||
|
||||
set(SDL2_BIN_DIR ${sdl3_BINARY_DIR})
|
||||
|
|
@ -266,6 +269,7 @@ if(UNIX)
|
|||
OpenGL::GL
|
||||
dl
|
||||
SDL3
|
||||
SDL3_image
|
||||
libcurl_static
|
||||
OpenSSL::SSL OpenSSL::Crypto
|
||||
)
|
||||
|
|
|
|||
1
story-editor/libs/SDL_image
Submodule
1
story-editor/libs/SDL_image
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 25e816f614dbe4aa9fdaf89c248ae283f20038f9
|
||||
|
|
@ -32,7 +32,7 @@ your use of the corresponding standard functions.
|
|||
#else
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#endif
|
||||
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
|
||||
#include "IconsMaterialDesignIcons.h"
|
||||
#include "IconsFontAwesome5_c.h"
|
||||
|
|
@ -61,6 +61,36 @@ static std::string GetFileExtension(const std::string &fileName)
|
|||
// Simple helper function to load an image into a OpenGL texture with common settings
|
||||
bool LoadTextureFromFile(const char* filename, Gui::Image &img)
|
||||
{
|
||||
|
||||
SDL_Surface *surface, *temp;
|
||||
|
||||
surface = IMG_Load(filename);
|
||||
if (!surface) {
|
||||
SDL_Log("Couldn't load %s: %s\n", filename, SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Use the tonemap operator to convert to SDR output */
|
||||
const char *tonemap = NULL;
|
||||
SDL_SetStringProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING, tonemap);
|
||||
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32);
|
||||
SDL_DestroySurface(surface);
|
||||
if (!temp) {
|
||||
SDL_Log("Couldn't convert surface: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
img.texture = SDL_CreateTextureFromSurface(renderer, temp);
|
||||
SDL_DestroySurface(temp);
|
||||
if (!img.texture) {
|
||||
SDL_Log("Couldn't create texture: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_QueryTexture(static_cast<SDL_Texture*>(img.texture), NULL, NULL, &img.w, &img.h);
|
||||
|
||||
/*
|
||||
|
||||
std::string ext = GetFileExtension(filename);
|
||||
|
||||
SDL_Surface* surface = nullptr;
|
||||
|
|
@ -120,7 +150,7 @@ bool LoadTextureFromFile(const char* filename, Gui::Image &img)
|
|||
|
||||
SDL_DestroySurface(surface); // SDL3
|
||||
// SDL_FreeSurface(surface); // SDL2
|
||||
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -334,7 +364,10 @@ bool Gui::LoadRawImage(const std::string &filename, Image &image)
|
|||
{
|
||||
bool success = true;
|
||||
|
||||
LoadTextureFromFile(filename.c_str(), image);
|
||||
if (std::filesystem::is_regular_file(filename))
|
||||
{
|
||||
LoadTextureFromFile(filename.c_str(), image);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ MediaNode::MediaNode(const std::string &title, IStoryManager &proj)
|
|||
: BaseNode(title, proj)
|
||||
, m_story(proj)
|
||||
{
|
||||
Gui::LoadRawImage("fairy.png", m_image);
|
||||
// Gui::LoadRawImage("fairy.png", m_image);
|
||||
|
||||
// Create defaut one input and one output
|
||||
AddInput();
|
||||
|
|
|
|||
Loading…
Reference in a new issue