Skip to content

Commit

Permalink
Swap out SDL for GLFW
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Aug 3, 2021
1 parent aeff44b commit 3adfacd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
35 changes: 13 additions & 22 deletions NoiseTool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ CPMAddPackage(
"WITH_TESTSUITE OFF"
)

# Get SDL2 windows dev release
if(WIN32)
CPMAddPackage(
NAME SDL2
VERSION 2.0.14
URL https://www.libsdl.org/release/SDL2-devel-2.0.14-VC.zip
)

# Set SDL2 path so magnum can find it
list(APPEND CMAKE_PREFIX_PATH "${SDL2_SOURCE_DIR}")
endif()
CPMAddPackage(
NAME GLFW
GITHUB_REPOSITORY glfw/glfw
GIT_TAG 3.3.4
EXCLUDE_FROM_ALL YES
OPTIONS
"GLFW_INSTALL OFF"
"GLFW_BUILD_TESTS OFF"
"GLFW_BUILD_EXAMPLES OFF"
"GLFW_BULID_DOCS OFF"
)

CPMAddPackage(
NAME magnum
Expand All @@ -31,7 +31,7 @@ CPMAddPackage(
OPTIONS
"BUILD_STATIC ON"
"BUILD_PLUGINS_STATIC ON"
"WITH_SDL2APPLICATION ON"
"WITH_GLFWAPPLICATION ON"
"WITH_MESHTOOLS OFF"
"WITH_TRADE OFF"
"WITH_TEXT OFF"
Expand Down Expand Up @@ -65,7 +65,7 @@ CPMAddPackage(
# Use modules from magnum-integration since it has everything we need
set(CMAKE_MODULE_PATH "${magnum-integration_SOURCE_DIR}/modules" ${CMAKE_MODULE_PATH})

find_package(Magnum REQUIRED GL Sdl2Application)
find_package(Magnum REQUIRED GL GlfwApplication)
find_package(MagnumIntegration REQUIRED ImGui)

# Bundle a better font
Expand Down Expand Up @@ -104,14 +104,5 @@ endif()

set(install_targets ${install_targets} NoiseTool PARENT_SCOPE)

# Need sdl2 dll on windows, linux/mac its expected to be installed
if(WIN32)
find_package(SDL2)
install(
FILES ${SDL2_DLL_RELEASE}
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()

# Make the executable a default target to build & run in Visual Studio
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT NoiseTool)
2 changes: 2 additions & 0 deletions NoiseTool/FastNoiseNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ const FastNoise::Metadata* FastNoiseNodeEditor::MetadataMenuGroup::DrawUI( std::

FastNoiseNodeEditor::FastNoiseNodeEditor()
{
ImGui::CreateContext();

#ifdef IMGUI_HAS_DOCK
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
#endif
Expand Down
11 changes: 7 additions & 4 deletions NoiseTool/NoiseToolApp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <imgui.h>
#include <Corrade/Utility/Resource.h>
#include <Magnum/ImGuiIntegration/Context.hpp>
#include <Magnum/Math/Matrix4.h>
#include <Magnum/GL/DefaultFramebuffer.h>
Expand All @@ -24,20 +25,22 @@ NoiseToolApp::NoiseToolApp( const Arguments& arguments ) :
.setWindowFlags( Configuration::WindowFlag::Resizable | Configuration::WindowFlag::Maximized ),
GLConfiguration{}
.setSampleCount( 4 )
},
mImGuiContext( Vector2{ windowSize() } / dpiScaling(), windowSize(), framebufferSize() )
}
{
InitResources();

const Vector2 size = Vector2 { windowSize() } / dpiScaling();

// Add a font that actually looks acceptable on HiDPI screens.
{
ImGui::GetIO().Fonts->Clear();
ImFontConfig fontConfig;
fontConfig.FontDataOwnedByAtlas = false;
const auto font = Utility::Resource { "font" }.getRaw( "main.ttf" );
ImGui::GetIO().Fonts->AddFontFromMemoryTTF( const_cast<char*>( font.data() ), font.size(), 14.0f * framebufferSize().x() / ImGui::GetIO().DisplaySize.x, &fontConfig );
ImGui::GetIO().Fonts->AddFontFromMemoryTTF( const_cast<char*>( font.data() ), font.size(), 14.0f * framebufferSize().x() / size.x(), &fontConfig );
}

mImGuiContext = ImGuiIntegration::Context( *ImGui::GetCurrentContext(), size, windowSize(), framebufferSize() );

GL::Renderer::enable( GL::Renderer::Feature::DepthTest );

setSwapInterval( 1 );
Expand Down
2 changes: 1 addition & 1 deletion NoiseTool/NoiseToolApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <array>
#include <Magnum/Math/Color.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/Platform/GlfwApplication.h>
#include <Magnum/ImGuiIntegration/Context.h>
#include <Magnum/SceneGraph/Object.h>
#include <Magnum/SceneGraph/Camera.h>
Expand Down

0 comments on commit 3adfacd

Please sign in to comment.