Changeset c1ca5b5 in opengl-game
- Timestamp:
- May 6, 2018, 11:21:01 PM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1a616e6
- Parents:
- c58ebc3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
imgui_example.cpp
rc58ebc3 rc1ca5b5 15 15 } 16 16 17 int main (int, char**)17 int mainimgui(int, char**) 18 18 { 19 19 // Setup window -
new-game.cpp
rc58ebc3 rc1ca5b5 17 17 #include <glm/gtc/matrix_transform.hpp> 18 18 #include <glm/gtc/type_ptr.hpp> 19 20 #include "IMGUI/imgui.h" 21 #include "imgui_impl_glfw_gl3.h" 19 22 20 23 #include <GL/glew.h> … … 52 55 int height = 480; 53 56 57 double fps; 58 54 59 vec3 cam_pos; 55 60 … … 62 67 SceneObject* selectedObject; 63 68 64 double fps; 69 float NEAR_CLIP = 0.1f; 70 float FAR_CLIP = 100.0f; 71 72 ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); 65 73 66 74 bool faceClicked(array<vec3, 3> points, SceneObject* obj, vec4 world_ray, vec4 cam, vec4& click_point); … … 74 82 void print4DVector(string label, vec4 v); 75 83 76 float NEAR_CLIP = 0.1f; 77 float FAR_CLIP = 100.0f; 84 void renderGui(); 78 85 79 86 void glfw_error_callback(int error, const char* description) { … … 135 142 } 136 143 137 int realmain(int argc, char* argv[]) {144 int main(int argc, char* argv[]) { 138 145 cout << "New OpenGL Game" << endl; 139 146 … … 175 182 } 176 183 177 glfwSetMouseButtonCallback(window, mouse_button_callback);178 179 184 glfwMakeContextCurrent(window); 180 185 glewExperimental = GL_TRUE; 181 186 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); 182 201 183 202 const GLubyte* renderer = glGetString(GL_RENDERER); … … 596 615 } 597 616 617 renderGui(); 618 598 619 glfwSwapBuffers(window); 599 620 … … 646 667 } 647 668 669 ImGui_ImplGlfwGL3_Shutdown(); 670 ImGui::DestroyContext(); 671 672 glfwDestroyWindow(window); 648 673 glfwTerminate(); 674 649 675 return 0; 650 676 } … … 782 808 cout << label << " -> (" << v.x << "," << v.y << "," << v.z << "," << v.w << ")" << endl; 783 809 } 810 811 void 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.