Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the position of a user mouse click in C & GLUT

Tags:

c

mouse

glut

I would like to store the user's mouse click position on two variables

float x,y;

I'm using openGL with C. I already have a mouse function using glut, but when I try to print x and y, it gives me values like x = 134; y = 150, while my screen ortho is between 0 and 1.

I want to get the exact points to draw a point there.

like image 473
Lily Avatar asked Nov 15 '12 14:11

Lily


1 Answers

you need to register a mouse callback function it has the following signature:

void glutMouseFunc(void (*func)(int button, int state,
                                int x, int y));

There's a tutorial that covers some basics here

Edit: If you want the position to be normalized (0.0 - 1.0) divide by the width and height:

float x1 = x /(float) width;
float y1 = y /(float) height;
like image 52
iabdalkader Avatar answered Sep 26 '22 18:09

iabdalkader