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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章