Changeset a6f6833 in opengl-game


Ignore:
Timestamp:
Sep 15, 2019, 5:27:13 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
92cbc6a
Parents:
09e15a4
Message:

Remove getWindowSize() from game-gui and instead add getWindowWidth(), getWindowHeight(), and refreshWindowSize() (which updates the internal variables returned by the first two functions)

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • game-gui-glfw.cpp

    r09e15a4 ra6f6833  
    5656   window = glfwCreateWindow(windowWidth, windowHeight, title.c_str(), mon, nullptr);
    5757
     58   // TODO: I should check the window size after it's created to make sure it matches the requested size
     59   // glfwGetFramebufferSize(window, width, height) segfaults on OSX, check other platforms
     60   // I think glfwGetWindowSize(window, width, height) works fine.
     61
    5862   glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
    5963   glfwSetKeyCallback(window, glfw_key_callback);
     
    8993}
    9094
     95void GameGui_GLFW::refreshWindowSize() {
     96   // glfwGetFramebufferSize(window, width, height) segfaults on OSX, check other platforms
     97   // I think glfwGetWindowSize(window, width, height) works fine.
     98   glfwGetWindowSize(window, &windowWidth, &windowHeight);
     99}
     100
     101int GameGui_GLFW::getWindowWidth() {
     102   return windowWidth;
     103}
     104
     105int GameGui_GLFW::getWindowHeight() {
     106   return windowHeight;
     107}
     108
    91109#ifdef GAMEGUI_INCLUDE_VULKAN
    92110
     
    95113      RTWO_SUCCESS : RTWO_ERROR;
    96114}
    97 
    98 #endif
    99115
    100116vector<const char*> GameGui_GLFW::getRequiredExtensions() {
     
    109125}
    110126
    111 void GameGui_GLFW::getWindowSize(int* width, int* height) {
    112    // This function segfaults on OSX, check other platforms
    113    //glfwGetFramebufferSize(window, width, height);
    114 
    115    *width = windowWidth;
    116    *height = windowHeight;
    117 }
     127#endif
    118128
    119129void glfw_error_callback(int error, const char* description) {
  • game-gui-glfw.hpp

    r09e15a4 ra6f6833  
    88#ifdef GAMEGUI_INCLUDE_VULKAN
    99   #define GLFW_INCLUDE_VULKAN
     10#else
     11   #include <GL/glew.h>
    1012#endif
    1113
     
    3032      int pollEvent(UIEvent* event);
    3133
     34      void refreshWindowSize();
     35      int getWindowWidth();
     36      int getWindowHeight();
     37
    3238#ifdef GAMEGUI_INCLUDE_VULKAN
    3339      bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface);
     40      vector<const char*> getRequiredExtensions();
    3441#endif
    35 
    36       vector<const char*> getRequiredExtensions();
    37       void getWindowSize(int* width, int* height);
    3842
    3943   private:
    4044      GLFWwindow* window;
    41 
    4245      int windowWidth, windowHeight;
    4346};
  • game-gui-sdl.cpp

    r09e15a4 ra6f6833  
    6161               SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
    6262               width, height, flags);
     63
     64   refreshWindowSize();
    6365
    6466   return window;
     
    125127}
    126128
     129void GameGui_SDL::refreshWindowSize() {
     130   SDL_GetWindowSize(window, &windowWidth, &windowHeight);
     131}
     132
     133int GameGui_SDL::getWindowWidth() {
     134   return windowWidth;
     135}
     136
     137int GameGui_SDL::getWindowHeight() {
     138   return windowHeight;
     139}
     140
    127141#ifdef GAMEGUI_INCLUDE_VULKAN
    128142
     
    131145      RTWO_SUCCESS : RTWO_ERROR;
    132146}
    133 
    134 #endif
    135147
    136148vector<const char*> GameGui_SDL::getRequiredExtensions() {
     
    144156}
    145157
    146 void GameGui_SDL::getWindowSize(int* width, int* height) {
    147    SDL_GetWindowSize(window, width, height);
    148 }
     158#endif
  • game-gui-sdl.hpp

    r09e15a4 ra6f6833  
    77#include <SDL2/SDL_image.h>
    88#include <SDL2/SDL_ttf.h>
    9 #include <SDL2/SDL_vulkan.h>
     9
     10#ifdef GAMEGUI_INCLUDE_VULKAN
     11   #include <SDL2/SDL_vulkan.h>
     12#endif
    1013
    1114class GameGui_SDL : public GameGui {
     
    2225      int pollEvent(UIEvent* event);
    2326
     27      void refreshWindowSize();
     28      int getWindowWidth();
     29      int getWindowHeight();
     30
    2431#ifdef GAMEGUI_INCLUDE_VULKAN
    2532      bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface);
     33      vector<const char*> getRequiredExtensions();
    2634#endif
    27 
    28       vector<const char*> getRequiredExtensions();
    29       void getWindowSize(int* width, int* height);
    3035
    3136   private:
    3237      SDL_Window* window;
     38      int windowWidth, windowHeight;
    3339
    3440      static string s_errorMessage;
  • game-gui.hpp

    r09e15a4 ra6f6833  
    6767      virtual int pollEvent(UIEvent* event) = 0;
    6868
    69       /*
    70       virtual void processEvents() = 0;
    71 
    72       virtual int pollMouseEvent(MouseEvent* event) = 0;
    73 
    74       virtual unsigned char getKeyEvent(unsigned int key) = 0;
    75       virtual bool isKeyPressed(unsigned int key) = 0;
    76       */
     69      virtual void refreshWindowSize() = 0;
     70      virtual int getWindowWidth() = 0;
     71      virtual int getWindowHeight() = 0;
    7772
    7873#ifdef GAMEGUI_INCLUDE_VULKAN
    7974      virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0;
     75      virtual vector<const char*> getRequiredExtensions() = 0;
    8076#endif
    81 
    82       virtual vector<const char*> getRequiredExtensions() = 0;
    83       virtual void getWindowSize(int* width, int* height) = 0;
    8477};
    8578
  • opengl-game.cpp

    r09e15a4 ra6f6833  
    6666   }
    6767
    68    int actualWidth=0, actualHeight=0;
    69    gui->getWindowSize(&actualWidth, &actualHeight);
    70 
    7168   cout << "Target window size: (" << width << ", " << height << ")" << endl;
    72    cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
     69   cout << "Actual window size: (" << gui->getWindowWidth() << ", " << gui->getWindowHeight() << ")" << endl;
    7370
    7471   return RTWO_SUCCESS;
  • vulkan-game.cpp

    r09e15a4 ra6f6833  
    7878   }
    7979
    80    int actualWidth, actualHeight;
    81    gui->getWindowSize(&actualWidth, &actualHeight);
    82 
    8380   cout << "Target window size: (" << width << ", " << height << ")" << endl;
    84    cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
     81   cout << "Actual window size: (" << gui->getWindowWidth() << ", " << gui->getWindowHeight() << ")" << endl;
    8582
    8683   return RTWO_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.