Move all files into src folder.

Add defines.h for menu titles and window title.
Reorganize project quite a bit, refactor code.
Add _TEST2 preprocessor, add helpers.cpp and helpers.h.
Partially make OpenGL work for Windows.
Rename Solution to KCNet-ImGui-Test.
This commit is contained in:
kelson8 2025-01-09 20:12:07 -05:00
parent 938e61f01a
commit 294937a0c6
26 changed files with 767 additions and 206 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188 VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGuiTestCPP", "ConsoleAppTest.vcxproj", "{6E4373C3-3E97-4007-9B8B-597F55378360}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGuiTestCPP", "KCNet-ImGui-Test.vcxproj", "{0BED48FD-945D-4084-80AB-20EC84A145DE}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -17,22 +17,22 @@ Global
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug|x64.ActiveCfg = Debug|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug|x64.ActiveCfg = Debug|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug|x64.Build.0 = Debug|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug|x64.Build.0 = Debug|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug|x86.ActiveCfg = Debug|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug|x86.ActiveCfg = Debug|Win32
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug|x86.Build.0 = Debug|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug|x86.Build.0 = Debug|Win32
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x64.ActiveCfg = Debug-Directx9|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-Directx9|x64.ActiveCfg = Debug-Directx9|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x64.Build.0 = Debug-Directx9|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-Directx9|x64.Build.0 = Debug-Directx9|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x86.ActiveCfg = Debug-Directx9|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-Directx9|x86.ActiveCfg = Debug-Directx9|Win32
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-Directx9|x86.Build.0 = Debug-Directx9|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-Directx9|x86.Build.0 = Debug-Directx9|Win32
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x64.ActiveCfg = Debug-OpenGL|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-OpenGL|x64.ActiveCfg = Debug-OpenGL|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x64.Build.0 = Debug-OpenGL|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-OpenGL|x64.Build.0 = Debug-OpenGL|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x86.ActiveCfg = Debug-OpenGL|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-OpenGL|x86.ActiveCfg = Debug-OpenGL|Win32
{6E4373C3-3E97-4007-9B8B-597F55378360}.Debug-OpenGL|x86.Build.0 = Debug-OpenGL|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Debug-OpenGL|x86.Build.0 = Debug-OpenGL|Win32
{6E4373C3-3E97-4007-9B8B-597F55378360}.Release|x64.ActiveCfg = Release|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Release|x64.ActiveCfg = Release|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Release|x64.Build.0 = Release|x64 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Release|x64.Build.0 = Release|x64
{6E4373C3-3E97-4007-9B8B-597F55378360}.Release|x86.ActiveCfg = Release|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Release|x86.ActiveCfg = Release|Win32
{6E4373C3-3E97-4007-9B8B-597F55378360}.Release|x86.Build.0 = Release|Win32 {0BED48FD-945D-4084-80AB-20EC84A145DE}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -37,10 +37,10 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion> <VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<ProjectGuid>{6e4373c3-3e97-4007-9b8b-597f55378360}</ProjectGuid> <ProjectGuid>{0BED48FD-945D-4084-80AB-20EC84A145DE}</ProjectGuid>
<RootNamespace>ConsoleAppTest</RootNamespace> <RootNamespace>ConsoleAppTest</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>ImGuiTestCPP</ProjectName> <ProjectName>KCNet-ImGui-Test</ProjectName>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@ -130,12 +130,15 @@
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_OPENGL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>.\include\GLFW;.\lib\ImGui;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>glfw3.lib;glfw3dll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\lib\glfw\lib-vc2022\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -161,7 +164,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard> <LanguageStandard>stdcpplatest</LanguageStandard>
<AdditionalIncludeDirectories>lib\imgui\;lib\imgui\backends;include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>lib\imgui\;lib\imgui\backends;include\;.\util;.\test;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -204,7 +207,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Directx9|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Directx9|x64'">
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>lib\imgui\;lib\imgui\backends;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>lib\imgui\;lib\imgui\backends;.\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DIRECTX9</PreprocessorDefinitions> <PreprocessorDefinitions>_DIRECTX9</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
@ -220,7 +223,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="lib\ImGui\backends\imgui_impl_opengl3.cpp" /> <ClCompile Include="lib\ImGui\backends\imgui_impl_opengl3.cpp" />
<ClCompile Include="Main.cpp" /> <ClCompile Include="src\Main.cpp" />
<ClCompile Include="lib\ImGui\backends\imgui_impl_dx9.cpp" /> <ClCompile Include="lib\ImGui\backends\imgui_impl_dx9.cpp" />
<ClCompile Include="lib\ImGui\backends\imgui_impl_win32.cpp" /> <ClCompile Include="lib\ImGui\backends\imgui_impl_win32.cpp" />
<ClCompile Include="lib\ImGui\imgui.cpp" /> <ClCompile Include="lib\ImGui\imgui.cpp" />
@ -228,16 +231,32 @@
<ClCompile Include="lib\ImGui\imgui_draw.cpp" /> <ClCompile Include="lib\ImGui\imgui_draw.cpp" />
<ClCompile Include="lib\ImGui\imgui_tables.cpp" /> <ClCompile Include="lib\ImGui\imgui_tables.cpp" />
<ClCompile Include="lib\ImGui\imgui_widgets.cpp" /> <ClCompile Include="lib\ImGui\imgui_widgets.cpp" />
<ClCompile Include="menus\main_menu.cpp" /> <ClCompile Include="src\menus\main_menu.cpp" />
<ClCompile Include="test\constructor_test.cpp" /> <ClCompile Include="src\menus\text_menu.cpp" />
<ClCompile Include="test\directx9_test.cpp" /> <ClCompile Include="src\test\constructor_test.cpp" />
<ClCompile Include="test\opengl_test.cpp" /> <ClCompile Include="src\test\curl_test.cpp" />
<ClCompile Include="menus\text_menu.cpp" /> <ClCompile Include="src\test\directx9_test.cpp" />
<ClCompile Include="util\keystates.cpp" /> <ClCompile Include="src\test\http_lib_test.cpp" />
<ClCompile Include="util\text_file_functions.cpp" /> <ClCompile Include="src\test\opengl_test.cpp" />
<ClCompile Include="util\text_functions.cpp" /> <ClCompile Include="src\util\helpers.cpp" />
<ClCompile Include="src\util\keystates.cpp" />
<ClCompile Include="src\util\text_file_functions.cpp" />
<ClCompile Include="src\util\text_functions.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\menus\main_menu.h" />
<ClInclude Include="src\menus\pch.h" />
<ClInclude Include="src\menus\text_menu.h" />
<ClInclude Include="src\test\constructor_test.h" />
<ClInclude Include="src\test\curl_test.h" />
<ClInclude Include="src\test\defines.h" />
<ClInclude Include="src\test\directx9_test.h" />
<ClInclude Include="src\test\http_lib_test.h" />
<ClInclude Include="src\test\opengl_test.h" />
<ClInclude Include="src\util\helpers.h" />
<ClInclude Include="src\util\keystates.h" />
<ClInclude Include="src\util\text_file_functions.h" />
<ClInclude Include="src\util\text_functions.h" />
<ClInclude Include="lib\ImGui\backends\imgui_impl_dx9.h" /> <ClInclude Include="lib\ImGui\backends\imgui_impl_dx9.h" />
<ClInclude Include="lib\ImGui\backends\imgui_impl_opengl3.h" /> <ClInclude Include="lib\ImGui\backends\imgui_impl_opengl3.h" />
<ClInclude Include="lib\ImGui\backends\imgui_impl_opengl3_loader.h" /> <ClInclude Include="lib\ImGui\backends\imgui_impl_opengl3_loader.h" />
@ -248,15 +267,6 @@
<ClInclude Include="lib\ImGui\imstb_rectpack.h" /> <ClInclude Include="lib\ImGui\imstb_rectpack.h" />
<ClInclude Include="lib\ImGui\imstb_textedit.h" /> <ClInclude Include="lib\ImGui\imstb_textedit.h" />
<ClInclude Include="lib\ImGui\imstb_truetype.h" /> <ClInclude Include="lib\ImGui\imstb_truetype.h" />
<ClInclude Include="menus\main_menu.h" />
<ClInclude Include="menus\pch.h" />
<ClInclude Include="test\constructor_test.h" />
<ClInclude Include="test\directx9_test.h" />
<ClInclude Include="test\opengl_test.h" />
<ClInclude Include="menus\text_menu.h" />
<ClInclude Include="util\keystates.h" />
<ClInclude Include="util\text_file_functions.h" />
<ClInclude Include="util\text_functions.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="lib\ImGui\backends\imgui_impl_metal.mm" /> <None Include="lib\ImGui\backends\imgui_impl_metal.mm" />

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="src\Main.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\imgui.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\imgui_demo.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\imgui_draw.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\backends\imgui_impl_dx9.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\backends\imgui_impl_win32.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\backends\imgui_impl_opengl3.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\imgui_tables.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="lib\ImGui\imgui_widgets.cpp">
<Filter>src\lib\ImGui</Filter>
</ClCompile>
<ClCompile Include="src\util\helpers.cpp">
<Filter>src\util</Filter>
</ClCompile>
<ClCompile Include="src\util\keystates.cpp">
<Filter>src\util</Filter>
</ClCompile>
<ClCompile Include="src\util\text_file_functions.cpp">
<Filter>src\util</Filter>
</ClCompile>
<ClCompile Include="src\util\text_functions.cpp">
<Filter>src\util</Filter>
</ClCompile>
<ClCompile Include="src\test\opengl_test.cpp">
<Filter>src\test</Filter>
</ClCompile>
<ClCompile Include="src\test\http_lib_test.cpp">
<Filter>src\test</Filter>
</ClCompile>
<ClCompile Include="src\test\directx9_test.cpp">
<Filter>src\test</Filter>
</ClCompile>
<ClCompile Include="src\test\curl_test.cpp">
<Filter>src\test</Filter>
</ClCompile>
<ClCompile Include="src\test\constructor_test.cpp">
<Filter>src\test</Filter>
</ClCompile>
<ClCompile Include="src\menus\main_menu.cpp">
<Filter>src\menus</Filter>
</ClCompile>
<ClCompile Include="src\menus\text_menu.cpp">
<Filter>src\menus</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="lib\ImGui\imconfig.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\imgui.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\backends\imgui_impl_dx9.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\backends\imgui_impl_opengl3_loader.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\backends\imgui_impl_opengl3.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\imgui_internal.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\backends\imgui_impl_win32.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\imstb_rectpack.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\imstb_textedit.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="lib\ImGui\imstb_truetype.h">
<Filter>src\lib\ImGui</Filter>
</ClInclude>
<ClInclude Include="src\util\helpers.h">
<Filter>src\util</Filter>
</ClInclude>
<ClInclude Include="src\util\keystates.h">
<Filter>src\util</Filter>
</ClInclude>
<ClInclude Include="src\util\text_file_functions.h">
<Filter>src\util</Filter>
</ClInclude>
<ClInclude Include="src\util\text_functions.h">
<Filter>src\util</Filter>
</ClInclude>
<ClInclude Include="src\test\opengl_test.h">
<Filter>src\test</Filter>
</ClInclude>
<ClInclude Include="src\test\http_lib_test.h">
<Filter>src\test</Filter>
</ClInclude>
<ClInclude Include="src\test\directx9_test.h">
<Filter>src\test</Filter>
</ClInclude>
<ClInclude Include="src\test\defines.h">
<Filter>src\test</Filter>
</ClInclude>
<ClInclude Include="src\test\curl_test.h">
<Filter>src\test</Filter>
</ClInclude>
<ClInclude Include="src\test\constructor_test.h">
<Filter>src\test</Filter>
</ClInclude>
<ClInclude Include="src\menus\main_menu.h">
<Filter>src\menus</Filter>
</ClInclude>
<ClInclude Include="src\menus\pch.h">
<Filter>src\menus</Filter>
</ClInclude>
<ClInclude Include="src\menus\text_menu.h">
<Filter>src\menus</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{96d2e389-bfd0-443a-af14-d02226755b89}</UniqueIdentifier>
</Filter>
<Filter Include="src\util">
<UniqueIdentifier>{74c54db3-2a79-45b7-ace5-bcbf01fa1044}</UniqueIdentifier>
</Filter>
<Filter Include="src\test">
<UniqueIdentifier>{caee360c-2fdb-4dc0-b9d0-11cc1c076d58}</UniqueIdentifier>
</Filter>
<Filter Include="src\menus">
<UniqueIdentifier>{f4aa985e-3c6f-454e-b800-c186b9f15084}</UniqueIdentifier>
</Filter>
<Filter Include="src\lib">
<UniqueIdentifier>{980dc627-529c-4841-abd5-7fa717911800}</UniqueIdentifier>
</Filter>
<Filter Include="src\include">
<UniqueIdentifier>{91557761-2f06-4a06-b8fa-506b1ae06724}</UniqueIdentifier>
</Filter>
<Filter Include="src\lib\ImGui">
<UniqueIdentifier>{1804e534-3e6f-47ec-bf39-30070e52ce27}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="lib\ImGui\backends\imgui_impl_metal.mm">
<Filter>src\lib\ImGui</Filter>
</None>
</ItemGroup>
</Project>

View File

@ -1,42 +0,0 @@
#include <iostream>
#include <string>
#include <print>
// Fixes it to where I don't need to use std::cout and std::string
using namespace std;
int main()
{
// This is a way to define multiple variables at once
int player1_score = 25, player2_score = 40;
// Variable declaration
int player3_score;
// Variable initialisation
player3_score = 22;
// Constants (These can't be changed later)
const string playername = "kelson8";
// Pointer test (Both of these are valid)
const int *ptr = &player2_score;
const string* ptr1 = &playername;
// "endl" makes a new line
// either "cout" or "printf" can be used to output text.
//cout << "Hello " << playername << " welcome to the party!" << endl;
//cout << "Nice, you got a high score of " << player2_score << endl;
// This needs the * on it or it don't work right since it's a pointer, I still don't fully understand how these work.
cout << *ptr1 << " " << *ptr;
// Newest C++ preview required for this to work.
//std::print("Hello {}, welcome to the party!", playername);
//std::print("Test");
// Why doesn't this printf work right?
//printf("Hello %s welcome to the party", playername);
//printf("Nice, you got a high score of %s", player2_score);
return 0;
}

View File

@ -1,6 +1,8 @@
// Test main method can go in here, can be useful for quick testing in the console. // Test main method can go in here, can be useful for quick testing in the console.
//#define _TEST //#define _TEST
// TODO Fix this to work... It just dies?
// TODO Actually fix Linux support with CMake, make this build on Windows and Linux with CMake.
#ifdef _TEST #ifdef _TEST
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
@ -22,7 +24,7 @@ int main(int, char**)
// I moved the DirectX9 code into the test/directx9_test.cpp file, // I moved the DirectX9 code into the test/directx9_test.cpp file,
#ifdef _DIRECTX9 #ifdef _DIRECTX9
#include "test/directx9_test.h" #include "./test/directx9_test.h"
#endif //_DIRECTX9 #endif //_DIRECTX9
#ifdef _OPENGL #ifdef _OPENGL
@ -64,6 +66,9 @@ int main(int, char**)
#ifdef _TEST1 #ifdef _TEST1
#ifdef _DIRECTX9 #ifdef _DIRECTX9
// I forgot about making a test DLL for this project.
// DLL initialize
HINSTANCE hinstDLL; HINSTANCE hinstDLL;
DLLPROC HelloWorld; DLLPROC HelloWorld;
BOOL fFreeDLL; BOOL fFreeDLL;
@ -112,6 +117,8 @@ int main(int, char**)
fFreeDLL = FreeLibrary(hinstDLL); fFreeDLL = FreeLibrary(hinstDLL);
} }
// End DLL initialize
#endif //_DIRECTX9 #endif //_DIRECTX9
#endif //_TEST1 #endif //_TEST1

View File

@ -4,7 +4,7 @@
#if _WIN32 #if _WIN32
#include "imgui_impl_win32.h" #include "imgui_impl_win32.h"
#include <Windows.h> #include <Windows.h>
#include "../util/keystates.h" #include "./util/keystates.h"
#endif #endif
#include <d3d9.h> #include <d3d9.h>
@ -14,16 +14,28 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "../util/text_file_functions.h"
#include "../test/directx9_test.h" // Utility functions
#include "../util/text_functions.h" #include "./util/text_functions.h"
#include "main_menu.h" #include "./util/text_file_functions.h"
// Test functions
#include "./test/directx9_test.h"
// New test
#include "./test/constructor_test.h"
// OpenGL
#include "./test/opengl_test.h"
// Menus
#include "./menus/main_menu.h"
// https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/ // https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/
// Test macros // Test macros
#define LIMIT 5 #define LIMIT 5
// Boolean values // Boolean values
// DirectX9Test
bool DirectX9Test::show_demo_window = false; bool DirectX9Test::show_demo_window = false;
bool DirectX9Test::button1_clicked = false; bool DirectX9Test::button1_clicked = false;
bool DirectX9Test::show_app_main_menu_bar = false; bool DirectX9Test::show_app_main_menu_bar = false;
@ -32,17 +44,48 @@ bool DirectX9Test::dark_mode = true; // I have dark mode enabled, I'll leave thi
bool DirectX9Test::define_test = false; bool DirectX9Test::define_test = false;
bool DirectX9Test::list_values = false; bool DirectX9Test::list_values = false;
// OpenGLTest
bool OpenGLTest::show_demo_window = false;
// //
// TODO Setup test for storing an array of pointers // TODO Setup test for storing an array of pointers
// TODO Try to play around with PS3 homebrew or Nintendo Switch homebrew. // TODO Try to play around with PS3 homebrew or Nintendo Switch homebrew.
// This doesn't work
#ifdef _TEST1
/// <summary>
/// Testing vsprintf_s
/// https://www.educative.io/answers/what-is-vsprintfs-in-c
/// </summary>
/// <returns></returns>
int call_vsprintf_s(char* buffer, size_t numberOfElements, char* format)
{
int result;
va_list argList;
va_start(argList, format);
result = vsprintf_s(buffer, numberOfElements, format, argList);
va_end(argList);
return result;
}
#endif //_TEST1
// Enable this for test constructor once I get it fixed.
//#define _TEST1
void MainMenu::MainMenuTest() { void MainMenu::MainMenuTest() {
ImGuiIO& io = ImGui::GetIO(); (void)io; ImGuiIO& io = ImGui::GetIO(); (void)io;
//if (ImGui::Begin("KCNet ImGui", nullptr, ImGuiWindowFlags_MenuBar)) //if (ImGui::Begin("KCNet ImGui", nullptr, ImGuiWindowFlags_MenuBar))
//{ //{
// Constructor test, kills ImGui.
#ifdef _TEST1 // TODO Fixme
Car car1("Ford", "Mustang", 1969);
#endif //_TEST1
// Menu bar // Menu bar
if (ImGui::BeginMenuBar()) if (ImGui::BeginMenuBar())
{ {
@ -60,7 +103,17 @@ void MainMenu::MainMenuTest() {
ImGui::BulletText("Hello, this should show up."); ImGui::BulletText("Hello, this should show up.");
ImGui::Separator(); ImGui::Separator();
// This works
// TODO Fix constructor test to work, this kills it instantly when opening test1.
#ifdef _TEST1 // TODO Fixme
ImGui::BulletText("Car brand: %s, Car type: %s, Car year: %s", car1.brand, car1.model, car1.year);
//ImGui::Text("Car brand: %s, Car type: %s, Car year: %s", car1.brand, car1.model, car1.year);
#endif //_TEST1
//#undef _TEST1
// This works, freezes the window until clicked though.
if (ImGui::Button("Windows Msg Box")) if (ImGui::Button("Windows Msg Box"))
{ {
MessageBox(NULL, TEXT("Hello From ImGui, a MessageBox"), MessageBox(NULL, TEXT("Hello From ImGui, a MessageBox"),
@ -127,9 +180,11 @@ void MainMenu::MainMenuTest() {
// Dark mode toggle // Dark mode toggle
///////////// /////////////
// Is this really needed?
#ifndef _TEST #ifndef _TEST
#define _TEST #define _TEST
#endif #endif
#ifdef _TEST #ifdef _TEST
@ -171,7 +226,14 @@ void MainMenu::MainMenuTest() {
#undef _TEST #undef _TEST
// This works for toggling the demo window on and off // This works for toggling the demo window on and off
#ifdef _OPENGL
ImGui::Checkbox("Demo window", &OpenGLTest::show_demo_window);
#endif
#ifdef _DIRECTX9
ImGui::Checkbox("Demo window", &DirectX9Test::show_demo_window); ImGui::Checkbox("Demo window", &DirectX9Test::show_demo_window);
#endif
// Possibly implement feature to read from a text file and write it to some output box. // Possibly implement feature to read from a text file and write it to some output box.
//ImGui::Text("Test"); //ImGui::Text("Test");
@ -289,7 +351,9 @@ void MainMenu::MainMenuTest() {
//#undef _TEST //#undef _TEST
// Oh this is how I'm doing checkboxes.
// Lists out the values from the charTest
ImGui::Checkbox("List values", &DirectX9Test::list_values); ImGui::Checkbox("List values", &DirectX9Test::list_values);
if (DirectX9Test::list_values) if (DirectX9Test::list_values)
@ -305,10 +369,31 @@ void MainMenu::MainMenuTest() {
{ {
ImGui::Text("Disabled"); ImGui::Text("Disabled");
} }
//
} }
ImGui::Separator(); ImGui::Separator();
// New
const int vsprintBufferSize = 1024;
char* vsPrintBuffer = new char[vsprintBufferSize];
if (ImGui::CollapsingHeader("test2"))
{
// Disabled, doesn't work.
#ifdef _TEST1
if (ImGui::Button("Test"))
{
char format[] = "Hello %s";
std::cout << "Hello" << std::endl;
call_vsprintf_s(vsPrintBuffer, 15, format);
}
#endif //_TEST1
}
//
// This works for a column, having multiple items on the same row. // This works for a column, having multiple items on the same row.
ImGui::Columns(2); ImGui::Columns(2);
ImGui::Text("Hello"); ImGui::Text("Hello");
@ -317,4 +402,5 @@ void MainMenu::MainMenuTest() {
ImGui::Columns(1); ImGui::Columns(1);
//} //}
} }

View File

@ -4,7 +4,7 @@
#if _WIN32 #if _WIN32
#include "imgui_impl_win32.h" #include "imgui_impl_win32.h"
#include <Windows.h> #include <Windows.h>
#include "../util/keystates.h" #include "./util/keystates.h"
#endif #endif
#include <d3d9.h> #include <d3d9.h>
@ -14,9 +14,14 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "../util/text_file_functions.h" // Utility functions
#include "../test/directx9_test.h" #include "./util/text_file_functions.h"
#include "text_menu.h"
// Test functions
#include "./test/directx9_test.h"
// Menus
#include "./menus/text_menu.h"
bool show_text = false; bool show_text = false;

29
src/test/defines.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#if _WIN32
#include <Windows.h>
#endif
//
#ifdef _WIN32
class Defines {
private:
// Defining all of these in a private class, they will be called under the public class.
// Kind of mimics my Java Messages file from KBP: https://github.com/kelson8/KBP/blob/master/src/main/java/net/Kelsoncraft/KBP/util/Messages.java
// https://stackoverflow.com/questions/50332569/why-i-am-getting-this-error-constexpr-is-not-valid-here
static constexpr wchar_t* TITLE = L"KCNet ImGui DirectX Test";
// TODO Add more of these
static constexpr wchar_t* MAIN_MENU_TITLE_ = L"Main Menu";
static constexpr char* IMGUI_WINDOW_NAME_ = "KCNet ImGui";
public:
const wchar_t* window_title = TITLE;
const wchar_t* main_menu_title = MAIN_MENU_TITLE_;
const char* imgui_window_name = IMGUI_WINDOW_NAME_;
};
#endif //_WIN32

View File

@ -30,7 +30,7 @@
#if _WIN32 #if _WIN32
#include "imgui_impl_win32.h" #include "imgui_impl_win32.h"
#include <Windows.h> #include <Windows.h>
#include "../util/keystates.h" #include "./util/keystates.h"
#endif #endif
// //
@ -42,14 +42,30 @@
#include <fstream> #include <fstream>
// Util // Util
#include "../util/text_file_functions.h" #include "./util/text_file_functions.h"
#include "../util/text_functions.h" #include "./util/text_functions.h"
// //
// Menus // Menus
#include "../menus/main_menu.h" #include "./menus/main_menu.h"
#include "../menus/text_menu.h" #include "./menus/text_menu.h"
// Enums, menu title and etc.
// TODO Move into main source folder
#include "./test/defines.h"
#include "./util/helpers.h"
// TODO Move into ../menus/http_menu.h
#include "./test/http_lib_test.h"
// //
// Switch to using helpers.cpp for helper functions.
//#define _TEST2
// TODO Create src folder for project, move source files into it
// TODO Possibly create headers folder for project.
// https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/ // https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/
// Test macros // Test macros
#define LIMIT 5 #define LIMIT 5
@ -60,15 +76,20 @@
#endif #endif
// Data // Data
// TODO Move into helpers.cpp or helpers.h
#ifndef _TEST2 //!_TEST2
static LPDIRECT3D9 g_pD3D = nullptr; static LPDIRECT3D9 g_pD3D = nullptr;
static LPDIRECT3DDEVICE9 g_pd3dDevice = nullptr; static LPDIRECT3DDEVICE9 g_pd3dDevice = nullptr;
static UINT g_ResizeWidth = 0, g_ResizeHeight = 0; static UINT g_ResizeWidth = 0, g_ResizeHeight = 0;
static D3DPRESENT_PARAMETERS g_d3dpp = {}; static D3DPRESENT_PARAMETERS g_d3dpp = {};
#endif //_!_TEST2
// Forward declarations of helper functions // Forward declarations of helper functions
#ifndef _TEST2 //!_TEST2
bool CreateDeviceD3D(HWND hWnd); bool CreateDeviceD3D(HWND hWnd);
void CleanupDeviceD3D(); void CleanupDeviceD3D();
void ResetDevice(); void ResetDevice();
#endif //!_TEST2
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static void HelpMarker(const char* desc) static void HelpMarker(const char* desc)
@ -149,35 +170,86 @@ static void ShowWindow(bool* p_open)
} }
// Main code static void CreateApplicationWindow()
void DirectX9Test::directX9Test()
{ {
// Define custom booleans and features. }
TextMenu *textMenu = new TextMenu();
#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"KCNet ImGui", nullptr };
::RegisterClassExW(&wc);
HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"KCNet ImGui", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr);
static void InitializeD3D(HWND hwnd, WNDCLASSEXW wc)
{
// Initialize Direct3D // Initialize Direct3D
#ifndef _TEST2 //!_TEST2
if (!CreateDeviceD3D(hwnd)) if (!CreateDeviceD3D(hwnd))
#else
if (!Helpers::CreateDeviceD3D(hwnd))
#endif //!_TEST2
{ {
#ifndef _TEST2 //!_TEST2
CleanupDeviceD3D(); CleanupDeviceD3D();
#else
Helpers::CleanupDeviceD3D();
#endif //!_TEST2
::UnregisterClassW(wc.lpszClassName, wc.hInstance); ::UnregisterClassW(wc.lpszClassName, wc.hInstance);
//return 1; //return 1;
} }
}
static void ShowWindow(HWND hwnd)
{
// Show the window // Show the window
::ShowWindow(hwnd, SW_SHOWDEFAULT); ::ShowWindow(hwnd, SW_SHOWDEFAULT);
::UpdateWindow(hwnd); ::UpdateWindow(hwnd);
}
static void Render(ImVec4 clear_color)
{
#ifndef _TEST2 //!_TEST2
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)
#else
Helpers::g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
Helpers::g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
Helpers::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));
Helpers::g_pd3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
if (Helpers::g_pd3dDevice->BeginScene() >= 0)
{
ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
Helpers::g_pd3dDevice->EndScene();
}
HRESULT result = Helpers::g_pd3dDevice->Present(nullptr, nullptr, nullptr, nullptr);
// Handle loss of D3D9 device
if (result == D3DERR_DEVICELOST && Helpers::g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
#endif //!_TEST2
#ifndef _TEST2 //!_TEST2
ResetDevice();
#else
Helpers::ResetDevice();
#endif //_TEST2
}
void setupContext()
{
// Setup Dear ImGui context // Setup Dear ImGui context
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
@ -185,14 +257,6 @@ void DirectX9Test::directX9Test()
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad 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 // 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. // - 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. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
@ -201,13 +265,64 @@ void DirectX9Test::directX9Test()
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering. // - 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. // - 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 \\ ! // - 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->AddFontDefault();
io.Fonts->AddFontFromFileTTF("./lib/ImGui/misc/fonts/DroidSans.ttf", 16.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.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/Roboto-Medium.ttf", 16.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.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()); //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != nullptr); //IM_ASSERT(font != nullptr);
}
// Main code
// TODO Fix this not to break when imgui_impl_glfw.cpp and imgui_impl_glfw.h is included.
// Found the fix for OpenGL here: https://github.com/ocornut/imgui/issues/1299
void DirectX9Test::directX9Test()
{
// Define custom booleans and features.
TextMenu *textMenu = new TextMenu();
Defines* defines = new Defines();
#ifdef _TEST
//std::cout << testString1();
#endif
// Move window title into here.
// TODO Make this grab from a enum or something.
//const wchar_t* window_title = L"KCNet ImGui";
// Create application window
//ImGui_ImplWin32_EnableDpiAwareness();
WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, defines->window_title, nullptr };
::RegisterClassExW(&wc);
HWND hwnd = ::CreateWindowW(wc.lpszClassName, defines->window_title, WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr);
// Initialize Direct3D
InitializeD3D(hwnd, wc);
// Show the window
ShowWindow(hwnd);
// Setup Dear ImGui context
setupContext();
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
ImGui_ImplWin32_Init(hwnd);
#ifndef _TEST2
ImGui_ImplDX9_Init(g_pd3dDevice);
#else
ImGui_ImplDX9_Init(Helpers::g_pd3dDevice);
#endif //!_TEST2
// Our state // Our state
//bool show_demo_window = true; //bool show_demo_window = true;
@ -239,13 +354,26 @@ void DirectX9Test::directX9Test()
if (done) if (done)
break; break;
#ifndef _TEST2
// Handle window resize (we don't resize directly in the WM_SIZE handler) // Handle window resize (we don't resize directly in the WM_SIZE handler)
if (g_ResizeWidth != 0 && g_ResizeHeight != 0) if (g_ResizeWidth != 0 && g_ResizeHeight != 0)
{ {
g_d3dpp.BackBufferWidth = g_ResizeWidth; g_d3dpp.BackBufferWidth = g_ResizeWidth;
g_d3dpp.BackBufferHeight = g_ResizeHeight; g_d3dpp.BackBufferHeight = g_ResizeHeight;
g_ResizeWidth = g_ResizeHeight = 0; g_ResizeWidth = g_ResizeHeight = 0;
#else
if (Helpers::g_ResizeWidth != 0 && Helpers::g_ResizeHeight != 0)
{
Helpers::g_d3dpp.BackBufferWidth = Helpers::g_ResizeWidth;
Helpers::g_d3dpp.BackBufferHeight = Helpers::g_ResizeHeight;
Helpers::g_ResizeWidth = Helpers::g_ResizeHeight = 0;
#endif //!_TEST2
#ifndef _TEST2
ResetDevice(); ResetDevice();
#else
Helpers::ResetDevice();
#endif //!_TEST2
} }
// Start the Dear ImGui frame // Start the Dear ImGui frame
@ -261,9 +389,13 @@ void DirectX9Test::directX9Test()
//#define _OLD_CODE //#define _OLD_CODE
if (ImGui::Begin("KCNet ImGui", nullptr, ImGuiWindowFlags_MenuBar)) //***************
// Start of ImGui code
//***************
//if (ImGui::Begin("KCNet ImGui", nullptr, ImGuiWindowFlags_MenuBar))
if (ImGui::Begin(defines->imgui_window_name, nullptr, ImGuiWindowFlags_MenuBar))
{ {
// Show the main menu
MainMenu::MainMenuTest(); MainMenu::MainMenuTest();
@ -274,6 +406,27 @@ void DirectX9Test::directX9Test()
textMenu->TextMainMenu(); textMenu->TextMainMenu();
} }
// End Text file functions test menu // End Text file functions test menu
// HTTP Test menu, doesn't work
#ifdef _TEST1
if (ImGui::CollapsingHeader("Http Test")) {
bool show_html = false;
// TODO Move this to using
// httpTestMenu->HttpTestMainMenu();
ImGui::Checkbox("Test", &show_html);
if (show_html)
{
//ImGui::Text(HttpTest::test);
HttpTest::test();
}
}
#endif //_TEST1
// End http test menu
//if (ImGui::BeginMenu("My menu")) //if (ImGui::BeginMenu("My menu"))
//{ //{
@ -288,37 +441,39 @@ void DirectX9Test::directX9Test()
// End ImGui // End ImGui
ImGui::End(); ImGui::End();
// Rendering
ImGui::EndFrame(); ImGui::EndFrame();
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE); //***************
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); // End of ImGui code
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 // Rendering
if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
ResetDevice(); Render(clear_color);
} }
// Shutdown ImGui
ImGui_ImplDX9_Shutdown(); ImGui_ImplDX9_Shutdown();
ImGui_ImplWin32_Shutdown(); ImGui_ImplWin32_Shutdown();
// Destroy ImGui Context
ImGui::DestroyContext(); ImGui::DestroyContext();
// Cleanup D3D Device
#ifndef _TEST2
CleanupDeviceD3D(); CleanupDeviceD3D();
#else
Helpers::CleanupDeviceD3D();
#endif
::DestroyWindow(hwnd); ::DestroyWindow(hwnd);
::UnregisterClassW(wc.lpszClassName, wc.hInstance); ::UnregisterClassW(wc.lpszClassName, wc.hInstance);
} }
// End Main class
// Helper functions // Helper functions
#ifndef _TEST2
bool CreateDeviceD3D(HWND hWnd) bool CreateDeviceD3D(HWND hWnd)
{ {
if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == nullptr) if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == nullptr)
@ -354,6 +509,8 @@ void ResetDevice()
ImGui_ImplDX9_CreateDeviceObjects(); ImGui_ImplDX9_CreateDeviceObjects();
} }
#endif //!_TEST2
// Forward declare message handler from imgui_impl_win32.cpp // 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); extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
@ -372,8 +529,14 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_SIZE: case WM_SIZE:
if (wParam == SIZE_MINIMIZED) if (wParam == SIZE_MINIMIZED)
return 0; return 0;
#ifndef _TEST2
g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize
g_ResizeHeight = (UINT)HIWORD(lParam); g_ResizeHeight = (UINT)HIWORD(lParam);
#else
Helpers::g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize
Helpers::g_ResizeHeight = (UINT)HIWORD(lParam);
#endif //!_TEST2
return 0; return 0;
case WM_SYSCOMMAND: case WM_SYSCOMMAND:
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu

View File

@ -3,6 +3,8 @@
// Moving opengl test into this file until I'm ready to mess with it. // Moving opengl test into this file until I'm ready to mess with it.
// 5-25-2024 @ 12:21PM // 5-25-2024 @ 12:21PM
// TODO Fix this to work on Linux and Windows
// https://www.reddit.com/r/cpp/comments/16scrps/at_what_point_in_your_c_development_do_you/ // https://www.reddit.com/r/cpp/comments/16scrps/at_what_point_in_your_c_development_do_you/
#ifndef _OPENGL #ifndef _OPENGL
@ -21,6 +23,7 @@
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp // - Introduction, links and more at the top of imgui.cpp
// ImGui and GLFW
#include "imgui.h" #include "imgui.h"
#include "imgui_impl_glfw.h" #include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h" #include "imgui_impl_opengl3.h"
@ -31,6 +34,19 @@
#endif #endif
#include <GLFW/glfw3.h> // Will drag system OpenGL headers #include <GLFW/glfw3.h> // Will drag system OpenGL headers
// Test
// This seems to be windows only
#if _WIN32
#include <tchar.h>
#endif //_WIN32
#include <string>
#include <iostream>
#include <fstream>
//
// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers. // [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. // 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. // 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.
@ -43,34 +59,77 @@
#include "../libs/emscripten/emscripten_mainloop_stub.h" #include "../libs/emscripten/emscripten_mainloop_stub.h"
#endif #endif
// Util
#include "../util/text_file_functions.h"
#include "../util/text_functions.h"
//
// Menus
#include "../menus/main_menu.h"
#include "../menus/text_menu.h"
static void glfw_error_callback(int error, const char* description) static void glfw_error_callback(int error, const char* description)
{ {
fprintf(stderr, "GLFW Error %d: %s\n", error, description); fprintf(stderr, "GLFW Error %d: %s\n", error, description);
} }
static void setupGlfw()
{
}
static void Render(GLFWwindow* window, ImVec4 clear_color)
{
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);
}
static void setupContext()
{
// 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
}
// Main code // Main code
void OpenGLTest::openGLTest() void OpenGLTest::openGLTest()
{ {
// Define custom booleans and features.
TextMenu* textMenu = new TextMenu();
const char* window_title = "KCNet ImGui OpenGL";
glfwSetErrorCallback(glfw_error_callback); glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit()) if (!glfwInit())
// Decide GL+GLSL versions
// TODO Fix below to work, for now I have hard-coded "#version 130" into ImGui_ImplOpenGL3_Init
// Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2) #if defined(IMGUI_IMPL_OPENGL_ES2)
// GL ES 2.0 + GLSL 100 // GL ES 2.0 + GLSL 100
const char* glsl_version = "#version 100"; const char* glsl_version = "#version 100";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
#elif defined(__APPLE__) #elif defined(__APPLE__)
// GL 3.2 + GLSL 150 // GL 3.2 + GLSL 150
const char* glsl_version = "#version 150"; const char* glsl_version = "#version 150";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
#else #else
// GL 3.0 + GLSL 130 // GL 3.0 + GLSL 130
const char* glsl_version = "#version 130"; const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
@ -78,29 +137,31 @@ void OpenGLTest::openGLTest()
#endif #endif
// Create window with graphics context // Create window with graphics context
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", nullptr, nullptr); //GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", nullptr, nullptr);
if (window == nullptr) GLFWwindow* window = glfwCreateWindow(1280, 720, window_title, nullptr, nullptr);
if (window == nullptr) {
return;
}
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync glfwSwapInterval(1); // Enable vsync
// Setup Dear ImGui context // Setup ImGui Context.
IMGUI_CHECKVERSION(); setupContext();
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 // Setup Dear ImGui style
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
//ImGui::StyleColorsLight(); //ImGui::StyleColorsLight();
// Setup Platform/Renderer backends // Setup Platform/Renderer backends
// Initialize ImGui
ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplGlfw_InitForOpenGL(window, true);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas"); ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
#endif #endif
//ImGui_ImplOpenGL3_Init(glsl_version); //ImGui_ImplOpenGL3_Init(glsl_version);
ImGui_ImplOpenGL3_Init("#version 130"); ImGui_ImplOpenGL3_Init("#version 130");
//
// Load Fonts // 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. // - 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.
@ -120,11 +181,13 @@ void OpenGLTest::openGLTest()
//IM_ASSERT(font != nullptr); //IM_ASSERT(font != nullptr);
// Our state // Our state
bool show_demo_window = true; //bool show_demo_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Show window
// Main loop // Main loop
bool done = false;
#ifdef __EMSCRIPTEN__ #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. // 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. // You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
@ -150,6 +213,28 @@ void OpenGLTest::openGLTest()
if (show_demo_window) if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window); ImGui::ShowDemoWindow(&show_demo_window);
// TODO Make this part compatible between the OpenGL Test and the
// DirectX9 test, I should be able to put this into a utilites file somewhere.
#define _TEST
#ifdef _TEST
if (ImGui::Begin("KCNet ImGui", nullptr, ImGuiWindowFlags_MenuBar))
{
// Show the main menu
MainMenu::MainMenuTest();
// Text file functions test menu
if (ImGui::CollapsingHeader("Text File Functions"))
{
textMenu->TextMainMenu();
}
}
// End ImGui
ImGui::End();
#else
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named 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 float f = 0.0f;
@ -182,19 +267,24 @@ void OpenGLTest::openGLTest()
show_another_window = false; show_another_window = false;
ImGui::End(); ImGui::End();
} }
#endif
// Rendering // Rendering
ImGui::Render(); // Test with local Render function
int display_w, display_h; Render(window, clear_color);
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); //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);
ImGui::EndFrame(); ImGui::EndFrame();
} }
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
EMSCRIPTEN_MAINLOOP_END; EMSCRIPTEN_MAINLOOP_END;

10
src/test/opengl_test.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
class OpenGLTest{
public:
static void openGLTest();
static bool show_demo_window;
// To enable OpenGL Test:
// Include these two files into the project:
// imgui_impl_glfw.cpp and imgui_impl_glfw.h
};

50
src/util/helpers.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "helpers.h"
#include <d3d9.h>
#include "imgui.h"
#include "imgui_impl_dx9.h"
// Data
static LPDIRECT3D9 g_pD3D = nullptr;
static LPDIRECT3DDEVICE9 g_pd3dDevice = nullptr;
static UINT g_ResizeWidth = 0, g_ResizeHeight = 0;
static D3DPRESENT_PARAMETERS g_d3dpp = {};
// TODO Figure out if I can move these DirectX helpers into here.
// If I define _TEST2 into directx9_test.cpp it'll switch everything to using this file
// It crashes because g_d3dpp is a nullptr though
bool Helpers::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 Helpers::CleanupDeviceD3D()
{
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = nullptr; }
if (g_pD3D) { g_pD3D->Release(); g_pD3D = nullptr; }
}
void Helpers::ResetDevice()
{
ImGui_ImplDX9_InvalidateDeviceObjects();
HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
if (hr == D3DERR_INVALIDCALL)
IM_ASSERT(0);
ImGui_ImplDX9_CreateDeviceObjects();
}

32
src/util/helpers.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#ifdef _WIN32
#include <Windows.h>
#endif //_WIN32
// Oops I named the source file with a .c extension instead of .cpp
// No wonder this didn't work.
// https://stackoverflow.com/questions/12524168/resolving-found-at-file-scope-missing-function-header-in-vs2010-c
class Helpers {
public:
#ifdef _WIN32
static bool CreateDeviceD3D(HWND hWnd);
static void CleanupDeviceD3D();
static void Helpers::ResetDevice();
#ifdef _TEST2
static LPDIRECT3D9 g_pD3D;
static LPDIRECT3DDEVICE9 g_pd3dDevice;
static UINT g_ResizeWidth;
static UINT g_ResizeHeight;
static D3DPRESENT_PARAMETERS g_d3dpp;
#endif //_TEST2
#else
// Will this work on Linux or Mac? I don't think DirectX does.
static bool CreateDeviceD3D();
#endif
};

View File

@ -62,6 +62,8 @@ void TextFileFunctions::readTextFile(std::string file)
// This works // This works
// Some code from Google AI:/// // Some code from Google AI:///
// TODO Fix this to work on OpenGL test, it only works on the DirectX9 one.
void TextFileFunctions::outputTextFileContents(const char* filePath) { void TextFileFunctions::outputTextFileContents(const char* filePath) {
std::ifstream myfile(filePath); std::ifstream myfile(filePath);
@ -87,8 +89,6 @@ void TextFileFunctions::outputTextFileContents(const char* filePath) {
} }
} }
// Add test function for this, I need to figure out how to return an array like this.
#ifdef _TEST
// This prints the text file output to the console but spams it, I probably won't use this much. // This prints the text file output to the console but spams it, I probably won't use this much.
void TextFileFunctions::printTextOutput(std::string file) void TextFileFunctions::printTextOutput(std::string file)
{ {
@ -127,41 +127,3 @@ void TextFileFunctions::printTextOutput(std::string file)
// //
//} //}
#else
//static std::string testString1(std::string file std::string text)
//std::string TextFileFunctions::testString1(std::string file)
// This doesn't fully work yet, once I finish it, it'll show up on a ImGui tab.
//std::string TextFileFunctions::printTextOutput(std::string file)
void TextFileFunctions::printTextOutput(std::string file)
{
std::string line;
std::ifstream myfile(file);
if (TextFileFunctions::fileExistCheck(file))
{
if (myfile.is_open())
{
while (std::getline(myfile, line))
{
std::cout << line << '\n';
//return line;
}
//return line;
myfile.close();
}
else
{
std::cout << "Unable to open file!";
}
}
else
{
std::cout << "File doesn't exist!";
}
}
#endif //_TEST

View File

@ -1,5 +0,0 @@
#pragma once
class OpenGLTest{
public:
static void openGLTest();
};