Changeset c1ca5b5 in opengl-game


Ignore:
Timestamp:
May 6, 2018, 11:21:01 PM (7 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
1a616e6
Parents:
c58ebc3
Message:

Show the example ImGui gui in the OpenGL game.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • imgui_example.cpp

    rc58ebc3 rc1ca5b5  
    1515}
    1616
    17 int main(int, char**)
     17int mainimgui(int, char**)
    1818{
    1919   // Setup window
  • new-game.cpp

    rc58ebc3 rc1ca5b5  
    1717#include <glm/gtc/matrix_transform.hpp>
    1818#include <glm/gtc/type_ptr.hpp>
     19
     20#include "IMGUI/imgui.h"
     21#include "imgui_impl_glfw_gl3.h"
    1922
    2023#include <GL/glew.h>
     
    5255int height = 480;
    5356
     57double fps;
     58
    5459vec3 cam_pos;
    5560
     
    6267SceneObject* selectedObject;
    6368
    64 double fps;
     69float NEAR_CLIP = 0.1f;
     70float FAR_CLIP = 100.0f;
     71
     72ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
    6573
    6674bool faceClicked(array<vec3, 3> points, SceneObject* obj, vec4 world_ray, vec4 cam, vec4& click_point);
     
    7482void print4DVector(string label, vec4 v);
    7583
    76 float NEAR_CLIP = 0.1f;
    77 float FAR_CLIP = 100.0f;
     84void renderGui();
    7885
    7986void glfw_error_callback(int error, const char* description) {
     
    135142}
    136143
    137 int realmain(int argc, char* argv[]) {
     144int main(int argc, char* argv[]) {
    138145   cout << "New OpenGL Game" << endl;
    139146
     
    175182   }
    176183
    177    glfwSetMouseButtonCallback(window, mouse_button_callback);
    178 
    179184   glfwMakeContextCurrent(window);
    180185   glewExperimental = GL_TRUE;
    181186   glewInit();
     187
     188   // Setup Dear ImGui binding
     189   IMGUI_CHECKVERSION();
     190   ImGui::CreateContext();
     191   ImGuiIO& io = ImGui::GetIO(); (void)io;
     192   //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls
     193   //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;   // Enable Gamepad Controls
     194   ImGui_ImplGlfwGL3_Init(window, true);
     195
     196   // Setup style
     197   ImGui::StyleColorsDark();
     198   //ImGui::StyleColorsClassic();
     199
     200   glfwSetMouseButtonCallback(window, mouse_button_callback);
    182201
    183202   const GLubyte* renderer = glGetString(GL_RENDERER);
     
    596615      }
    597616
     617      renderGui();
     618
    598619      glfwSwapBuffers(window);
    599620
     
    646667   }
    647668
     669   ImGui_ImplGlfwGL3_Shutdown();
     670   ImGui::DestroyContext();
     671
     672   glfwDestroyWindow(window);
    648673   glfwTerminate();
     674
    649675   return 0;
    650676}
     
    782808   cout << label << " -> (" << v.x << "," << v.y << "," << v.z << "," << v.w << ")" << endl;
    783809}
     810
     811void renderGui() {
     812   bool show_demo_window = true;
     813   bool show_another_window = true;
     814
     815   ImGui_ImplGlfwGL3_NewFrame();
     816
     817   // 1. Show a simple window.
     818   // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
     819   {
     820      static float f = 0.0f;
     821      static int counter = 0;
     822      ImGui::Text("Hello, world!");                           // Display some text (you can use a format string too)
     823      ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f   
     824      ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
     825
     826      ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our windows open/close state
     827      ImGui::Checkbox("Another Window", &show_another_window);
     828
     829      if (ImGui::Button("Button"))                            // Buttons return true when clicked (NB: most widgets return true when edited/activated)
     830         counter++;
     831      ImGui::SameLine();
     832      ImGui::Text("counter = %d", counter);
     833
     834      ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
     835   }
     836
     837   // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
     838   if (show_another_window) {
     839      ImGui::Begin("Another Window", &show_another_window);
     840      ImGui::Text("Hello from another window!");
     841      if (ImGui::Button("Close Me"))
     842         show_another_window = false;
     843      ImGui::End();
     844   }
     845
     846   // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui!
     847   if (show_demo_window) {
     848      ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
     849      ImGui::ShowDemoWindow(&show_demo_window);
     850   }
     851
     852   ImGui::Render();
     853   ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData());
     854}
Note: See TracChangeset for help on using the changeset viewer.