Mouse Input

Introduction

Mouse InputIn many of your programs you will need the option of accepting pointer input. This tutorial will explain how to capture messages sent by using a pointing device on the window.

If you are using GLUT|ES, please consult the GLUT on how to capture input from the mouse. The code is almost exactly the same for the stylus. Also make sure that you download the source code at the bottom of this page.

Contents of main.cpp :


The first step is to create a function that will process all pointer input. This function must accept certain parameters.

The first parameter must accept a UGWindow variable.

The second parameter must be an integer. This specifies what button has been pressed. The possible values can be either UG_BUT_LEFTUG_BUT_MIDDLE or UG_BUT_RIGHT.

The third parameter must also be an integer. This specifies what state the button was in. The two states areUG_BUT_DOWN and UG_BUT_UP signalling when the pointing device has been pressed and when it has been lifted.

The fourth and fifth parameters must also both be integers. These specify the x and y value of the pointing device when the key was pressed.

void pointer(UGWindow uwin, int button, int state, int x, int y)
{

We simply exit the program if the pointing device is pressed.

	exit(0);
}

The window needs to know what function we are using for processing pointer presses. We therefore place a call to the ugPointerFunc function along with the ugDisplayFunc function. This function takes the handle to the OpenGL window as its first parameter and the pointer function as its second.

	ugPointerFunc(uwin, pointer);

You should now be able to process pointer messages. If you run this program, you will still not see any graphics occur, but you can quit the program by either clicking on the screen with your pointing device or by pressing theq or up arrow keys.

Please let me know of any comments you may have : Contact Me

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值