You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lunarium_OLD/src/test_main.cpp

195 lines
6.4 KiB
C++

#include <iostream>
#include <GLFW/glfw3.h>
#include <glm/vec3.hpp> // glm::vec3
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#include <pugixml.hpp>
#include "utils/INIFile.h"
#include "utils/Logger.h"
extern "C"
{
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
// the following can also be <GLFWTConfig.h> but it results in
// an intellisense error
#include "../build/LunariumConfig.h"
int main(int argc, char** argv)
{
// VERSION TEST
std::cout << "Hello yall\n";
std::cout << "This is " << argv[0] << " Version " << Lunarium_VERSION_MAJOR
<< "." << Lunarium_VERSION_MINOR
<< "." << Lunarium_VERSION_PATCH << '\n';
glm::vec3 testVec = glm::vec3(1.0f, 2.0f, 3.0f);
std::cout << "\ntestVec: (" << testVec.x << ", " << testVec.y << ", " << testVec.z << ")\n";
// LUA TEST
std::cout << "\nTesting LUA: a = 7 + 4\n";
lua_State* L = luaL_newstate();
std::string cmd = "a = 7 + 4";
int r = luaL_dostring(L, cmd.c_str());
if (r == LUA_OK)
{
lua_getglobal(L, "a");
if (lua_isnumber(L, -1))
{
float a_in_cpp = (float)lua_tonumber(L, -1);
std::cout << "a is: " << a_in_cpp << std::endl;
}
}
else
{
std::string errormsg = lua_tostring(L, -1);
std::cout << errormsg << std::endl;
}
lua_close(L);
// PUGIXML TEST
std::cout << "\nAttempting to open test.xml...";
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("../test_data/test.xml");
if (!result)
{
std::cout << "\nCould not open the file!\n";
return -1;
}
else
{
int x = doc.child("test").attribute("x").as_int();
std::cout << "\nPugiXML worked! -- x is: " << x << std::endl;
}
// UTILS TEST
// NOTE: this works but is windows only so it won't be used in the engine
// unless INIFile is re-written to be cross-platform
// Lunarium::INIFile file("../test_data/test.ini");
// int meaning = file.ReadInt("section", "var");
// std::cout << "\nvar from test.ini is: " << meaning;
std::cout << "\nTesting GLFW and ImGui\n";
// GLFW DEAR IMGUI TEST
GLFWwindow* window;
int width, height;
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
exit( EXIT_FAILURE );
}
glfwWindowHint(GLFW_DEPTH_BITS, 16);
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
window = glfwCreateWindow( 1280, 720, "Lunarium", NULL, NULL );
if (!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
exit( EXIT_FAILURE );
}
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
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
//io.ConfigViewportsNoAutoMerge = true;
//io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
ImGuiStyle& style = ImGui::GetStyle();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
// 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
while( !glfwWindowShouldClose(window) )
{
// 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.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// 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);
// 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());
// Update and Render additional Platform Windows
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
// For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
glfwSwapBuffers(window);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}