iDevGames Forums
Two gluProject points? - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Two gluProject points? (/thread-9670.html)

Two gluProject points? - mikey - Jan 2, 2012 11:58 AM

Hi all,

I have been using gluProject in my 3D scene with the following code:

y_position, z_position, model_view_matrix, projection_matrix, viewport, &label_position_x, &label_position_y, &label_position_z);

print("Marker" ,label_position_x,label_position_y);

    glGetDoublev(GL_MODELVIEW_MATRIX, model_view_matrix);
    glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
    glGetIntegerv(GL_VIEWPORT, viewport);
(Please let me know if you think you need more code)

The problem is that the label 'Marker' is being drawn twice, once where it is supposed to be at (3D Object) and then again when the user is facing away from the object, but in the right position. That is, when I face the real marker, then turn exactly 180 degrees around there is another fake marker.

I think this may have something to do with a Z coordinate from gluProject, but I tried only drawing the marker when label_position_z was less than 0 and then only when more than 0; no results, still two markers.

Any help is greatly appreciated,


RE: Two gluProject points? - OneSadCookie - Jan 2, 2012 12:39 PM

z_position is a window z coordinate. How are you getting it?

RE: Two gluProject points? - mikey - Jan 2, 2012 01:23 PM

What do you mean? I am inputting the x_position, y_position and z_position as geographical locations in my world.

Quote:GLint gluProject( GLdouble objX,
GLdouble objY,
GLdouble objZ,
const GLdouble * model,
const GLdouble * proj,
const GLint * view,
GLdouble* winX,
GLdouble* winY,
GLdouble* winZ);


objX, objY, objZ
Specify the object coordinates.
- OpenGL Wiki

RE: Two gluProject points? - OneSadCookie - Jan 3, 2012 12:41 AM

oh yeah, sorry, I'm backward, despite having worried that I might be backward :/

How are you drawing the marker at the calculated window coords?

RE: Two gluProject points? - mikey - Jan 3, 2012 11:20 AM

Here's the function call in the previous code:

And the function defenition:

int print(string printstring, float cursorx, float cursory)
    int qs;
        glRasterPos2f(cursorx, cursory);

    for (qs = 0; qs < printstring.length(); qs++)
        cursorx += glutBitmapWidth(GLUT_BITMAP_8_BY_13,;
    //    cout << "printing " << << ". \n";

I am also drawing a circle at the same position (label_position_x,label_position_y). This behaves with the text.

RE: Two gluProject points? - mikey - Jan 5, 2012 01:03 PM

The label_x and label_y coordinates are definetly right, I think that somewhere a Z coordinate is being neglected, but I can't find any appropriate... n.b. label_position_z is always 1.0, is this correct?