glUnProject??

Hi!
I’m new in OpenGL.
I badly need some easy code of using glUnproject. How does it work ? How to make button in openGL using glUnproject? Is there any better way to make interface or button in opebGL?
Please please help me

    GLint Viewport[4];

GLdouble ModelMatrix[16];
GLdouble ProjMatrix[16];
float z1;
double winX = 10;
double winY = 10;
double newX;
double newY;
double newZ;

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glGetDoublev(GL_MODELVIEW_MATRIX,ModelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX,ProjMatrix);
glGetIntegerv(GL_VIEWPORT,Viewport);
glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z1);
gluUnProject(winX,winY,z1,ModelMatrix,ProjMatrix,Viewport,&newX,&newY,&newZ);
glPopMatrix();

[This message has been edited by no-one (edited 07-11-2002).]

Mishuk,

If you are looking for ways to create a 2D GUI ‘on top’ of your 3D drawings, don’t use gluUnproject, but setup a glOrtho projection after drawing the 3D stuff and render in 2D (possibly without depth-writing & testing to prevent 3D geometry obscuring the GUI).

HTH

Jean-Marc.

To design 2D GUI how to implement it without
glUnProject? Can you give me some hints?

something like this?

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
// set the top left to 0,0 and the bottom right to 800 by 600
glOrtho(0,800,600,0,1.0,-1.0);

  DrawGuiStuff();

glPopMatrix();
glMatrixMode(GL_MODELVIEW);

[This message has been edited by no-one (edited 07-14-2002).]

Thank you.
But in this case how can i implement mouse coordinate to associate with the GUI without glUnProject? Is it possible to implement it without glUnProject?

Moreover i saw some code about Selection and picking. Is is usual technique to make GUI?

thanks

>Is it possible to implement it without glUnProject?

yes, if you set the projection and viewport the same size, then yes, the mouse coordinates will be in natural window coordinates, or in relation to the desktop in which case you’ll have to adjust them by getting the windows position and adjust accordingly.

>
Moreover i saw some code about Selection and picking. Is is usual technique to make GUI?
<

it depends, OpenGL picking has the possibility of HW acceleration, though both are quite feasible, its really up to which you prefer, though selection without GL can get fairly complicated if your not used to it.