Browse Source

trying to make imgui work on dll

vlod 3 years ago
parent
commit
ae284ccee0

+ 2 - 2
Pika/core/pikaRuntime/dllLoader/dllLoader.h

@@ -1,8 +1,9 @@
 #pragma once
 #include <filesystem>
 #include <GLFW/glfw3.h>
+#include <imgui.h>
 
-#define TESTSTART(x) void x(GLFWwindow *wind)
+#define TESTSTART(x) void x(GLFWwindow *wind, ImGuiContext *imguiContext)
 typedef TESTSTART(testStart_t);
 //extern "C" __declspec(dllexport) TESTPRINT(gameLogic);
 #undef TESTSTART
@@ -16,7 +17,6 @@ typedef TESTUPDATE(testUpdate_t);
 namespace pika
 {
 
-
 bool loadDll(std::filesystem::path path, 
 	testStart_t** testPrint, testUpdate_t** testUpdate);
 

+ 11 - 3
Pika/core/pikaRuntime/pikaImgui/pikaImgui.cpp

@@ -1,9 +1,9 @@
+#include <glad/glad.h>
 #include <pikaImgui/pikaImgui.h>
 
-
-void pika::initImgui(GLFWwindow *wind)
+ImGuiContext *pika::initImgui(GLFWwindow *wind)
 {
-	ImGui::CreateContext();
+	auto context = ImGui::CreateContext();
 	//ImGui::StyleColorsDark();
 	imguiThemes::embraceTheDarkness();
 	
@@ -26,6 +26,7 @@ void pika::initImgui(GLFWwindow *wind)
 	ImGui_ImplGlfw_InitForOpenGL(wind, true);
 	ImGui_ImplOpenGL3_Init("#version 330");
 
+	return context;
 }
 
 void pika::imguiStartFrame()
@@ -52,9 +53,16 @@ void pika::imguiEndFrame(GLFWwindow *wind)
 	//  For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
 	if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
 	{
+		//GLFWwindow *backup_current_context = glfwGetCurrentContext();
+		//ImGui::UpdatePlatformWindows();
+		//ImGui::RenderPlatformWindowsDefault();
+		//glfwMakeContextCurrent(backup_current_context);
+
 		GLFWwindow *backup_current_context = glfwGetCurrentContext();
 		ImGui::UpdatePlatformWindows();
 		ImGui::RenderPlatformWindowsDefault();
 		glfwMakeContextCurrent(backup_current_context);
+
+	
 	}
 }

+ 1 - 1
Pika/core/pikaRuntime/pikaImgui/pikaImgui.h

@@ -13,7 +13,7 @@ namespace pika
 {
 
 
-	void initImgui(GLFWwindow *wind);
+	ImGuiContext *initImgui(GLFWwindow *wind);
 	void imguiStartFrame();
 	void imguiEndFrame(GLFWwindow *wind);
 

+ 6 - 14
Pika/core/pikaRuntime/pikaMain.cpp

@@ -5,8 +5,6 @@
 #include <glad/glad.h>
 #include <GLFW/glfw3.h>
 
-#include <gl2d/gl2d.h>
-gl2d::Renderer2D renderer;
 
 #include "assert/assert.h"
 #include "dllLoader/dllLoader.h"
@@ -36,28 +34,22 @@ int main()
 
 	PIKA_PERMA_ASSERT(gladLoadGL(), "Problem initializing glad");
 
-	gl2d::init();
-	renderer.create();
+	auto imguiContext = pika::initImgui(window);
 
-	pika::initImgui(window);
-
-	testStart(window);
+	testStart(window, imguiContext);
 
 	while (!glfwWindowShouldClose(window))
 	{
 
 		glClear(GL_COLOR_BUFFER_BIT);
-		pika::imguiStartFrame();
-
-		gl2d::enableNecessaryGLFeatures();
-		renderer.updateWindowMetrics(640, 480);
-		renderer.renderRectangle({10,10, 100, 100}, Colors_Magenta);
-		renderer.flush();
 
 		testUpdate(window);
 
+		//pika::imguiStartFrame();
+		//ImGui::Begin("test");
+		//ImGui::End();
+		//pika::imguiEndFrame(window);
 
-		pika::imguiEndFrame(window);
 
 		glfwPollEvents();
 		glfwSwapBuffers(window);

+ 21 - 7
Pika/gameplay/dllMain.cpp

@@ -5,28 +5,42 @@
 #include "pikaImgui/pikaImgui.h"
 #include <assert/assert.h>
 
+#include <gl2d/gl2d.h>
+gl2d::Renderer2D renderer;
 
-PIKA_API void testStart(GLFWwindow *wind)
+ImGuiContext *imguiContextGlobal = 0;
+
+PIKA_API void testStart(GLFWwindow *wind, ImGuiContext *imguiContext)
 {
+	
 	//PIKA_PERMA_ASSERT(glfwInit(), "Problem initializing glfw from dll");
 	//glfwMakeContextCurrent(wind);
 
 	PIKA_PERMA_ASSERT(gladLoadGL(), "Problem initializing glad from dll");
-
+	//printf("%s\n", glGetString(GL_VERSION));
 	//pika::initImgui(wind);
+
+	imguiContextGlobal = imguiContext;
+	ImGui::SetCurrentContext(imguiContextGlobal);
+	//ImGui::SetAllocatorFunctions()
+
+	gl2d::init();
+	renderer.create();
+
 }
 
 
 PIKA_API void testUpdate(GLFWwindow *wind)
 {
-	pika::imguiStartFrame();
-
+	gl2d::enableNecessaryGLFeatures();
+	renderer.updateWindowMetrics(640, 480);
+	renderer.renderRectangle({10,10, 100, 100}, Colors_Magenta);
+	renderer.flush();
 
+	ImGui::SetCurrentContext(imguiContextGlobal);
 
+	pika::imguiStartFrame();
 	ImGui::Begin("test");
-	
 	ImGui::End();
-
-
 	pika::imguiEndFrame(wind);
 }

+ 2 - 2
Pika/gameplay/dllMain.h

@@ -1,7 +1,7 @@
 #pragma once
 #include <pikaConfig.h>
 #include <GLFW/glfw3.h>
+#include <imgui.h>
 
-
-PIKA_API void testStart(GLFWwindow *wind);
+PIKA_API void testStart(GLFWwindow *wind, ImGuiContext *imguiContext);
 PIKA_API void testUpdate(GLFWwindow *wind);