Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include "../../include/glad/glad.h"
  2. #include "../../include/imgui/imgui.h"
  3. #include "../../include/imgui/impl/imgui_impl_opengl3.h"
  4. #include "../../include/imgui/impl/imgui_impl_glfw.h"
  5. #include <GLFW/glfw3.h>
  6. #include <iostream>
  7.  
  8. void fbuffer(GLFWwindow *window, int width, int height);
  9. void processInput(GLFWwindow *window);
  10.  
  11. int main(int argc, char const *argv[])
  12. {
  13.     glfwInit();
  14.     GLFWwindow *window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
  15.     glfwMakeContextCurrent(window);
  16.     glfwSetFramebufferSizeCallback(window, fbuffer);
  17.  
  18.     bool err = gladLoadGL() == 0;
  19.  
  20.     IMGUI_CHECKVERSION();
  21.     ImGui::CreateContext();
  22.     ImGuiIO &io = ImGui::GetIO();
  23.     (void)io;
  24.     io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
  25.     ImGui::StyleColorsDark();
  26.  
  27.     const char *glsl_version = "#version 130";
  28.     ImGui_ImplGlfw_InitForOpenGL(window, true);
  29.     ImGui_ImplOpenGL3_Init(glsl_version);
  30.  
  31.     bool showDemo = true;
  32.     ImVec4 bg = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
  33.  
  34.     while (!glfwWindowShouldClose(window))
  35.     {
  36.         processInput(window);
  37.         glfwPollEvents();
  38.  
  39.         //Start ImGui
  40.         ImGui_ImplOpenGL3_NewFrame();
  41.         ImGui_ImplGlfw_NewFrame();
  42.         ImGui::NewFrame();
  43.         if (showDemo)
  44.         {
  45.             ImGui::ShowDemoWindow(&showDemo);
  46.         }
  47.  
  48.         //Render
  49.         ImGui::Render();
  50.         glClearColor(bg.x, bg.y, bg.z, bg.w);
  51.         glClear(GL_COLOR_BUFFER_BIT);
  52.         ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
  53.         glfwSwapBuffers(window);
  54.     }
  55.     ImGui_ImplOpenGL3_Shutdown();
  56.     ImGui_ImplGlfw_Shutdown();
  57.     ImGui::DestroyContext();
  58.     glfwTerminate();
  59.     return 0;
  60. }
  61.  
  62. void fbuffer(GLFWwindow *window, int width, int height)
  63. {
  64.     glViewport(0, 0, width, height);
  65. }
  66.  
  67. void processInput(GLFWwindow *window)
  68. {
  69.     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
  70.         glfwSetWindowShouldClose(window, true);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement