Changeset 7bf5433 in opengl-game


Ignore:
Timestamp:
Sep 12, 2019, 5:23:28 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
d2f607c
Parents:
27c40ce
Message:

Create a new OpenGLGame project for a refactor of the original OpenGL game to make copying its logic over to the Vulkan implementation easier

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • NewOpenGLGame.sln

    r27c40ce r7bf5433  
    99EndProject
    1010Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VulkanGame", "VulkanGame.vcxproj", "{3489E223-6118-49E3-98F3-8887B68AC32F}"
     11EndProject
     12Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenGLGame", "OpenGLGame.vcxproj", "{569037E7-4D03-4412-8CC1-DE51435C0BBE}"
    1113EndProject
    1214Global
     
    4244                {3489E223-6118-49E3-98F3-8887B68AC32F}.Release|x86.ActiveCfg = Release|Win32
    4345                {3489E223-6118-49E3-98F3-8887B68AC32F}.Release|x86.Build.0 = Release|Win32
     46                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Debug|x64.ActiveCfg = Debug|x64
     47                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Debug|x64.Build.0 = Debug|x64
     48                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Debug|x86.ActiveCfg = Debug|Win32
     49                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Debug|x86.Build.0 = Debug|Win32
     50                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Release|x64.ActiveCfg = Release|x64
     51                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Release|x64.Build.0 = Release|x64
     52                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Release|x86.ActiveCfg = Release|Win32
     53                {569037E7-4D03-4412-8CC1-DE51435C0BBE}.Release|x86.Build.0 = Release|Win32
    4454        EndGlobalSection
    4555        GlobalSection(SolutionProperties) = preSolution
  • VulkanGame.vcxproj

    r27c40ce r7bf5433  
    7171  <PropertyGroup Label="UserMacros" />
    7272  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    73     <IncludePath>include;$(IncludePath)</IncludePath>
     73    <IncludePath>include;D:\VulkanSDK\1.1.108.0\Include;$(IncludePath)</IncludePath>
    7474    <LibraryPath>lib;D:\VulkanSDK\1.1.108.0\Lib;$(LibraryPath)</LibraryPath>
    7575  </PropertyGroup>
     
    8282      <LanguageStandard>stdcpp17</LanguageStandard>
    8383      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;GAMEGUI_INCLUDE_VULKAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    84       <AdditionalIncludeDirectories>D:\VulkanSDK\1.1.108.0\Include;include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     84      <AdditionalIncludeDirectories>
     85      </AdditionalIncludeDirectories>
    8586    </ClCompile>
    8687    <Link>
     
    139140  </ItemGroup>
    140141  <ItemGroup>
     142    <ClInclude Include="compiler.hpp" />
    141143    <ClInclude Include="consts.hpp" />
    142144    <ClInclude Include="crash-logger.hpp" />
  • game-gui-glfw.cpp

    r27c40ce r7bf5433  
    11#include "game-gui-glfw.hpp"
     2
     3#include <queue>
    24
    35#include "compiler.hpp"
    46#include "consts.hpp"
    57
    6 const int KEY_STATE_UNCHANGED = -1;
     8int GameGui_GLFW::s_keyState[GLFW_KEY_LAST];
     9bool GameGui_GLFW::s_keyDown[GLFW_KEY_LAST];
     10
     11// queue<MouseEvent> mouseEvents;
    712
    813string GameGui_GLFW::s_errorMessage;
    9 
    10 int GameGui_GLFW::s_keyState[NUM_KEYS];
    11 bool GameGui_GLFW::s_keyDown[NUM_KEYS];
    1214
    1315string& GameGui_GLFW::getError() {
     
    6264   //glfwMakeContextCurrent(window);
    6365
    64    //glfwSetMouseButtonCallback(window, mouse_button_callback);
     66   glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
    6567   glfwSetKeyCallback(window, glfw_key_callback);
    6668
    67    fill(GameGui_GLFW::s_keyState, GameGui_GLFW::s_keyState + NUM_KEYS, KEY_STATE_UNCHANGED);
     69   // fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);
     70   // fill(s_keyDown, s_keyDown + GLFW_KEY_LAST, false);
    6871
    6972   return window;
     
    7477   glfwDestroyWindow(window);
    7578}
     79
     80/*
     81void GameGui_GLFW::processEvents() {
     82   fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);
     83
     84   glfwPollEvents();
     85}
     86
     87unsigned char GameGui_GLFW::getKeyEvent(unsigned int key) {
     88   return s_keyState[key];
     89}
     90
     91bool GameGui_GLFW::isKeyPressed(unsigned int key) {
     92   return s_keyDown[key];
     93}
     94
     95int GameGui_GLFW::pollMouseEvent(MouseEvent* event) {
     96   if (mouseEvents.empty()) {
     97      return 0;
     98   }
     99
     100   *event = mouseEvents.front();
     101   mouseEvents.pop();
     102
     103   return 1;
     104}
     105*/
    76106
    77107#ifdef GAMEGUI_INCLUDE_VULKAN
     
    107137}
    108138
     139void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {
     140   double x, y;
     141   glfwGetCursorPos(window, &x, &y);
     142
     143   /*
     144   MouseEvent e { button, action, (int)x, (int)y };
     145
     146   mouseEvents.push(e);
     147   */
     148}
     149
    109150void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
    110151   GameGui_GLFW::s_keyState[key] = action;
     152   /*
     153   switch(action) {
     154      case GLFW_PRESS:
     155         s_keyState[key] = RTWO_KEY_EVENT_PRESSED;
     156         break;
     157      case GLFW_RELEASE:
     158         s_keyState[key] = RTWO_KEY_EVENT_RELEASED;
     159         break;
     160      default:
     161         s_keyState[key] = RTWO_KEY_EVENT_NONE;
     162         break;
     163   }
    111164
    112165   // should be true for GLFW_PRESS and GLFW_REPEAT
    113166   GameGui_GLFW::s_keyDown[key] = (action != GLFW_RELEASE);
     167   */
    114168}
  • game-gui-glfw.hpp

    r27c40ce r7bf5433  
    1010#include <GLFW/glfw3.h>
    1111
    12 #define NUM_KEYS (512)
    13 
    1412class GameGui_GLFW : public GameGui {
    1513   public:
     
    1816      // Both have to be public so that glfw_key_callback can access them
    1917      // TODO: Implement a more generic public api over this to get the key state
    20       static int s_keyState[NUM_KEYS];
    21       static bool s_keyDown[NUM_KEYS];
     18      static int s_keyState[GLFW_KEY_LAST];
     19      static bool s_keyDown[GLFW_KEY_LAST];
    2220
    2321      string& getError();
     
    2826      void* createWindow(const string& title, int width, int height, bool fullscreen);
    2927      void destroyWindow();
     28
     29      /*
     30      void processEvents();
     31
     32      unsigned char getKeyEvent(unsigned int key);
     33      bool isKeyPressed(unsigned int key);
     34
     35      int pollMouseEvent(MouseEvent* event);
     36      */
    3037
    3138#ifdef GAMEGUI_INCLUDE_VULKAN
     
    4350
    4451void glfw_error_callback(int error, const char* description);
     52void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
    4553void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
    4654
  • opengl-game.cpp

    r27c40ce r7bf5433  
    5757
    5858void OpenGLGame::mainLoop() {
     59   //MouseEvent e;
     60
    5961   while (!glfwWindowShouldClose(window)) {
     62      /*
     63      gui->processEvents();
     64
     65      if (gui->getKeyEvent(GLFW_KEY_ESCAPE) == RTWO_KEY_EVENT_PRESSED) {
     66         glfwSetWindowShouldClose(window, 1);
     67      }
     68
     69      while (gui->pollMouseEvent(&e)) {
     70         cout << "Mouse click detected at (" << e.x << ", " << e.y << ")" << endl;
     71      }
     72      */
     73
    6074      glfwPollEvents();
    6175
Note: See TracChangeset for help on using the changeset viewer.