hopestar
October 24th, 2002, 11:04 PM
I've been searching around the internet for a while now and I'm not finding the answer to my question so I thought I'd give this a whirl...
All I want to do is click on a point in my application's window and have the app draw a dot at that point. My problem comes in when I use the coordinates I get from unprojecting the mouse click to draw the point. The window size is 600 x 600 but my viewing area is set up as glOrtho(-30, 30, -30, 30, -10, 10)
Is there a way to unproject the mouse click to the glOrtho coordinates? If there is, does it lose too much accuracy?
Thanks for any help!!
Zeeshan
October 25th, 2002, 01:17 AM
Take a look at this.
// draw point on mouse click
#include <GL/glut.h>
/* to remove Console Window */
#pragma comment(linker, "/subsystem:windows")
#pragma comment(linker, "/entry:mainCRTStartup")
GLint g_iHeight = 500;
GLint g_iWidth = 500;
void display()
{
glClearColor(1.0, 1.0, 1.0, 1.0); /* set current color to white */
glClear(GL_COLOR_BUFFER_BIT); /* clear the display */
glFlush();
}
void drawPoint(int x, int y)
{
glPointSize(3);
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POINTS);
glVertex2i(x, g_iHeight - y);
glEnd();
glFlush();
}
void mouse(int button, int state, int x, int y)
{
switch (button)
{
case GLUT_LEFT_BUTTON:
if (GLUT_DOWN == state)
{
drawPoint(x, y);
}
break;
}
}
void reshape(GLint width, GLint height)
{
/* update the value of variable whenever window resize */
g_iWidth = width;
g_iHeight = height;
//gluOrtho2D(0, 0 + g_iWidth, 0, 0 + g_iHeight);
}
int main(int argc, char *argv[])
{
/* initialize GLUT system */
glutInit(&argc, argv);
/* initilise it to use double buffer */
glutInitDisplayMode(GLUT_RGB);
/* width=500 pixels height=500 pixels */
glutInitWindowSize(g_iWidth, g_iHeight);
/* set window position to 100, 100 */
glutInitWindowPosition(100, 100);
/* create window */
glutCreateWindow("GL Test");
/* how object is mapped to window */
gluOrtho2D(0, 0 + g_iWidth, 0, 0 + g_iHeight);
/* register mouse function */
glutMouseFunc(mouse);
/* register function when window resize */
glutReshapeFunc(reshape);
/* register window display function */
glutDisplayFunc(display);
/* start processing events */
glutMainLoop();
return 0;
}
Hope it helps.