Skip to content

Commit

Permalink
Update to latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Jun 15, 2024
1 parent 4727cf1 commit d6a6974
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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

0 comments on commit d6a6974

Please sign in to comment.