Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / glPicking and GL_POINTS. Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
Gavin John Costello

April 30, 2005, 01:11 AM

Hi, as a minor part of a "demonstration program" for a library I'm writing, I required to take some user input (mouse clicks) and use that information to select certain nodes.

Now... so far as I can see, it all works fine, if you click nothing, then there is nothing in selection buffer. If you do click on a node, then the vProcessHits() function is called... as it should be.

The thing is, the names that I push onto the stack before rendering the nodes don't seem to be actually stored. The program detects that I've clicked on a node, but the number of names in the selection buffer is 0.

I was wondering if this was because I'm rendering the nodes as GL_POINTS (yes, it can still detect the hits), and whether the naming only works with display lists? (if so I'll just slap a small sphere in a display list and use that for the nodes).

... Just in-case you SHOULD be able to push names with GL_POINTS I'll post the code (basically) that I'm using.

  2.                 glBegin(GL_POINTS);
  3.                         glColor3f(0.0f, 1.0f, 0.2f);
  4.                         if(shared.currentState == CShared_t::currentState_t::STATE_PICKING)
  5.                         {
  6.                                 glPushName(i);
  7.                         }
  8.                         glVertex3f(thisNode->position.x, thisNode->position.y, thisNode->position.z);
  9.                         if(shared.currentState == CShared_t::currentState_t::STATE_PICKING)
  10.                         {
  11.                                 glPopName();
  12.                         }
  13.                         glColor3f(1.0f, 1.0f, 1.0f);
  14.                 glEnd();

The points are rendered if we're in STATE_RENDER mode (basic rendering) or STATE_PICKING mode (after a mouse click has been processed).

NOTE: 'i' is just the number of the node (they're being rendered from a vector, i is the reference value for that node in the vector)

Any help appreciated, thanks.


Rui Martins

April 30, 2005, 05:23 AM

Show us the code where you actually check the selection buffer.

It seems you are missing something there, or you are testing it when you shouldn't, when not picking.

Or even simpler, you could be failing to setup the selection buffer correctly.

Gavin John Costello

April 30, 2005, 12:50 PM

I did it exactly like this:

(seeing as it wasn't a major part of the program a simple tutorial was enough).

Gavin John Costello

April 30, 2005, 05:06 PM

... it still doesn't work though btw (that previous post wasn't "I got it working like this: *link*" ... it was "Here's how I tried it... but it doesn't work: *link")

Tomas H

May 04, 2005, 07:48 AM

Are you sure you're allowed to do glPushName()/glPopName within glBegin()/glEnd()? Try moving them outside:

  1. glPushName(i);
  2. glBegin(GL_POINTS);
  3. //...
  4. glEnd();
  5. glPopName();

If that was the error, you might want to consider using glGetError() to check for errors..

Gavin John Costello

May 04, 2005, 09:25 AM

That was exactly the problem. Thank you! I didn't know that you couldn't push or pop names from the stack between glBegin and glEnd!

You learn something new every day eh?

Much appreciated


This thread contains 6 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.