Please help with selection..

Started by
6 comments, last by Allebarde 21 years, 8 months ago
Hi! I have a problem with selection and it''s strange because i cut the code from a program i made a few time ago.. glInitNames(); glPushName(0); glLoadName(100); gluSphere(quadratic,2,10,10); glEnd(); if(MOUSE_DOWN(MOUSE_LEFT) && !MouseLeftClick) { MouseLeftClick=TRUE; int objectID = GetObjectID( pointMouse.x , pointMouse.y); if (objectID==BALLCLICK) MessageBox(NULL,"selection","ds",MB_OK); } with a char BALLCLICK = 100; When i click with a mouse i always se my message box, why? Thanks
Advertisement
glInitNames(); glPushName(0); glLoadName(100);glBegin(GL_LINES);glEnd();         gluSphere(quadratic,2,10,10);glEnd();//<-- Does this belong to gluSphere() ?if(MOUSE_DOWN(MOUSE_LEFT) && !MouseLeftClick) {MouseLeftClick=TRUE;int objectID = GetObjectID( pointMouse.x , pointMouse.y);if (objectID==BALLCLICK) MessageBox(NULL,"selection","ds",MB_OK);}with a char BALLCLICK = 100;  


[edited by - Jonus on August 16, 2002 10:37:47 AM]
Those 2 lines that you added are used to fix a voodoo2 problem..
It doesn''t concern my picking problem
const GLuint SOMETHING = 100;

or

#define SOMETHING 100

glInitNames();
glPushName(0);

glPushMatrix(); //Optinal

glLoadName(something);
gluSphere(quadric,1.0f,32,32);

glPopMatrix(); //Optinal

And then use the selection code but make sure that it''s corect!


The pain is coming...this sommer!!!
quote:Original post by Allebarde
Those 2 lines that you added are used to fix a voodoo2 problem..
It doesn't concern my picking problem
Wrong. On my nVidea TNT Card, picking won't work without those two lines. So its no PURE vodoo fix. The problem in your case are the quadrics.

Here is the explaination from the gametutorial.com tutorial:
	// If we use glLoadName(), then we need to end it with glEnd().  There is a problem	// though with some video cards that MUST have a glBegin()/glEnd() between	// the calls to glLoadName()/glEnd().  This is strange but some cards grind	// to a 2 FPS speed (VoodooCards).  Since we are using Quadrics there is	// no glBegin()/glEnd() being called explicitly, so we need to fake it.  	// *Remember, you only have to do this if you are using Quadrics.*  So, to fix 	// this we just put a empty glBegin()/glEnd() statement between each object ID passed in.	glBegin(GL_LINES);								glEnd();    
Get the turotial here.

[edited by - Jonus on August 17, 2002 8:05:42 AM]
I found where was the problem..
For picking i redraw all my scene in GL_SELECT_MODE.. The problem is that in my scene i display the FPS in projection mode, and when you pick something you musn''t switch into projection mode.
But just watch the new topic "How can i pick in projection mode?"

I draw a texture in projection mode and i just want to pick it
quote:Original post by Allebarde
I found where was the problem..
For picking i redraw all my scene in GL_SELECT_MODE.
Yes, only in select mode
glRenderMode(GL_SELECT); 
the name stack is filled.

quote:Original post by Allebarde
The problem is that in my scene i display the FPS in projection mode, and when you pick something you musn't switch into projection mode.
I don't get this sentence. What has a fps text output to do with selection?

quote:Original post by Allebarde
I draw a texture in projection mode and i just want to pick it
You draw a texture? Are you drawing a quad with a texture in it or do you use something like glBitmap?

[edited by - Jonus on August 17, 2002 9:32:11 AM]
Ok i explain all:
i''m making a pool game and all is working except one thing:
if you have ever played to a french pool, you know that you have to give some effects to the ball so that it rotates..

What i want to do is displaying a ball texture in projection mode at the bottom right hand side and i want the user to click on this ball texture to select where exactly he wants to hit the ball.
____
/ .\ he wants to hit here for example at the top right OK?
| |
\____/

i just want to use picking for knowing whether he''s clicking on the ball..
But i just saw that picking doesn''t work in projection mode, so how can i make it work? Shall i use a special matrix? i really don''t know how to do?


glSelectBuffer(32, selectBuffer); glGetIntegerv(GL_VIEWPORT, viewportCoords); glMatrixMode(GL_PROJECTION); glPushMatrix();
glRenderMode(GL_SELECT);
glLoadIdentity(); gluPickMatrix(x, viewportCoords[3]- y, 2, 2, viewportCoords);
gluPerspective(45.0f, float(ResolutionX)/float(ResolutionY) ,0.1f,150.0f);
glMatrixMode(GL_MODELVIEW);
// here i draw my quad ( texture representing the ball in projection mode) and before i do glPushName(blabla)..


objectsFound = glRenderMode(GL_RENDER);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

If i draw an object in perspective mode and not my texture ball the selection works well but the fact that i switch into projection mode for drawing my texture ball doesn''t allow me to pick..

Here is the code for drawing the texture:

glLoadName(100); // begin selection

glPushMatrix();

ProjectionMode(0,0,ResolutionX,ResolutionY);

glTranslatef(ResolutionX-ResolutionX/10.0f , ResolutionY - ResolutionY/7.5f ,0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _TGA[0].textureTGA);

glScalef(1.0f , float(ResolutionX)/float (ResolutionY) ,1.0f);

glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(- ResolutionX/10.0f, - ResolutionY/10.0f);
glTexCoord2f(1,0); glVertex2f( ResolutionX/10.0f , - ResolutionY/10.0f);
glTexCoord2f(1,1); glVertex2f(ResolutionX/10.0f , ResolutionY/10.0f );
glTexCoord2f(0,1); glVertex2f(- ResolutionX/10.0f, ResolutionY/10.0f );
glEnd();

PerspectiveMode();
glPopMatrix();

glEnd(); // end for picking

So is it clear??
Thanks a lot

This topic is closed to new replies.

Advertisement