PDA

View Full Version : GL_SELECT



SteeleR
10-29-2006, 09:51 AM
GLuint selectBuf[100];
GLint hits;
GLint viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (100, selectBuf);

glRenderMode(GL_SELECT);
glInitNames();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix( cX, viewport[3]-cY, 5.0, 5.0, viewport);
glMatrixMode(GL_MODELVIEW);
DrawObjects();
glPopMatrix();
glFlush();

hits = glRenderMode (GL_RENDER);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
cX and cY are the current mouse coords... but when the SELECT mode is trigged.. the viewport becomes only a small part of the screen and the selection of the objects can be done only there.. i.e. if i draw a red rectangle and press the mouse on or near it.. the screen becames red and I can only select there.. so the result is always this rect. Any ideas how to fix it?
10x...

Bob
10-29-2006, 01:44 PM
You push the projection matrix but pop the modelview matrix. All matrix modes have their own indepdendend stack, so if you push while the projection matrix is current, you must pop when it's current too.

k_szczech
10-29-2006, 01:57 PM
glMatrixMode(GL_PROJECTION);
glPushMatrix();
(...)
glMatrixMode(GL_MODELVIEW);
DrawObjects();
glPopMatrix();I don't know what the DrawObjects function does, but it looks like you have stack overflow with projection matrix and stack underflow with modelview matrix.

SteeleR
10-29-2006, 08:42 PM
added


glMatrixMode(GL_PROJECTION);
glPopMatrix();
before the glPopMatrix(); but no effect.. still getting area arround the center only...
Could it be cause I'm not using glProjection ?

Ther
10-29-2006, 10:17 PM
why don't you set up projection matrix ?


gluLookAt( eyex, eyey, eyez, lookx, looky, lookz, 0,1,0 ) ;

Ther
10-29-2006, 10:20 PM
so it could cause, cause at init you should setup, for opengl the bounding space:


gluPerspective( 45, 1, 0.1 , 100 );

SteeleR
10-29-2006, 10:40 PM
added the gluPerspective.. but the result is the same...

the view fixes after I resize the window with glOrtho.. but the selection area is still the same - samo pixels around the center coors...

gluLookAt doen't helps, too..

k_szczech
10-30-2006, 04:17 AM
Many things could go wrong:
-matrices
-viewport settings
-scissor settings
-depth test
-stencil test
-alpha test
-clip planes
-and many others
All of the above can affect vertices or pixels. I assume you're not using alpha test, stencil test nor clip planes.
Most likely you have problem with scissor test, viewport or matrices. Make sure you handle matrices properly - otherwise your program can go bananas. Remember that vertices are transformed by both projection and modelview matrix. Tutorials and examples are definitely not enough to understand matrices - some book would definitely help.
It could be depth buffer, too - make sure you clear it.
So inspect your code and clean it up - you'll probably find some more misuses of matrices or perhaps you will find some mysterious glScissor?
If you won't be able to solve this yourself, then you will have to post more code.

SteeleR
10-30-2006, 09:04 AM
Fixed! :) turned out that I have to use and the glOrtho befo rendering the scene in GL_SELECT mode :)

10x all :)