Results 1 to 3 of 3

Thread: gluProject not giving the same pixel as glVertex3d

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    9

    gluProject not giving the same pixel as glVertex3d

    Hello,


    I set my camera up at the ECEF value equivalent to Lon/Lat/Alt -120/0/500 (about 6e6 meters/units from the origin) looking toward the center of the earth with an orthographic projection 6 meters/units wide by 4 meters tall.

    These are extreme values (10^6 from the center, dealing with values 10^-2) but well within the capability of 64 bit floats. Here is how things are setup (partial copy/paste from my code with variables filled in):

    Code :
    glViewport(
    0, 
    0,
    1680, 
    984);
     
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity ();
     
    glOrtho(
    -2.8923234490162368,
    2.8923234490162368,
    -1.6940751629952242,
    1.6940751629952242,
    500.00000000000000,
    12758274.000000000);
     
    gluLookAt(
    -3189568.5000000037,
    -5524494.6962212501,
    0.00000000000000000,
    0.50000000000000056,
    0.86602540378443826,
    -0.00000000000000000);
     
    glMatrixMode(GL_MODELVIEW);
     
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    glLoadIdentity();

    gluProject confirms that a point will appear in the correct pixel.

    Code :
    std::vector<double> mProjectionMatrix;
    std::vector<double> mModelviewMatrix;
    std::vector<int>    mViewportVector;
    mModelviewMatrix.resize(16);
    mProjectionMatrix.resize(16);
    mViewportVector.resize(4);
     
    glGetDoublev( GL_MODELVIEW_MATRIX, &amp;(mModelviewMatrix[0]) );
    glGetDoublev( GL_PROJECTION_MATRIX, &amp;(mProjectionMatrix[0]) );
    glGetIntegerv( GL_VIEWPORT, &amp;(mViewportVector[0]) );
     
    gluProject(
      -3189071.1178866909,
      -5523627.1593787950,
      -1.6906319431479520,
      &amp;(mProjectionMatrix[0]),
      &amp;(mModelviewMatrix[0]),
      &amp;(mViewportVector[0]),
      &amp;PixelX,
      &amp;PixelY,
      &amp;PixelZ);

    PixelX = 2.9967977246269584
    PixelY = 0.99999999999996447
    PixelZ = 3.9133395107027180e-005
    (Thee pixels from the left edge of the screen)

    However, when I actually draw the pixel in the next line of c++, the pixel is dran approximately 50 pixels from the left edge of the screen:

    Code :
    glBegin(GL_POINTS);
    glVertex3d(
      -3189071.1178866909,
      -5523627.1593787950,
      -1.6906319431479520,
    );
    glEnd();

    Pixel draws at approx (50, 1) on my screen, to the right of where it should be

    Question1: Why is my video card not drawing my glVertex3d in the same place gluProject is reporting it to go?

    Question2: Is my video hardware using 64 bit floats, like gluProject is?

    Thank you,

    Chris

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: gluProject not giving the same pixel as glVertex3d

    All 3D hardware I am aware of only uses 32bit floats. Your doubles are first converted to floats before going into the video card.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    9

    Re: gluProject not giving the same pixel as glVertex3d

    That would explain it. thank you.

Similar Threads

  1. gluProject giving wrong results
    By Rick93NL in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-24-2012, 04:23 AM
  2. books without giving money????
    By vivek vyas in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-05-2009, 01:48 PM
  3. "Blue" giving me the blues
    By bronze in forum OpenGL: User Software
    Replies: 3
    Last Post: 02-20-2005, 04:55 AM
  4. gluUnProject() is giving me trouble
    By Tokage in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 07-26-2004, 03:41 PM
  5. gl.h giving me problems
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-15-2001, 11:20 AM

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