imgui-platform-kit 2.0.0
Cross-platform Dear ImGui application framework
Loading...
Searching...
No Matches
glfw_opengl3_user_interface.h
Go to the documentation of this file.
1
2#pragma once
3
13#if defined(__linux__)
14
15#include "imgui.h"
16#include "imgui_impl_glfw.h"
17#include "imgui_impl_opengl3.h"
18
19#include <string>
20#include <iostream>
21#include <vector>
22#include <filesystem>
23#include <memory>
24
25#include <stdio.h>
26#define GL_SILENCE_DEPRECATION
27#if defined(IMGUI_IMPL_OPENGL_ES2)
28#include <GLES2/gl2.h>
29#endif
30#include <GLFW/glfw3.h> // Will drag system OpenGL headers
31
32#include "implot.h"
33#include "implot_internal.h"
34
35#include "imgui-node-editor/imgui_node_editor.h"
36namespace ImNodeEditor = ax::NodeEditor;
37
38
39// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers.
40// To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma.
41// Your own project should not be affected, as you are likely to link with a newer binary of GLFW that is adequate for your version of Visual Studio.
42#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
43#pragma comment(lib, "legacy_stdio_definitions")
44#endif
45
46// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
47#ifdef __EMSCRIPTEN__
48#include "../libs/emscripten/emscripten_mainloop_stub.h"
49#endif
50
51
52#include "../user_interface_parameters.h"
53#include "../user_interface_window.h"
54
55namespace imgui_kit
56{
61 struct GLFWbackgroundImageTexture
62 {
63 GLuint texture;
64 BackgroundImageParameters parameters;
65
66 GLFWbackgroundImageTexture()
67 : texture(0)
68 , parameters()
69 {}
70
71 explicit GLFWbackgroundImageTexture(BackgroundImageParameters parameters)
72 : texture(0), parameters(std::move(parameters))
73 {}
74 };
75
82 class UserInterface
83 {
84 private:
85 UserInterfaceParameters parameters;
86 GLFWbackgroundImageTexture backgroundImageTexture;
87 GLFWwindow* window;
88 std::vector<std::shared_ptr<UserInterfaceWindow>> windows;
89 bool shutdownRequest;
90 public:
92 explicit UserInterface(UserInterfaceParameters parameters);
93 ~UserInterface() = default;
94
95 void initialize();
96 void render();
97 void shutdown() const;
98 [[nodiscard]] bool isShutdownRequested() const;
99 template<typename T, typename... Args>
100 void addWindow(Args&&... args)
101 {
102 auto window = std::make_shared<T>(std::forward<Args>(args)...);
103 windows.push_back(std::move(window));
104 }
105 private:
106 void loadIcon() const;
107 void loadFont();
108 void loadBackgroundImage();
109 void renderWindows() const;
110 void renderBackgroundImage() const;
111 void updateLastRenderedFrameDimensions();
112 void updateFontGlobalScale() const;
113 };
114
115}
116
117// Forward declarations of helper functions
118bool LoadTextureFromFile(const char* filename, GLuint* out_texture, int* out_width, int* out_height);
119float GetDpiScale(GLFWwindow* window);
120GLFWmonitor* GetActiveMonitor(GLFWwindow* window);
121#endif
void addWindow(Args &&... args)
Constructs a window of type T and registers it for rendering.
Definition win32_dx12_user_interface.h:157
void shutdown()
Destroys the rendering backend, the ImGui contexts and the platform window.
bool isShutdownRequested() const
Returns true once the user has requested to close the window.
void initialize()
Creates the platform window, sets up the rendering backend and the ImGui/ImPlot/node-editor contexts,...
void render()
Renders one frame: processes platform events and calls render() on every registered window.
UserInterface()
Constructs the interface with default UserInterfaceParameters.
Definition colour_palette.h:11