Dear All,
I have one more doubt,
When I click the mouse on a square(say 3rd square on the 5th row), in the mesh it should print
the print as row = 5 and colum = 3)
I used glutMouseFunc(mouse) and wrote the following code for mouse call back. But it is not printing the exact row column value.
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
void make_mesh()
{
float x, y;
glBegin(GL_LINES);
for (x = -5; x <= 5; x += 1.0f) // x += 1.0f Stands For 1 Meter Of Space In This Example
{
glVertex3f(x, 5.0, 0);
glVertex3f(x, -5.0, 0);
}
// Draw The Horizontal Lines
for (y = -5; y <= 5; y += 1.0f) // y += 1.0f Stands For 1 Meter Of Space In This Example
{
glVertex3f( 5.0, y, 0);
glVertex3f( -5.0, y, 0);
}
glEnd();
}
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity();
make_mesh();
glFlush();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-5.0, 5.0, -5.0, 5.0, -1.0, 1.0);
glMatrixMode (GL_MODELVIEW);
}
void mouse(int button, int state, int x, int y)
{
int mx = x * 10/500;
int my = y * 10/500;
printf("Value of x = %d
", x);
printf("Value of y = %d
", y);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}