yea
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
#include <iostream>
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static VkAllocationCallbacks* g_Allocator = NULL;
|
||||
@@ -329,7 +331,7 @@ static void glfw_error_callback(int error, const char* description)
|
||||
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
||||
}
|
||||
|
||||
int startImgui(void* customState, void (*const initFunc)(void), void (*const drawFunc)(DrawData&, void*))
|
||||
int startImgui(void* customState, void (*const initFunc)(DrawData&, void*), void (*const drawFunc)(DrawData&, void*), const char* title, int windowWidth, int windowHeight)
|
||||
{
|
||||
// Setup GLFW window
|
||||
glfwSetErrorCallback(glfw_error_callback);
|
||||
@@ -337,7 +339,7 @@ int startImgui(void* customState, void (*const initFunc)(void), void (*const dra
|
||||
return 1;
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Vulkan example", NULL, NULL);
|
||||
GLFWwindow* window = glfwCreateWindow(windowWidth, windowHeight, title, NULL, NULL);
|
||||
|
||||
// Setup Vulkan
|
||||
if (!glfwVulkanSupported())
|
||||
@@ -404,7 +406,12 @@ int startImgui(void* customState, void (*const initFunc)(void), void (*const dra
|
||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
//IM_ASSERT(font != NULL);
|
||||
|
||||
initFunc();
|
||||
// Our state
|
||||
DrawData drawData{};
|
||||
drawData.window_handle = glfwGetWin32Window(window);
|
||||
drawData.window_size = getWindowSize(window);
|
||||
|
||||
initFunc(drawData, customState);
|
||||
|
||||
// Upload Fonts
|
||||
{
|
||||
@@ -436,9 +443,6 @@ int startImgui(void* customState, void (*const initFunc)(void), void (*const dra
|
||||
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
||||
}
|
||||
|
||||
// Our state
|
||||
DrawData drawData{};
|
||||
|
||||
// Main loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
@@ -468,8 +472,16 @@ int startImgui(void* customState, void (*const initFunc)(void), void (*const dra
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImVec2 prevWindowSize = getWindowSize(window);
|
||||
drawData.window_size = prevWindowSize;
|
||||
|
||||
drawFunc(drawData, customState);
|
||||
|
||||
if (drawData.window_size.x != prevWindowSize.x || drawData.window_size.y != prevWindowSize.y)
|
||||
{
|
||||
glfwSetWindowSize(window, drawData.window_size.x, drawData.window_size.y);
|
||||
}
|
||||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
ImDrawData* draw_data = ImGui::GetDrawData();
|
||||
@@ -500,3 +512,11 @@ int startImgui(void* customState, void (*const initFunc)(void), void (*const dra
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ImVec2 getWindowSize(GLFWwindow* window)
|
||||
{
|
||||
int window_width;
|
||||
int window_height;
|
||||
glfwGetWindowSize(window, &window_width, &window_height);
|
||||
return ImVec2(window_width, window_height);
|
||||
}
|
||||
Reference in New Issue
Block a user