我正在尝试运行一个使用我自己构建的GLFW和GLEW库的OpenGL程序.我使用的入门代码是
#include <iostream>
// GLEW
#define GLEW_STATIC
#include <glew.h>
// GLFW
#include <glfw3.h>
// Function prototypes
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode);
// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;
// The MAIN function, from here we start the application and run the game loop
int main()
{
std::cout << "Starting GLFW context, OpenGL 3.3" << std::endl;
// Init GLFW
glfwInit();
// Set all the required options for GLFW
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, …Run Code Online (Sandbox Code Playgroud) 假设我要在 GLFW 中设置回调函数
glfwSetCursorPosCallback(window, mouse);
Run Code Online (Sandbox Code Playgroud)
检索光标位置的最明显的方法是
vec2 m;
void mouse (GLFWwindow* window, GLdouble x, GLdouble y)
{
m = vec2 (x, y);
}
Run Code Online (Sandbox Code Playgroud)
但是,我更愿意在不使用全局变量的情况下这样做。能做到吗?