OpenGL ES Tutorials


Mouse Input

Tutorials > OpenGL ES > Mouse Input

View Full Source


Mouse Input In 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_LEFT, UG_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 are UG_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.


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 the q or up arrow keys.

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

GLUT|ES Source Files : Embedded Visual C++ 4.0
UG Source Files : Embedded Visual C++ 4.0

Last Updated : 20 November 2005

< Tutorial 04 - Keyboard Input Tutorial 06 - Rendering >

Back to Top

All Rights Reserved, © Zeus Communication, Multimedia & Development 2004-2005

Read the Disclaimer