gluProject and gluUnproject source (for float data)

Hi… does anyone have the source for GLU functions gluProject and gluUnProject???

I want to create float versions of them so I do not need to convert my matrices to double every frame. I made a float version of gluProject and it matches the results from the original double version. Here it is:

void gluProject_float(const vector3& p_obj, vector3& p_win)
    vector4 t;
    t = p_obj * view_matrix; // v3 * m(4x3)
    t = t * proj_matrix; // v4 * m(4x4)
    p_win.x = win_sizex * (t.x / t.w + 1.0f) * 0.5f;
    p_win.y = win_sizey * (t.y / t.w + 1.0f) * 0.5f;
    p_win.z = (t.z / t.w + 1.0f) * 0.5f;

But can not find any info on how to implement gluUnProject. Any links for its definition or implementation in GLU???

I need this for a deferred shading demo … works ok when converting to double before gluUnProject but think a float version would be nice as I do not use double anywere else.

Your code for gluProject looks weird.
Shouldn’t that be

vector4 t;
t = view_matrix * p_obj; // v3 * m(4x3)
t = proj_matrix * t; // v4 * m(4x4)

I have a lib that is a a glu replacement

The functions you would be interested in

  1. glhProjectd
  2. glhProjectf
  3. glhUnProjectd
  4. glhUnProjectf
  5. glhProjectf_2
  6. glhProjectf_3
  7. glhUnProjectf_2
  8. glhUnProjectf_3
  9. glhProjectf_SSE_Aligned_2
  10. glhProjectf_SSE_Aligned_WarmCache_2
  11. glhProjectf_SSE_Unaligned_2
  12. glhUnProjectf_SSE_Aligned_2
  13. glhUnProjectf_SSE_Aligned_WarmCache_2
  14. glhUnProjectf_SSE_Unaligned_2

The 5 to 14 are for mass processing.

The source for the original GLU can be found in MESA (

Go to and get the latest source for the Mesa library, which includes its own version of libGLU, as well as SGI’s implementation.

Look at:





Thanks for the links and the quick reply.

V-man, the (matrix * vector) or (vertor * matrix) would be the same thing… anyway that was just a pseudo code not my actual code.

And thanks again for the library and source link.