Results 1 to 2 of 2

Thread: gluunproject

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    10

    gluunproject

    Hi all,

    I am new to Opengl. I am working on a navigation application.
    The map is displayed in perspective mode using glfrustum.
    When the mouse is clicked on the map, I use glUnproject to map the window coordinate to the original object coordinate.

    To get the z-coordinate for the click position (to pass it to glUnproject), I have tried the following methods. None of them worked propely for me.

    1) glReadPixels(x, height-y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);

    int nResult = gluUnProject(x, height-y, z, m_pdModelMatrix, m_pdProjMatrix, m_pnViewport, &winx, &winy, &winz );

    The value of z returned from glreadpixel is always 0 and hence i dont get the right coordinate

    2) I tried to the relative z coordinate using following method

    gluProject(0,0,0,m_pdModelMatrix,m_pdProjMatrix, m_pnViewport, &winx, &winy, &z);

    int nResult = gluUnProject(x, y, z, m_pdModelMatrix, m_pdProjMatrix, m_pnViewport, &winx, &winy, &winz );

    I get a coordinate which is somewhere close to the object. But i dont get the accurate value.


    Following are some patches i have used in code to get the expected perspective view. I am not sure if the problem is caused by any of these.

    glFrustum (-width/40, width/40, -height/20, height/20, 1, 80 );
    glTranslatef (0, 0, -21.0); /* viewing transformation */
    glScalef (1, 1, 1); /* modeling transformation */

    1) As such the range of all the vertices is from -width/2 to width/2 and -height/2 to height/2.
    But the value given in glfrustum is totally different.

    2) The range of z value of all coordinates is from 1 to 20. I have calculated the value of z based on the value of y. I have just given the same value of y to z simply mapping it to suite the range of 1 to 20.
    But the value given in glfrustum is 1 to 80.

    Kindly tell me if there is a better way to do this and the reason for inaccurate results.

    Thanks in advance.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,651

    Re: gluunproject

    Quote Originally Posted by Ramya Maithreyi
    1) glReadPixels(x, height-y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);

    The value of z returned from glreadpixel is always 0 and hence i dont get the right coordinate
    This suggests one or more of your arguments are incorrect, or the framebuffer you want to read is not the active ReadBuffer.

Similar Threads

  1. gluUnProject
    By Raiden in forum OpenGL: Linux
    Replies: 1
    Last Post: 04-11-2005, 09:33 AM
  2. gluUnProject
    By Amir in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-10-2004, 01:53 PM
  3. Example of gluUnProject
    By jirkamelich in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-11-2002, 08:53 AM
  4. gluUnProject
    By mphanke in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-24-2002, 08:28 AM
  5. Once again, gluUnProject...
    By Tanus in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-08-2001, 05:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean