Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Pixel coordinates with gluPerspective

  1. #1
    Guest

    Pixel coordinates with gluPerspective

    When using glOrtho2D( ), my mouse handler would return an int x, y position of the mouse click.

    I could then set the pixel at that point to a particular color, etc.

    I am trying 3D drawing now, with the following:

    glViewport (0, 0, 500, 500);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    gluPerspective(65.0, (GLfloat) 500/ (GLfloat) 500, 1.0, 20.0);
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    Now, when i click the window with my mouse, I still get integer coordinates - but they can no longer be displayed on the window.

    The problem is that the scaling has changed, so that plotting (0,0,0) is at the center of the window, and (1,0,0) is about an inch to the right of the origin - instead of just one pixel to the right.

    Is there any way at all to use mouse coordinates with the perspective projection functions?

    Thanks
    chetty

  2. #2
    Guest

    Re: Pixel coordinates with gluPerspective

    Okay ... found the answer ... gluUnProject( )

    Now I need to make it work in my program (!)

    Thanks to past posters who ran into the same issue :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •