Changeset c4c205e in opengl-game for new-game.cpp
- Timestamp:
- Apr 5, 2019, 2:52:35 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- a9d191a
- Parents:
- a926b79
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
ra926b79 rc4c205e 65 65 UNIFORM_1F, 66 66 UNIFORM_3F, 67 }; 68 69 enum UIValueType { 70 UIVALUE_INT, 71 UIVALUE_DOUBLE, 67 72 }; 68 73 … … 142 147 }; 143 148 149 struct UIValue { 150 UIValueType type; 151 string label; 152 void* value; 153 154 UIValue(UIValueType _type, string _label, void* _value) : type(_type), label(_label), value(_value) {} 155 }; 156 144 157 void glfw_error_callback(int error, const char* description); 145 158 … … 246 259 map<ObjectType, ShaderModelGroup>& modelGroups, GLuint ubo); 247 260 248 void renderSceneGui(); 261 void renderSceneGui(map<string, vector<UIValue>> valueLists); 262 263 void renderGuiValueList(vector<UIValue>& values); 249 264 250 265 float getRandomNum(float low, float high); … … 264 279 int width = 640; 265 280 int height = 480; 266 267 double fps;268 unsigned int score = 0;269 281 270 282 vec3 cam_pos; … … 752 764 753 765 766 double fps; 767 unsigned int score = 0; 768 754 769 bool cam_moved = false; 755 770 … … 767 782 768 783 State curState = STATE_MAIN_MENU; 784 785 map<string, vector<UIValue>> valueLists; 786 787 valueLists["stats value list"] = vector<UIValue>(); 788 valueLists["stats value list"].push_back(UIValue(UIVALUE_INT, "Score", &score)); 789 valueLists["stats value list"].push_back(UIValue(UIVALUE_DOUBLE, "FPS", &fps)); 790 791 valueLists["debug value list"] = vector<UIValue>(); 792 793 //valueLists["debug value list"].push_back(UIValue(UIVALUE_INT, "Buffer offset", &bufferOffset)); 769 794 770 795 while (!glfwWindowShouldClose(window) && isRunning) { … … 1039 1064 case STATE_GAME: 1040 1065 renderScene(shaderBufferInfo, modelGroups, ubo); 1041 renderSceneGui( );1066 renderSceneGui(valueLists); 1042 1067 break; 1043 1068 } … … 2568 2593 } 2569 2594 2570 void renderSceneGui( ) {2595 void renderSceneGui(map<string, vector<UIValue>> valueLists) { 2571 2596 ImGui_ImplGlfwGL3_NewFrame(); 2572 2597 … … 2593 2618 */ 2594 2619 2595 stringstream ssScore, ssFps;2596 ssScore << "Score: " << score;2597 ssFps << "FPS: " << fps;2598 2599 2620 { 2600 2621 ImGui::SetNextWindowSize(ImVec2(95, 46), ImGuiCond_Once); … … 2604 2625 ImGuiWindowFlags_NoResize | 2605 2626 ImGuiWindowFlags_NoMove); 2606 ImGui::Text(ssScore.str().c_str()); 2607 ImGui::Text(ssFps.str().c_str()); 2627 2628 renderGuiValueList(valueLists["stats value list"]); 2629 2608 2630 ImGui::End(); 2609 2631 } 2610 2632 2611 2633 { 2634 ImGui::SetNextWindowSize(ImVec2(250, 35), ImGuiCond_Once); 2612 2635 ImGui::SetNextWindowPos(ImVec2(380, 10), ImGuiCond_Once); 2613 ImGui::SetNextWindowSize(ImVec2(250, 35), ImGuiCond_Once);2614 2636 ImGui::Begin("WndMenubar", NULL, 2615 2637 ImGuiWindowFlags_NoTitleBar | … … 2624 2646 } 2625 2647 2648 { 2649 ImGui::SetNextWindowSize(ImVec2(200, 200), ImGuiCond_Once); 2650 ImGui::SetNextWindowPos(ImVec2(430, 60), ImGuiCond_Once); 2651 ImGui::Begin("WndDebug", NULL, 2652 ImGuiWindowFlags_NoTitleBar | 2653 ImGuiWindowFlags_NoResize | 2654 ImGuiWindowFlags_NoMove); 2655 2656 renderGuiValueList(valueLists["debug value list"]); 2657 2658 ImGui::End(); 2659 } 2660 2626 2661 ImGui::Render(); 2627 2662 ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData()); … … 2662 2697 ImGui::Render(); 2663 2698 ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData()); 2699 } 2700 2701 void renderGuiValueList(vector<UIValue>& values) { 2702 float maxWidth = 0.0f; 2703 float cursorStartPos = ImGui::GetCursorPosX(); 2704 2705 for (vector<UIValue>::iterator it = values.begin(); it != values.end(); it++) { 2706 float textWidth = ImGui::CalcTextSize(it->label.c_str()).x; 2707 2708 if (maxWidth < textWidth) 2709 maxWidth = textWidth; 2710 } 2711 2712 stringstream ss; 2713 2714 for (vector<UIValue>::iterator it = values.begin(); it != values.end(); it++) { 2715 ss.str(""); 2716 ss.clear(); 2717 2718 switch (it->type) { 2719 case UIVALUE_INT: 2720 ss << it->label << ": " << *(unsigned int*)it->value; 2721 break; 2722 case UIVALUE_DOUBLE: 2723 ss << it->label << ": " << *(double*)it->value; 2724 break; 2725 } 2726 2727 float textWidth = ImGui::CalcTextSize(it->label.c_str()).x; 2728 2729 ImGui::SetCursorPosX(cursorStartPos + maxWidth - textWidth); 2730 ImGui::Text("%s", ss.str().c_str()); 2731 } 2664 2732 } 2665 2733
Note:
See TracChangeset
for help on using the changeset viewer.