Changeset f133da0 in opengl-game


Ignore:
Timestamp:
Sep 16, 2019, 2:09:05 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
c6fec84
Parents:
df2cc24
Message:

Add renderScene and renderUI functions to openglgame and use IMGUI to render the main menu

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • game-gui-glfw.cpp

    rdf2cc24 rf133da0  
    6060   // I think glfwGetWindowSize(window, width, height) works fine.
    6161
     62   return window;
     63}
     64
     65void GameGui_GLFW::bindEventHandlers() {
    6266   glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
    6367   glfwSetKeyCallback(window, glfw_key_callback);
    64 
    65    return window;
    6668}
    6769
  • game-gui-glfw.hpp

    rdf2cc24 rf133da0  
    2929      void destroyWindow();
    3030
     31      void bindEventHandlers();
    3132      void processEvents();
    3233      int pollEvent(UIEvent* event);
  • new-game.cpp

    rdf2cc24 rf133da0  
    397397   cout << "MAX_UNIFORMS: " << MAX_UNIFORMS << endl;
    398398
     399/*** START OF REFACTORED CODE ***/
    399400   // Setup Dear ImGui binding
    400401   IMGUI_CHECKVERSION();
     
    411412   glfwSetMouseButtonCallback(window, mouse_button_callback);
    412413   glfwSetKeyCallback(window, key_callback);
     414/*** END OF REFACTORED CODE ***/
    413415
    414416   glfwSetWindowSizeCallback(window, window_size_callback);
     
    24462448}
    24472449
     2450/*** START OF REFACTORED CODE ***/
    24482451void renderMainMenuGui() {
    24492452   ImGui_ImplGlfwGL3_NewFrame();
     
    24782481   ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData());
    24792482}
     2483/*** END OF REFACTORED CODE ***/
    24802484
    24812485void initGuiValueLists(map<string, vector<UIValue>> valueLists) {
  • opengl-game.cpp

    rdf2cc24 rf133da0  
    8787      cout << "OpenGL debug message callback is not supported" << endl;
    8888   }
     89
     90   // Setup Dear ImGui binding
     91   IMGUI_CHECKVERSION();
     92   ImGui::CreateContext();
     93   ImGuiIO& io = ImGui::GetIO(); (void)io;
     94   //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls
     95   //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;   // Enable Gamepad Controls
     96   ImGui_ImplGlfwGL3_Init(window, true);
     97
     98   // Setup style
     99   ImGui::StyleColorsDark();
     100   //ImGui::StyleColorsClassic();
     101
     102   // The glfw event handlers have to be bound after ImGui is initialized.
     103   // Otherwise, it seems they get overridden by ImGui
     104   ((GameGui_GLFW*)gui)->bindEventHandlers();
    89105}
    90106
     
    103119               break;
    104120            case UI_EVENT_KEY:
     121               cout << "Got a key event" << endl;
    105122               if (e.key.keycode == GLFW_KEY_ESCAPE) {
    106123                  quit = true;
     
    121138      //glViewport(0, 0, gui->getWindowWidth(), gui->getWindowHeight());
    122139
     140      renderScene();
     141      renderUI();
     142
    123143      glfwSwapBuffers(window);
    124144   }
    125145}
    126146
     147void OpenGLGame::renderScene() {
     148
     149}
     150
     151void OpenGLGame::renderUI() {
     152   ImGui_ImplGlfwGL3_NewFrame();
     153
     154   {
     155      int padding = 4;
     156      ImGui::SetNextWindowPos(ImVec2(-padding, -padding), ImGuiCond_Once);
     157      ImGui::SetNextWindowSize(ImVec2(gui->getWindowWidth() + 2 * padding, gui->getWindowHeight() + 2 * padding), ImGuiCond_Always);
     158      ImGui::Begin("WndMain", NULL,
     159         ImGuiWindowFlags_NoTitleBar |
     160         ImGuiWindowFlags_NoResize |
     161         ImGuiWindowFlags_NoMove);
     162
     163      ImGui::InvisibleButton("", ImVec2(10, 80));
     164      ImGui::InvisibleButton("", ImVec2(285, 18));
     165      ImGui::SameLine();
     166      ImGui::Button("New Game");
     167
     168      ImGui::InvisibleButton("", ImVec2(10, 15));
     169      ImGui::InvisibleButton("", ImVec2(300, 18));
     170      ImGui::SameLine();
     171      ImGui::Button("Quit");
     172
     173      ImGui::End();
     174   }
     175
     176   ImGui::Render();
     177   ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData());
     178}
     179
    127180void OpenGLGame::cleanup() {
     181   ImGui_ImplGlfwGL3_Shutdown();
     182   ImGui::DestroyContext();
     183
    128184   gui->destroyWindow();
    129185   gui->shutdown();
  • opengl-game.hpp

    rdf2cc24 rf133da0  
    11#ifndef _OPENGL_GAME_H
    22#define _OPENGL_GAME_H
     3
     4#include "IMGUI/imgui.h"
     5#include "imgui_impl_glfw_gl3.h"
    36
    47#include "game-gui-glfw.hpp"
     
    1821      void initOpenGL();
    1922      void mainLoop();
     23      void renderScene();
     24      void renderUI();
    2025      void cleanup();
    2126};
Note: See TracChangeset for help on using the changeset viewer.