我设计的glfw按键检测类和其回调函数

35 篇文章 0 订阅
7 篇文章 0 订阅

一直想找个基于opengl的utilit好做游戏引擎 这几天看见了glfw,感觉不错

 

代码如下:

 

这后这样 int KeyEvent::key = 0;

 

在之后来一个实例

KeyEvent keyevent;

之后记得这样

glfwSetKeyCallback( KeyEvent::keyfun );

这些都是在初始化中完成的

之后在循环过程中这样

printf("按键是: %d/n", kk.get_key());

获得了案件的当前值 那么就可以做一些响应了  呼呼

 

那么对于鼠标应该一样 如下所示:

void GLFWCALL Fun(int x, int y)

{

 

       //获取鼠标位置的处理...

}

 

在上面的 x就是 GLFW_MOUSE_BUTTON_LEFT

                       GLFW_MOUSE_BUTTON_RIGHT

                       GLFW_MOUSE_BUTTON_MIDDLE

              y就是相应的动作   GLFW_PRESS or GLFW_RELEASE

在使用的时候,初始化:

glfwSetMouseButtonCallback( fun);

 

在循环中根据用户的鼠标位置做相应的处理

 

 

关于鼠标的最后一个函数是: void glfwSetMouseWheelCallback( GLFWmousewheelfun cbfun )

其相应的回调函数是void GLFWCALL functionname( int pos );

 

感觉很好理解

 

不过最后这里再给出一个相关的函数

void glfwSetCharCallback( GLFWcharfun cbfun )

其中cbfun的c函数原型是

void GLFWCALL functionname( int character, int action );

第二个参数还是GLFW_PRESS or GLFW_RELEASE.

 

需要说明的就是每次只取一个字符

 

附加一段说明

Character events are recorded continuously, but only reported when glfwPollEvents, glfwWaitEvents or glfwSwapBuffers is called. Control characters, such as tab and carriage return, are not reported to the character callback function, since they are not part of the Unicode character set. Use the key callback function for such events  。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值