Changeset 5b3462b in opengl-game for new-game.cpp


Ignore:
Timestamp:
May 8, 2018, 2:54:09 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
f0cc877
Parents:
1c81bf0
Message:

Implement a basic gui with a stats window and a menubar containing a quit button.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    r1c81bf0 r5b3462b  
    6969float NEAR_CLIP = 0.1f;
    7070float FAR_CLIP = 100.0f;
     71
     72// Should really have some array or struct of UI-related variables
     73bool isRunning = true;
    7174
    7275ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
     
    518521   //glfwSwapInterval(0);
    519522
    520    while (!glfwWindowShouldClose(window)) {
     523   while (!glfwWindowShouldClose(window) && isRunning) {
    521524      double current_seconds = glfwGetTime();
    522525      double elapsed_seconds = current_seconds - previous_seconds;
     
    813816
    814817void renderGui() {
    815    bool show_demo_window = true;
    816    bool show_another_window = true;
    817 
    818818   ImGui_ImplGlfwGL3_NewFrame();
    819819
    820820   // 1. Show a simple window.
    821821   // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
     822   /*
    822823   {
    823824      static float f = 0.0f;
     
    837838      ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
    838839   }
    839 
    840    // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
    841    if (show_another_window) {
    842       ImGui::Begin("Another Window", &show_another_window);
    843       ImGui::Text("Hello from another window!");
    844       if (ImGui::Button("Close Me"))
    845          show_another_window = false;
     840   */
     841
     842   {
     843      ImGui::SetNextWindowSize(ImVec2(85, 22), ImGuiCond_Once);
     844      ImGui::SetNextWindowPos(ImVec2(10, 50), ImGuiCond_Once);
     845      ImGui::Begin("WndStats", NULL, ImGuiWindowFlags_NoTitleBar |
     846                               ImGuiWindowFlags_NoResize |
     847                               ImGuiWindowFlags_NoMove);
     848      ImGui::Text("Score: ???");
    846849      ImGui::End();
    847850   }
    848851
    849    // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui!
    850    if (show_demo_window) {
    851       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!
    852       ImGui::ShowDemoWindow(&show_demo_window);
     852   {
     853      ImGui::SetNextWindowPos(ImVec2(380, 10), ImGuiCond_Once);
     854      ImGui::SetNextWindowSize(ImVec2(250, 35), ImGuiCond_Once);
     855      ImGui::Begin("WndMenubar", NULL, ImGuiWindowFlags_NoTitleBar |
     856         ImGuiWindowFlags_NoResize |
     857         ImGuiWindowFlags_NoMove);
     858      ImGui::InvisibleButton("", ImVec2(190, 18));
     859      ImGui::SameLine();
     860      if (ImGui::Button("Quit")) {
     861         isRunning = false;
     862      }
     863      ImGui::End();
    853864   }
    854865
Note: See TracChangeset for help on using the changeset viewer.