From da96d13a078d2dca2555b537019cb6b2e6647b69 Mon Sep 17 00:00:00 2001 From: kelson8 Date: Sat, 25 May 2024 12:55:57 -0400 Subject: [PATCH] Split project into seperate OpenGL and DirectX9 files. OpenGL support is broken and incomplete. --- ConsoleAppTest.vcxproj | 92 ++++- ConsoleAppTest.vcxproj.filters | 75 ---- GuiTestAppCpp.sln => ImGuiTestCPP.sln | 14 +- Main.cpp | 399 ++++++++++++++----- imgui.ini | 15 +- links.txt | 3 + test/directx9_test.cpp | 552 ++++++++++++++++++++++++++ test/directx9_test.h | 5 + test/opengl_test.cpp | 209 ++++++++++ test/opengl_test.h | 5 + 10 files changed, 1199 insertions(+), 170 deletions(-) delete mode 100644 ConsoleAppTest.vcxproj.filters rename GuiTestAppCpp.sln => ImGuiTestCPP.sln (55%) create mode 100644 links.txt create mode 100644 test/directx9_test.cpp create mode 100644 test/directx9_test.h create mode 100644 test/opengl_test.cpp create mode 100644 test/opengl_test.h diff --git a/ConsoleAppTest.vcxproj b/ConsoleAppTest.vcxproj index 7ea976b..489ff7a 100644 --- a/ConsoleAppTest.vcxproj +++ b/ConsoleAppTest.vcxproj @@ -1,6 +1,22 @@ + + Debug-Directx9 + Win32 + + + Debug-Directx9 + x64 + + + Debug-OpenGL + Win32 + + + Debug-OpenGL + x64 + Debug Win32 @@ -24,7 +40,7 @@ {6e4373c3-3e97-4007-9b8b-597f55378360} ConsoleAppTest 10.0 - GuiTestAppCpp + ImGuiTestCPP @@ -33,6 +49,12 @@ v143 Unicode + + Application + true + v143 + Unicode + Application false @@ -46,6 +68,12 @@ v143 Unicode + + Application + true + v143 + Unicode + Application false @@ -53,6 +81,12 @@ true Unicode + + v143 + + + v143 + @@ -61,16 +95,25 @@ + + + + + + + + true + Level3 @@ -83,6 +126,18 @@ true + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + Level3 @@ -106,12 +161,29 @@ _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpplatest - lib\imgui\;lib\imgui\backends;%(AdditionalIncludeDirectories) + lib\imgui\;lib\imgui\backends;include\;%(AdditionalIncludeDirectories) Console true - d3d9.lib;%(AdditionalDependencies) + d3d9.lib;opengl32.lib;glfw3.lib;%(AdditionalDependencies) + $(ProjectDir)lib\GLFW\lib-vc2022;%(AdditionalLibraryDirectories) + + + + + Level3 + true + _DEBUG;_CONSOLE;_OPENGL;%(PreprocessorDefinitions) + true + stdcpplatest + lib\imgui\;lib\imgui\backends;include\;%(AdditionalIncludeDirectories) + + + Console + true + d3d9.lib;opengl32.lib;glfw3.lib;%(AdditionalDependencies) + $(ProjectDir)lib\GLFW\lib-vc2022;%(AdditionalLibraryDirectories) @@ -130,6 +202,16 @@ true + + + lib\imgui\;lib\imgui\backends;%(AdditionalIncludeDirectories) + _DIRECTX9 + + + %(AdditionalLibraryDirectories) + d3d9.lib;$(CoreLibraryDependencies);%(AdditionalDependencies) + + @@ -139,6 +221,8 @@ + + @@ -150,6 +234,8 @@ + + diff --git a/ConsoleAppTest.vcxproj.filters b/ConsoleAppTest.vcxproj.filters deleted file mode 100644 index 994de89..0000000 --- a/ConsoleAppTest.vcxproj.filters +++ /dev/null @@ -1,75 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/GuiTestAppCpp.sln b/ImGuiTestCPP.sln similarity index 55% rename from GuiTestAppCpp.sln rename to ImGuiTestCPP.sln index bdd027b..1ca7ac4 100644 --- a/GuiTestAppCpp.sln +++ b/ImGuiTestCPP.sln @@ -3,12 +3,16 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleAppTest", "ConsoleAppTest.vcxproj", "{6E4373C3-3E97-4007-9B8B-597F55378360}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGuiTestCPP", "ConsoleAppTest.vcxproj", "{6E4373C3-3E97-4007-9B8B-597F55378360}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Debug-Directx9|x64 = Debug-Directx9|x64 + Debug-Directx9|x86 = Debug-Directx9|x86 + Debug-OpenGL|x64 = Debug-OpenGL|x64 + Debug-OpenGL|x86 = Debug-OpenGL|x86 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection @@ -17,6 +21,14 @@ Global {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug|x64.Build.0 = Debug|x64 {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug|x86.ActiveCfg = Debug|Win32 {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug|x86.Build.0 = Debug|Win32 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x64.ActiveCfg = Debug-Directx9|x64 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x64.Build.0 = Debug-Directx9|x64 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x86.ActiveCfg = Debug-Directx9|Win32 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x86.Build.0 = Debug-Directx9|Win32 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x64.ActiveCfg = Debug-OpenGL|x64 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x64.Build.0 = Debug-OpenGL|x64 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x86.ActiveCfg = Debug-OpenGL|Win32 + {6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x86.Build.0 = Debug-OpenGL|Win32 {6E4373C3-3E97-4007-9B8B-597F55378360}.Release|x64.ActiveCfg = Release|x64 {6E4373C3-3E97-4007-9B8B-597F55378360}.Release|x64.Build.0 = Release|x64 {6E4373C3-3E97-4007-9B8B-597F55378360}.Release|x86.ActiveCfg = Release|Win32 diff --git a/Main.cpp b/Main.cpp index 43ced88..ca7e382 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,3 +1,5 @@ +#ifdef _TEST +#ifdef _DIRECTX9 // Dear ImGui: standalone example application for DirectX 9 // Learn about Dear ImGui: @@ -6,9 +8,15 @@ // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). // - Introduction, links and more at the top of imgui.cpp + #include "imgui.h" #include "imgui_impl_dx9.h" + +#if _WIN32 #include "imgui_impl_win32.h" +#include +#endif + #include #include @@ -18,6 +26,15 @@ #include "util/textFileFunctions.h" +// https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/ +// Test macros +#define LIMIT 5 + +// Test code +#ifndef _TEST +#define _TEST +#endif + // Data static LPDIRECT3D9 g_pD3D = nullptr; static LPDIRECT3DDEVICE9 g_pd3dDevice = nullptr; @@ -42,6 +59,17 @@ static void HelpMarker(const char* desc) } } +// Windows specific features +// https://stackoverflow.com/questions/41600981/how-do-i-check-if-a-key-is-pressed-on-c +#ifdef _WIN32 + SHORT keyState = GetKeyState(VK_CAPITAL/*(caps lock)*/); + bool isToggled = keyState & 1; + bool isDown = keyState & 0x8000; + //[DllImport("kernel32.dll")] + //static extern IntPtr GetConsoleWindow(); +#endif + + // Will this work? static void setBulletText(const char* text) @@ -51,11 +79,63 @@ static void setBulletText(const char* text) // +int test() +{ + int num1 = 5; + int num2 = 10; + + return num1 + num2; +} + +// https://www.geeksforgeeks.org/converting-number-to-string-in-cpp/ +// Prints the value of +std::string testString1() +{ + int num1 = 5; + int num2 = 10; + int sum = num1 + num2; + std::string num1_string = std::to_string(num1); + std::string num2_string = std::to_string(num2); + std::string sum_string = std::to_string(sum); + + return "The value of " + num1_string + " + " + num2_string + " = " + sum_string; +} + + +// imgui_demo line 256 +static void ShowWindow(bool* p_open) +{ + static bool show_main_menu = false; + + if (show_main_menu) + { + if (ImGui::Begin("Test")) + { + ImGui::Text("Hello World!"); + } + } + + if (!ImGui::Begin("Test", p_open)) + { + + ImGui::End(); + return; + } + + +} + // Main code int main(int, char**) { + +#ifdef _TEST + //std::cout << testString1(); + std::cout << "Hello world!"; + +#else // Create application window - //ImGui_ImplWin32_EnableDpiAwareness(); +//ImGui_ImplWin32_EnableDpiAwareness(); WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr }; ::RegisterClassExW(&wc); HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui DirectX9 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr); @@ -109,11 +189,14 @@ int main(int, char**) ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); // Show window - - - // Main loop bool done = false; + bool button1_clicked = false; + static bool show_app_main_menu_bar = false; + //static bool toggle_text = false; + static bool dark_mode = false; + static bool define_test = false; + while (!done) { // Poll and handle messages (inputs, window resize, etc.) @@ -143,116 +226,216 @@ int main(int, char**) ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - // - // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); - static bool show_app_main_menu_bar = false; - static bool toggle_text = false; - - - if (ImGui::Begin("My new window", nullptr, ImGuiWindowFlags_MenuBar)) + if (ImGui::Begin("My new window", nullptr, ImGuiWindowFlags_MenuBar)) + { + // Menu bar + if (ImGui::BeginMenuBar()) { - if (ImGui::CollapsingHeader("test1")) + if (ImGui::BeginMenu("Test")) { - ImGui::BulletText("Hello, this should show up."); - ImGui::Separator(); + ImGui::MenuItem("Main menu bar", NULL, &show_app_main_menu_bar); + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + } - - - if (ImGui::Button("Menu toggle")) - { - std::cout << "Test" << std::endl; - // How would I check if dark mode is enabled? - //if (ImGui::GetStyle == ImGui) { - //ImGui::StyleColorsLight(); - //} - //else - // { - //ImGui::StyleColorsDark(); - //} - - } + // Main testing header. + if (ImGui::CollapsingHeader("test1")) + { + ImGui::BulletText("Hello, this should show up."); + ImGui::Separator(); - // I couldn't figure this out yet. - // This shows up for a second then dies. - ImGui::Separator(); - if (ImGui::Button("Click")) + // Menu toggle button + if (ImGui::Button("Menu toggle")) + { + std::cout << "Test" << std::endl; + // How would I check if dark mode is enabled? + //if (ImGui::GetStyle == ImGui) { + //ImGui::StyleColorsLight(); + //} + //else + // { + //ImGui::StyleColorsDark(); + //} + + } + + // I couldn't figure this out yet. + // This shows up for a second then dies. + ImGui::Separator(); + if (!ImGui::Button("Click")) + { + button1_clicked = false; + } + else + { + button1_clicked = true; + } + + if (!button1_clicked) + { + setBulletText("You clicked the button"); + } + else + { + ImGui::BulletText("Button not pressed."); + + //ImGui::BulletText("You clicked the button!"); + } + //} + + //if (ImGui::Button("Click")) + //{ + + // setBulletText("You clicked the button"); + // //ImGui::BulletText("You clicked the button!"); + //} + //else + //{ + // ImGui::BulletText("Button not pressed."); + //} + + ImGui::Separator(); + + + // This below works for a dark mode toggle. + // 5-16-2024 @ 9:14PM + +#ifndef _TEST +#define _TEST +#endif + + +#ifdef _TEST + // Well the checkbox is inverted lol, oh well I'll fix it later. + // If it is checked it turns off dark mode, I guess its because I have dark mode as the default theme. + if (!ImGui::Checkbox("Dark Mode", &dark_mode)) + { + if (!dark_mode) { - setBulletText("You clicked the button"); - //ImGui::BulletText("You clicked the button!"); + ImGui::StyleColorsDark(); + ImGui::BulletText("On"); } - else - { - ImGui::BulletText("Button not pressed."); - } - - ImGui::Separator(); - - - // This below works for a dark mode toggle. - // 5-16-2024 @ 9:14PM - ImGui::Checkbox("Dark Mode", &toggle_text); - - if (toggle_text) + else { ImGui::StyleColorsLight(); ImGui::BulletText("Off"); } - else - { - ImGui::StyleColorsDark(); - ImGui::BulletText("On"); - } - - // Possibly implement feature to read from a text file and write it to some output box. - ImGui::Text("Test"); - - //if (ImGui::Checkbox("Show Text", &toggle_text)) - //{ - // ImGui::BulletText("Hello"); - //} - //else - //{ - // ImGui::BulletText("Hola"); - //} - - - // How do I update this text in code? - // Like if a button is pressed. - //ImGui::Separator(); - //ImGui::BulletText("Test"); - } - if (ImGui::CollapsingHeader("Text File Functions")) +#else + ImGui::Checkbox("Dark Mode", &dark_mode); + if (dark_mode) { - ImGui::BulletText("I will add reading files, writing and more to this."); - ImGui::Separator(); - - // I almost got this working 5-17-2024 @ 3:14PM - // It doesn't print out all of the lines from the return value. - if (ImGui::Button("Test")) - { - std::cout << TextFileFunctions::printTextOutput("test.txt") << std::endl; - } - - + ImGui::StyleColorsLight(); + ImGui::BulletText("Off"); } + else + { + ImGui::StyleColorsDark(); - //if (ImGui::BeginMenu("My menu")) + ImGui::BulletText("On"); + } +#endif //_TEST + // Disable preprocessor +#undef _TEST + + // This works for toggling the demo window on and off + ImGui::Checkbox("Demo window", &show_demo_window); + + + // Possibly implement feature to read from a text file and write it to some output box. + //ImGui::Text("Test"); + + //const char *test = "Test"; + + //// I never did get this working yet. + //// https://www.programiz.com/cpp-programming/buffer + //char* buf = new char[40]; + ////char InputBuf[256]; + //// https://stackoverflow.com/questions/502856/whats-the-difference-between-size-t-and-int-in-c + //size_t num = 1; + ////char deref = &test; + + //// This doesn't work right. + //if (ImGui::InputText("##Username", buf, num)) //{ - // //ImGui::BulletText("You should see this"); - // ImGui::MenuItem("test", NULL); - // ImGui::EndMenu(); + // //std::cout << buf; //} - } ImGui::End(); + // This works. + if (ImGui::IsMousePosValid()) + ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + else + ImGui::Text("Mouse pos: "); + + //if (ImGui::Checkbox("Show Text", &toggle_text)) + //{ + // ImGui::BulletText("Hello"); + //} + //else + //{ + // ImGui::BulletText("Hola"); + //} + + + // How do I update this text in code? + // Like if a button is pressed. + //ImGui::Separator(); + //ImGui::BulletText("Test"); + + +#ifdef _TEST + ImGui::Checkbox("Define Test", &define_test); + + if (define_test) + { + ImGui::Text("Value of limit is: " + LIMIT); + std::cout << "Value of limit is " << LIMIT; + } +#endif //_TEST + + } + + // End main test menu + + + + // Text file functions test menu + if (ImGui::CollapsingHeader("Text File Functions")) + { + ImGui::BulletText("I will add reading files, writing and more to this."); + ImGui::Separator(); + + // I almost got this working 5-17-2024 @ 3:14PM + // It doesn't print out all of the lines from the return value. + if (ImGui::Button("Test")) + { + TextFileFunctions::printTextOutput("test.txt"); + //std::cout << TextFileFunctions::printTextOutput("test.txt") << std::endl; + } + } + // End Text file functions test menu + + //if (ImGui::BeginMenu("My menu")) + //{ + // //ImGui::BulletText("You should see this"); + // ImGui::MenuItem("test", NULL); + // ImGui::EndMenu(); + //} + + + + } + // End ImGui + ImGui::End(); // Rendering ImGui::EndFrame(); @@ -283,6 +466,9 @@ int main(int, char**) ::UnregisterClassW(wc.lpszClassName, wc.hInstance); return 0; +#endif //_TEST + + } // Helper functions @@ -353,3 +539,38 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) } return ::DefWindowProcW(hWnd, msg, wParam, lParam); } + +#endif //_DIRECTX9 + +#else + +#include +#include + + + +// Main code +// I moved the DirectX9 code into the test/directx9_test.cpp file, +// The code above is disabled with a preprocessor. + +#ifdef _DIRECTX9 +#include "test/directx9_test.h" +#endif //_DIRECTX9 + +#ifdef _OPENGL +#include "test/opengl_test.h" +#endif //_OPENGL + +int main(int, char**) +{ +#ifdef _DIRECTX9 + DirectX9Test::directX9Test(); +#endif //_DIRECTX9 + +#ifdef _OPENGL + OpenGLTest::openGLTest(); +#endif //_OPENGL + + //std::cout << "Hello World"; +} +#endif // _TEST \ No newline at end of file diff --git a/imgui.ini b/imgui.ini index 7407f47..dfc7013 100644 --- a/imgui.ini +++ b/imgui.ini @@ -4,7 +4,7 @@ Size=400,400 Collapsed=1 [Window][Dear ImGui Demo] -Pos=654,43 +Pos=652,43 Size=550,680 [Window][Hello, world!] @@ -12,7 +12,7 @@ Pos=116,183 Size=339,180 [Window][My new window] -Pos=48,170 +Pos=10,55 Size=517,436 [Window][Example: Console] @@ -35,3 +35,14 @@ Size=499,136 IsChild=1 Size=200,100 +[Table][0x64418101,3] +RefScale=13 +Column 0 Width=63 +Column 1 Width=63 +Column 2 Width=63 + +[Table][0xE0773582,3] +Column 0 Weight=1.0000 +Column 1 Weight=1.0000 +Column 2 Weight=1.0000 + diff --git a/links.txt b/links.txt new file mode 100644 index 0000000..b879e9e --- /dev/null +++ b/links.txt @@ -0,0 +1,3 @@ +ImGui C++ (Used for this project): https://github.com/ocornut/imgui + +C++ Naming scheme: https://manual.gromacs.org/documentation/2019/dev-manual/naming.html diff --git a/test/directx9_test.cpp b/test/directx9_test.cpp new file mode 100644 index 0000000..c503102 --- /dev/null +++ b/test/directx9_test.cpp @@ -0,0 +1,552 @@ +#include "directx9_test.h" + +// I would like to move opengl and directx into their own classes. +// So I can switch between them and the main file won't be so messy. + +#ifndef _TEST +#define _TEST +#endif + +#ifndef _DIRECTX9 +//#define _DIRECTX9 +#endif + +#ifdef _DIRECTX9 +#ifdef _TEST +// Dear ImGui: standalone example application for DirectX 9 + +// Learn about Dear ImGui: +// - FAQ https://dearimgui.com/faq +// - Getting Started https://dearimgui.com/getting-started +// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). +// - Introduction, links and more at the top of imgui.cpp + + + +#include "imgui.h" +#include "imgui_impl_dx9.h" + +#if _WIN32 +#include "imgui_impl_win32.h" +#include +#endif + +#include +#include + +#include +#include +#include + +#include "../util/textFileFunctions.h" + +// https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/ +// Test macros +#define LIMIT 5 + +// Test code +#ifndef _TEST +//#define _TEST +#endif + +// Data +static LPDIRECT3D9 g_pD3D = nullptr; +static LPDIRECT3DDEVICE9 g_pd3dDevice = nullptr; +static UINT g_ResizeWidth = 0, g_ResizeHeight = 0; +static D3DPRESENT_PARAMETERS g_d3dpp = {}; + +// Forward declarations of helper functions +bool CreateDeviceD3D(HWND hWnd); +void CleanupDeviceD3D(); +void ResetDevice(); +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +static void HelpMarker(const char* desc) +{ + ImGui::TextDisabled("(?)"); + if (ImGui::BeginItemTooltip()) + { + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(desc); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } +} + +// Windows specific features +// https://stackoverflow.com/questions/41600981/how-do-i-check-if-a-key-is-pressed-on-c +#ifdef _WIN32 +SHORT keyState = GetKeyState(VK_CAPITAL/*(caps lock)*/); +bool isToggled = keyState & 1; +bool isDown = keyState & 0x8000; +//[DllImport("kernel32.dll")] +//static extern IntPtr GetConsoleWindow(); +#endif + + +// Will this work? + +static void setBulletText(const char* text) +{ + ImGui::BulletText(text); +} + +// + +int test() +{ + int num1 = 5; + int num2 = 10; + + return num1 + num2; +} + +// https://www.geeksforgeeks.org/converting-number-to-string-in-cpp/ +// Prints the value of +std::string testString1() +{ + int num1 = 5; + int num2 = 10; + int sum = num1 + num2; + std::string num1_string = std::to_string(num1); + std::string num2_string = std::to_string(num2); + std::string sum_string = std::to_string(sum); + + return "The value of " + num1_string + " + " + num2_string + " = " + sum_string; +} + + +// imgui_demo line 256 +static void ShowWindow(bool* p_open) +{ + static bool show_main_menu = false; + + if (show_main_menu) + { + if (ImGui::Begin("Test")) + { + ImGui::Text("Hello World!"); + } + } + + if (!ImGui::Begin("Test", p_open)) + { + + ImGui::End(); + return; + } + + +} + +// Main code +void DirectX9Test::directX9Test() +{ + +#ifdef _TEST + std::cout << testString1(); +#endif + + // Create application window + //ImGui_ImplWin32_EnableDpiAwareness(); + WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr }; + ::RegisterClassExW(&wc); + HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui DirectX9 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr); + + // Initialize Direct3D + if (!CreateDeviceD3D(hwnd)) + { + CleanupDeviceD3D(); + ::UnregisterClassW(wc.lpszClassName, wc.hInstance); + //return 1; + } + + // Show the window + ::ShowWindow(hwnd, SW_SHOWDEFAULT); + ::UpdateWindow(hwnd); + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsLight(); + + // Setup Platform/Renderer backends + ImGui_ImplWin32_Init(hwnd); + ImGui_ImplDX9_Init(g_pd3dDevice); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering. + // - Read 'docs/FONTS.md' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != nullptr); + + // Our state + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Show window + // Main loop + bool done = false; + bool button1_clicked = false; + static bool show_app_main_menu_bar = false; + //static bool toggle_text = false; + static bool dark_mode = false; + static bool define_test = false; + + while (!done) + { + // Poll and handle messages (inputs, window resize, etc.) + // See the WndProc() function below for our to dispatch events to the Win32 backend. + MSG msg; + while (::PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE)) + { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + if (msg.message == WM_QUIT) + done = true; + } + if (done) + break; + + // Handle window resize (we don't resize directly in the WM_SIZE handler) + if (g_ResizeWidth != 0 && g_ResizeHeight != 0) + { + g_d3dpp.BackBufferWidth = g_ResizeWidth; + g_d3dpp.BackBufferHeight = g_ResizeHeight; + g_ResizeWidth = g_ResizeHeight = 0; + ResetDevice(); + } + + // Start the Dear ImGui frame + ImGui_ImplDX9_NewFrame(); + ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); + + // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). + if (show_demo_window) + ImGui::ShowDemoWindow(&show_demo_window); + + if (ImGui::Begin("My new window", nullptr, ImGuiWindowFlags_MenuBar)) + { + // Menu bar + if (ImGui::BeginMenuBar()) + { + if (ImGui::BeginMenu("Test")) + { + ImGui::MenuItem("Main menu bar", NULL, &show_app_main_menu_bar); + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + } + + // Main testing header. + if (ImGui::CollapsingHeader("test1")) + { + ImGui::BulletText("Hello, this should show up."); + ImGui::Separator(); + + // Menu toggle button + if (ImGui::Button("Menu toggle")) + { + std::cout << "Test" << std::endl; + // How would I check if dark mode is enabled? + //if (ImGui::GetStyle == ImGui) { + //ImGui::StyleColorsLight(); + //} + //else + // { + //ImGui::StyleColorsDark(); + //} + + } + + // I couldn't figure this out yet. + // This shows up for a second then dies. + ImGui::Separator(); + if (!ImGui::Button("Click")) + { + button1_clicked = false; + } + else + { + button1_clicked = true; + } + + if (!button1_clicked) + { + setBulletText("You clicked the button"); + } + else + { + ImGui::BulletText("Button not pressed."); + + //ImGui::BulletText("You clicked the button!"); + } + //} + + //if (ImGui::Button("Click")) + //{ + + // setBulletText("You clicked the button"); + // //ImGui::BulletText("You clicked the button!"); + //} + //else + //{ + // ImGui::BulletText("Button not pressed."); + //} + + ImGui::Separator(); + + + // This below works for a dark mode toggle. + // 5-16-2024 @ 9:14PM + +#ifndef _TEST +#define _TEST +#endif + + +#ifdef _TEST + // Well the checkbox is inverted lol, oh well I'll fix it later. + // If it is checked it turns off dark mode, I guess its because I have dark mode as the default theme. + if (!ImGui::Checkbox("Dark Mode", &dark_mode)) + { + if (!dark_mode) + { + + ImGui::StyleColorsDark(); + ImGui::BulletText("On"); + } + else + { + ImGui::StyleColorsLight(); + ImGui::BulletText("Off"); + } + } + +#else + ImGui::Checkbox("Dark Mode", &dark_mode); + if (dark_mode) + { + ImGui::StyleColorsLight(); + ImGui::BulletText("Off"); + } + else + { + ImGui::StyleColorsDark(); + + ImGui::BulletText("On"); + } +#endif //_TEST + // Disable preprocessor +#undef _TEST + + // This works for toggling the demo window on and off + ImGui::Checkbox("Demo window", &show_demo_window); + + + // Possibly implement feature to read from a text file and write it to some output box. + //ImGui::Text("Test"); + + //const char *test = "Test"; + + //// I never did get this working yet. + //// https://www.programiz.com/cpp-programming/buffer + //char* buf = new char[40]; + ////char InputBuf[256]; + //// https://stackoverflow.com/questions/502856/whats-the-difference-between-size-t-and-int-in-c + //size_t num = 1; + ////char deref = &test; + + //// This doesn't work right. + //if (ImGui::InputText("##Username", buf, num)) + //{ + // //std::cout << buf; + //} + + + + // This works. + if (ImGui::IsMousePosValid()) + ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + else + ImGui::Text("Mouse pos: "); + + //if (ImGui::Checkbox("Show Text", &toggle_text)) + //{ + // ImGui::BulletText("Hello"); + //} + //else + //{ + // ImGui::BulletText("Hola"); + //} + + + // How do I update this text in code? + // Like if a button is pressed. + //ImGui::Separator(); + //ImGui::BulletText("Test"); + + +#ifdef _TEST + ImGui::Checkbox("Define Test", &define_test); + + if (define_test) + { + ImGui::Text("Value of limit is: " + LIMIT); + std::cout << "Value of limit is " << LIMIT; + } +#endif //_TEST + + } + + // End main test menu + + + + // Text file functions test menu + if (ImGui::CollapsingHeader("Text File Functions")) + { + ImGui::BulletText("I will add reading files, writing and more to this."); + ImGui::Separator(); + + // I almost got this working 5-17-2024 @ 3:14PM + // It doesn't print out all of the lines from the return value. + if (ImGui::Button("Test")) + { + TextFileFunctions::printTextOutput("test.txt"); + //std::cout << TextFileFunctions::printTextOutput("test.txt") << std::endl; + } + } + // End Text file functions test menu + + //if (ImGui::BeginMenu("My menu")) + //{ + // //ImGui::BulletText("You should see this"); + // ImGui::MenuItem("test", NULL); + // ImGui::EndMenu(); + //} + + + + } + // End ImGui + ImGui::End(); + + // Rendering + ImGui::EndFrame(); + g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE); + g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); + g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE); + D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x * clear_color.w * 255.0f), (int)(clear_color.y * clear_color.w * 255.0f), (int)(clear_color.z * clear_color.w * 255.0f), (int)(clear_color.w * 255.0f)); + g_pd3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0); + if (g_pd3dDevice->BeginScene() >= 0) + { + ImGui::Render(); + ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); + g_pd3dDevice->EndScene(); + } + HRESULT result = g_pd3dDevice->Present(nullptr, nullptr, nullptr, nullptr); + + // Handle loss of D3D9 device + if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) + ResetDevice(); + } + + ImGui_ImplDX9_Shutdown(); + ImGui_ImplWin32_Shutdown(); + ImGui::DestroyContext(); + + CleanupDeviceD3D(); + ::DestroyWindow(hwnd); + ::UnregisterClassW(wc.lpszClassName, wc.hInstance); +} + +// Helper functions + +bool CreateDeviceD3D(HWND hWnd) +{ + if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == nullptr) + return false; + + // Create the D3DDevice + ZeroMemory(&g_d3dpp, sizeof(g_d3dpp)); + g_d3dpp.Windowed = TRUE; + g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // Need to use an explicit format with alpha if needing per-pixel alpha composition. + g_d3dpp.EnableAutoDepthStencil = TRUE; + g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16; + g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Present with vsync + //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync, maximum unthrottled framerate + if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0) + return false; + + return true; +} + +void CleanupDeviceD3D() +{ + if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = nullptr; } + if (g_pD3D) { g_pD3D->Release(); g_pD3D = nullptr; } +} + +void ResetDevice() +{ + ImGui_ImplDX9_InvalidateDeviceObjects(); + HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp); + if (hr == D3DERR_INVALIDCALL) + IM_ASSERT(0); + ImGui_ImplDX9_CreateDeviceObjects(); +} + +// Forward declare message handler from imgui_impl_win32.cpp +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +// Win32 message handler +// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. +// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. +// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) + return true; + + switch (msg) + { + case WM_SIZE: + if (wParam == SIZE_MINIMIZED) + return 0; + g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize + g_ResizeHeight = (UINT)HIWORD(lParam); + return 0; + case WM_SYSCOMMAND: + if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu + return 0; + break; + case WM_DESTROY: + ::PostQuitMessage(0); + return 0; + } + return ::DefWindowProcW(hWnd, msg, wParam, lParam); +} + +#endif //_TEST +#endif //_DIRECTX9 \ No newline at end of file diff --git a/test/directx9_test.h b/test/directx9_test.h new file mode 100644 index 0000000..c600a6b --- /dev/null +++ b/test/directx9_test.h @@ -0,0 +1,5 @@ +#pragma once +class DirectX9Test { +public: + static void directX9Test(); +}; \ No newline at end of file diff --git a/test/opengl_test.cpp b/test/opengl_test.cpp new file mode 100644 index 0000000..1c6f68e --- /dev/null +++ b/test/opengl_test.cpp @@ -0,0 +1,209 @@ +#include "opengl_test.h" + +// Moving opengl test into this file until I'm ready to mess with it. +// 5-25-2024 @ 12:21PM + +#ifndef _OPENGL +//#define _OPENGL +#endif + +// I never did get this one working. +// Keeps giving linker errors and library not found errors. +#ifdef _OPENGL + +// Dear ImGui: standalone example application for GLFW + OpenGL 3, using programmable pipeline +// (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) + +// Learn about Dear ImGui: +// - FAQ https://dearimgui.com/faq +// - Getting Started https://dearimgui.com/getting-started +// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). +// - Introduction, links and more at the top of imgui.cpp + +#include "imgui.h" +#include "imgui_impl_glfw.h" +#include "imgui_impl_opengl3.h" +#include +#define GL_SILENCE_DEPRECATION +#if defined(IMGUI_IMPL_OPENGL_ES2) +#include +#endif +#include // Will drag system OpenGL headers + +// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers. +// To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma. +// 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. +#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) +#pragma comment(lib, "legacy_stdio_definitions") +#endif + +// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details. +#ifdef __EMSCRIPTEN__ +#include "../libs/emscripten/emscripten_mainloop_stub.h" +#endif + +static void glfw_error_callback(int error, const char* description) +{ + fprintf(stderr, "GLFW Error %d: %s\n", error, description); +} + +// Main code +void OpenGLTest::openGLTest() +{ + glfwSetErrorCallback(glfw_error_callback); + if (!glfwInit()) + + // Decide GL+GLSL versions +#if defined(IMGUI_IMPL_OPENGL_ES2) + // GL ES 2.0 + GLSL 100 + const char* glsl_version = "#version 100"; + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); +#elif defined(__APPLE__) + // GL 3.2 + GLSL 150 + const char* glsl_version = "#version 150"; + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac +#else + // GL 3.0 + GLSL 130 + const char* glsl_version = "#version 130"; + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only + //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only +#endif + + // Create window with graphics context + GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", nullptr, nullptr); + if (window == nullptr) + glfwMakeContextCurrent(window); + glfwSwapInterval(1); // Enable vsync + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsLight(); + + // Setup Platform/Renderer backends + ImGui_ImplGlfw_InitForOpenGL(window, true); +#ifdef __EMSCRIPTEN__ + ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas"); +#endif + ImGui_ImplOpenGL3_Init(glsl_version); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering. + // - Read 'docs/FONTS.md' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + // - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details. + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != nullptr); + + // Our state + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop +#ifdef __EMSCRIPTEN__ + // For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file. + // You may manually call LoadIniSettingsFromMemory() to load settings from your own storage. + io.IniFilename = nullptr; + EMSCRIPTEN_MAINLOOP_BEGIN +#else + while (!glfwWindowShouldClose(window)) +#endif + { + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + glfwPollEvents(); + + // Start the Dear ImGui frame + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + + // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). + if (show_demo_window) + ImGui::ShowDemoWindow(&show_demo_window); + + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. + { + static float f = 0.0f; + static int counter = 0; + + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + + ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) + ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + ImGui::Checkbox("Another Window", &show_another_window); + + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f + ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color + + if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) + counter++; + ImGui::SameLine(); + ImGui::Text("counter = %d", counter); + + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + ImGui::End(); + } + + // 3. Show another simple window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) + ImGui::Text("Hello from another window!"); + if (ImGui::Button("Close Me")) + show_another_window = false; + ImGui::End(); + } + + // Rendering + ImGui::Render(); + int display_w, display_h; + glfwGetFramebufferSize(window, &display_w, &display_h); + glViewport(0, 0, display_w, display_h); + glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); + glClear(GL_COLOR_BUFFER_BIT); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + glfwSwapBuffers(window); + } +#ifdef __EMSCRIPTEN__ + EMSCRIPTEN_MAINLOOP_END; +#endif + + // Cleanup + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + + glfwDestroyWindow(window); + glfwTerminate(); +} + + +#endif //_OPENGL \ No newline at end of file diff --git a/test/opengl_test.h b/test/opengl_test.h new file mode 100644 index 0000000..b400ed4 --- /dev/null +++ b/test/opengl_test.h @@ -0,0 +1,5 @@ +#pragma once +class OpenGLTest{ +public: + static void openGLTest(); +}; \ No newline at end of file