PDA

View Full Version : gluProject not giving the same pixel as glVertex3d



chrisstankevitz
12-19-2008, 03:57 PM
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):


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.



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:


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

ZbuffeR
12-19-2008, 04:22 PM
All 3D hardware I am aware of only uses 32bit floats. Your doubles are first converted to floats before going into the video card.

chrisstankevitz
12-19-2008, 04:23 PM
That would explain it. thank you.