PDA

View Full Version : glUnProject??



Mishuk
07-11-2002, 11:01 AM
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

no-one
07-11-2002, 08:24 PM
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,V iewport,&newX,&newY,&newZ);
glPopMatrix();




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

JML
07-11-2002, 09:06 PM
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.

Mishuk
07-12-2002, 12:14 PM
To design 2D GUI how to implement it without
glUnProject? Can you give me some hints?

no-one
07-14-2002, 08:50 AM
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).]

Mishuk
07-15-2002, 09:50 AM
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

no-one
07-16-2002, 07:13 AM
>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.