118 lines
3.5 KiB
C++
118 lines
3.5 KiB
C++
#include <glad/glad.h> // Use GLAD instead of GLEW
|
|
#include <GLFW/glfw3.h>
|
|
#include "imgui.h"
|
|
#include "imgui_impl_glfw.h"
|
|
#include "imgui_impl_opengl3.h"
|
|
//#include <glm/glm.hpp>
|
|
#include <iostream>
|
|
|
|
#define NOMINMAX
|
|
#include <windows.h>
|
|
|
|
// GLFW error callback function
|
|
void glfw_error_callback(int error, const char* description) {
|
|
std::cerr << "GLFW Error " << error << ": " << description << std::endl;
|
|
}
|
|
|
|
int main();
|
|
|
|
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
|
return main();
|
|
}
|
|
|
|
int main() {
|
|
// Setup window
|
|
glfwSetErrorCallback(glfw_error_callback);
|
|
|
|
if (!glfwInit()) {
|
|
std::cerr << "Failed to initialize GLFW" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
|
glfwWindowHint(GLFW_VISIBLE, GL_TRUE);
|
|
glfwWindowHint(GLFW_MAXIMIZED, GL_TRUE);
|
|
glfwWindowHint(GLFW_DEPTH_BITS, 0);
|
|
glfwWindowHint(GLFW_STENCIL_BITS, 0);
|
|
|
|
// Create a windowed mode window and its OpenGL context
|
|
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui + GLFW + GLAD Example", nullptr, nullptr);
|
|
if (!window) {
|
|
std::cerr << "Failed to create GLFW window" << std::endl;
|
|
glfwTerminate();
|
|
return -1;
|
|
}
|
|
|
|
glfwMakeContextCurrent(window);
|
|
glfwSwapInterval(0); // Enable vsync
|
|
|
|
// Initialize GLAD
|
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
std::cerr << "Failed to initialize GLAD" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// Setup Dear ImGui context
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGuiIO& io = ImGui::GetIO(); //(void)io;
|
|
// io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18);
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
|
|
|
|
// Setup Dear ImGui style
|
|
ImGui::StyleColorsDark();
|
|
|
|
// Setup Platform/Renderer bindings
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
ImGui_ImplOpenGL3_Init("#version 130");
|
|
|
|
// Main loop
|
|
while (!glfwWindowShouldClose(window)) {
|
|
// Poll and handle events (inputs, window resize, etc.)
|
|
//glfwPollEvents();
|
|
glfwWaitEventsTimeout(0.1);
|
|
|
|
// Start the ImGui frame
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
|
|
ImGui::DockSpaceOverViewport();
|
|
|
|
// Create a simple ImGui window
|
|
{
|
|
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!"
|
|
ImGui::Text("This is a simple window using ImGui and GLFW.");
|
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
|
ImGui::End();
|
|
}
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
// Rendering
|
|
ImGui::Render();
|
|
int display_w, display_h;
|
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
|
glViewport(0, 0, display_w, display_h);
|
|
glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
// Swap buffers
|
|
glfwSwapBuffers(window);
|
|
}
|
|
|
|
// Cleanup
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
ImGui_ImplGlfw_Shutdown();
|
|
ImGui::DestroyContext();
|
|
glfwDestroyWindow(window);
|
|
glfwTerminate();
|
|
|
|
return 0;
|
|
} |