mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:10:04 +00:00 
			
		
		
		
	Connect ImGui render to QOpenGLWidgets
This commit is contained in:
		
							parent
							
								
									3c69ad28c6
								
							
						
					
					
						commit
						dd1b4f27c8
					
				
					 4 changed files with 76 additions and 6 deletions
				
			
		|  | @ -2,6 +2,12 @@ | |||
| #include <scwx/qt/config/county_database.hpp> | ||||
| #include <scwx/qt/util/font.hpp> | ||||
| #include <scwx/qt/util/texture_atlas.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <backends/imgui_impl_opengl3.h> | ||||
| #include <imgui.h> | ||||
| #include <QOffscreenSurface> | ||||
| #include <QOpenGLContext> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -11,20 +17,54 @@ namespace manager | |||
| { | ||||
| namespace ResourceManager | ||||
| { | ||||
| static void LoadFonts(); | ||||
| static const std::string logPrefix_ = "scwx::qt::manager::ResourceManager"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| void PreLoad() | ||||
| static void InitializeImGui(); | ||||
| static void LoadFonts(); | ||||
| static void LoadTextures(); | ||||
| static void ShutdownImGui(); | ||||
| 
 | ||||
| static std::unique_ptr<QOffscreenSurface> surface_ {}; | ||||
| 
 | ||||
| void Initialize() | ||||
| { | ||||
|    config::CountyDatabase::Initialize(); | ||||
| 
 | ||||
|    InitializeImGui(); | ||||
|    LoadFonts(); | ||||
|    LoadTextures(); | ||||
| } | ||||
| 
 | ||||
| void Shutdown() | ||||
| { | ||||
|    ShutdownImGui(); | ||||
| } | ||||
| 
 | ||||
| static void InitializeImGui() | ||||
| { | ||||
|    // Create OpenGL Offscreen Surface
 | ||||
|    surface_ = std::make_unique<QOffscreenSurface>(); | ||||
|    surface_->create(); | ||||
|    if (!QOpenGLContext::globalShareContext()->makeCurrent(surface_.get())) | ||||
|    { | ||||
|       logger_->warn("Failed to initialize offscreen surface"); | ||||
|    } | ||||
| 
 | ||||
|    // Initialize ImGui
 | ||||
|    ImGui::CreateContext(); | ||||
|    ImGui_ImplOpenGL3_Init(); | ||||
|    QOpenGLContext::globalShareContext()->doneCurrent(); | ||||
| } | ||||
| 
 | ||||
| static void LoadFonts() | ||||
| { | ||||
|    config::CountyDatabase::Initialize(); | ||||
| 
 | ||||
|    util::Font::Create(":/res/fonts/din1451alt.ttf"); | ||||
|    util::Font::Create(":/res/fonts/din1451alt_g.ttf"); | ||||
| } | ||||
| 
 | ||||
| static void LoadTextures() | ||||
| { | ||||
|    util::TextureAtlas& textureAtlas = util::TextureAtlas::Instance(); | ||||
|    textureAtlas.RegisterTexture("lines/default-1x7", | ||||
|                                 ":/res/textures/lines/default-1x7.png"); | ||||
|  | @ -33,6 +73,14 @@ static void LoadFonts() | |||
|    textureAtlas.BuildAtlas(8, 8); | ||||
| } | ||||
| 
 | ||||
| static void ShutdownImGui() | ||||
| { | ||||
|    QOpenGLContext::globalShareContext()->makeCurrent(surface_.get()); | ||||
|    ImGui_ImplOpenGL3_Shutdown(); | ||||
|    ImGui::DestroyContext(); | ||||
|    QOpenGLContext::globalShareContext()->doneCurrent(); | ||||
| } | ||||
| 
 | ||||
| } // namespace ResourceManager
 | ||||
| } // namespace manager
 | ||||
| } // namespace qt
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat