mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:30:05 +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
				
			
		|  | @ -21,6 +21,8 @@ int main(int argc, char* argv[]) | |||
|    scwx::util::Logger::Initialize(); | ||||
|    spdlog::set_level(spdlog::level::debug); | ||||
| 
 | ||||
|    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); | ||||
| 
 | ||||
|    QApplication a(argc, argv); | ||||
| 
 | ||||
|    QCoreApplication::setApplicationName("Supercell Wx"); | ||||
|  | @ -61,7 +63,7 @@ int main(int argc, char* argv[]) | |||
|    // Initialize application
 | ||||
|    scwx::qt::config::RadarSite::Initialize(); | ||||
|    scwx::qt::manager::SettingsManager::Initialize(); | ||||
|    scwx::qt::manager::ResourceManager::PreLoad(); | ||||
|    scwx::qt::manager::ResourceManager::Initialize(); | ||||
| 
 | ||||
|    // Run Qt main loop
 | ||||
|    int result; | ||||
|  | @ -78,6 +80,9 @@ int main(int argc, char* argv[]) | |||
|    work.reset(); | ||||
|    threadPool.join(); | ||||
| 
 | ||||
|    // Shutdown application
 | ||||
|    scwx::qt::manager::ResourceManager::Shutdown(); | ||||
| 
 | ||||
|    // Shutdown AWS SDK
 | ||||
|    Aws::ShutdownAPI(awsSdkOptions); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -8,7 +8,8 @@ namespace manager | |||
| { | ||||
| namespace ResourceManager | ||||
| { | ||||
| void PreLoad(); | ||||
| void Initialize(); | ||||
| void Shutdown(); | ||||
| } // namespace ResourceManager
 | ||||
| } // namespace manager
 | ||||
| } // namespace qt
 | ||||
|  |  | |||
|  | @ -13,6 +13,8 @@ | |||
| #include <scwx/util/threads.hpp> | ||||
| #include <scwx/util/time.hpp> | ||||
| 
 | ||||
| #include <backends/imgui_impl_opengl3.h> | ||||
| #include <imgui.h> | ||||
| #include <QApplication> | ||||
| #include <QColor> | ||||
| #include <QDebug> | ||||
|  | @ -682,10 +684,24 @@ void MapWidget::initializeGL() | |||
| void MapWidget::paintGL() | ||||
| { | ||||
|    p->frameDraws_++; | ||||
| 
 | ||||
|    // Setup ImGui Frame
 | ||||
|    ImGui::GetIO().DisplaySize = {static_cast<float>(size().width()), | ||||
|                                  static_cast<float>(size().height())}; | ||||
| 
 | ||||
|    // Start ImGui Frame
 | ||||
|    ImGui_ImplOpenGL3_NewFrame(); | ||||
|    ImGui::NewFrame(); | ||||
| 
 | ||||
|    // Render QMapLibreGL Map
 | ||||
|    p->map_->resize(size()); | ||||
|    p->map_->setFramebufferObject(defaultFramebufferObject(), | ||||
|                                  size() * pixelRatio()); | ||||
|    p->map_->render(); | ||||
| 
 | ||||
|    // Render ImGui Frame
 | ||||
|    ImGui::Render(); | ||||
|    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); | ||||
| } | ||||
| 
 | ||||
| void MapWidget::mapChanged(QMapLibreGL::Map::MapChange mapChange) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat