Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest sf::Texture changes #282

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions imgui-SFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ struct WindowContext {
const sf::Window* window;
ImGuiContext* imContext{ImGui::CreateContext()};

sf::Texture fontTexture; // internal font atlas which is used if user doesn't set a custom
// sf::Texture.
std::optional<sf::Texture> fontTexture; // internal font atlas which is used if user doesn't set
// a custom sf::Texture.

bool windowHasFocus;
bool mouseMoved{false};
Expand Down Expand Up @@ -499,20 +499,24 @@ bool UpdateFontTexture() {

io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

sf::Texture& texture = s_currWindowCtx->fontTexture;
if (!texture.create({static_cast<unsigned>(width), static_cast<unsigned>(height)})) {
auto newTexture =
sf::Texture::create({static_cast<unsigned>(width), static_cast<unsigned>(height)});

if (!newTexture.has_value()) {
return false;
}

texture.update(pixels);
newTexture->update(pixels);

ImTextureID texID = convertGLTextureHandleToImTextureID(texture.getNativeHandle());
ImTextureID texID = convertGLTextureHandleToImTextureID(newTexture->getNativeHandle());
io.Fonts->SetTexID(texID);

s_currWindowCtx->fontTexture = std::move(newTexture);

return true;
}

sf::Texture& GetFontTexture() {
std::optional<sf::Texture>& GetFontTexture() {
assert(s_currWindowCtx);
return s_currWindowCtx->fontTexture;
}
Expand Down
4 changes: 3 additions & 1 deletion imgui-SFML.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Joystick.hpp>

#include <optional>

#include "imgui-SFML_export.h"

namespace sf {
Expand Down Expand Up @@ -44,7 +46,7 @@ IMGUI_SFML_API void Shutdown(const sf::Window& window);
IMGUI_SFML_API void Shutdown();

[[nodiscard]] IMGUI_SFML_API bool UpdateFontTexture();
IMGUI_SFML_API sf::Texture& GetFontTexture();
IMGUI_SFML_API std::optional<sf::Texture>& GetFontTexture();

// joystick functions
IMGUI_SFML_API void SetActiveJoystickId(unsigned int joystickId);
Expand Down