小编Arh*_*ama的帖子

如何在 GLFW 中为游戏引擎设置正确的输入类

我正在做我的一个小项目,我基本上是在创建我自己的 C++ 游戏引擎/框架来创建图形和/或简单的游戏。我将 OpenGL 与 GLFW 一起使用。我的目标是拥有类似于各种图形框架的东西,比如 raylib 或 openFrameworks(但当然是精简了)

实际上到目前为止一切正常,但我无法弄清楚如何正确地将输入与窗口类分开,因为窗口句柄输入对我来说似乎相当笨重,只会使窗口类变得混乱。

这是对我的窗口类的快速过度简化。(我没有在键码中包含枚举类。)

#pragma once
#include "../extern/GLFW/glfw3.h"
#include <string>
class Window {
private:
    GLFWwindow* mWindow;
    int mWidth;
    int mHeight;
    std::string mTitle;

public:
    Window();
    ~Window();

    void createWindow(std::string title, int width, int height);
    void mainLoop();

    GLFWwindow* getWindow() const { return mWindow; }


// Input
private:

    bool Window::getKeyStatus(KEY key) {
    static void keyCallback(GLFWwindow* mWindow, int key, int scancode, int action, int mods);
    bool isKeyDown(KEY key);
};
Run Code Online (Sandbox Code Playgroud)

这是实施加

#include "Window.h"
#include <iostream>

Window::Window() {}
Window::~Window() …
Run Code Online (Sandbox Code Playgroud)

c++ opengl input game-engine glfw

1
推荐指数
1
解决办法
3598
查看次数

标签 统计

c++ ×1

game-engine ×1

glfw ×1

input ×1

opengl ×1