Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Selection, Name stack, Hits - Newbie question

This topic is 6144 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I''ve tested my code pretty thoroughly and hits and everything is working. The only thing that isn''t working is the name stack.
GLint viewport[4];
	double ratio;






	ratio = (viewport[2]+0.0) / viewport[3];
that is more or less from a book. Next I draw ''tiles'' each with its own name using

	for ( X = 0; X < MAP_SIZE; X += STEP_SIZE )
		for ( Y = 0; Y < MAP_SIZE; Y += STEP_SIZE )

			x = X;					
			y = 0;	
			z = Y;							
			glColor3f(1.0f, 1.0f, 1.0f);
			glVertex3i(x, y, z);		





Is there anything wrong with that ? As far as I can tell from the examples PopName should be used but if I use it it will erase the name on top of the stack which I don''t want (I don''t think). Now when performing to see if I have any hits, I get 1 hit, but the names in the hit are always 0. If I put glPushName(-1); during initialisation it will return 1 name but it is always -1, so why does that count during initialisation but not during rendering ? and yes I''ve set the Render mode to SELECT. Any idea''s ? thanks in advance!

Share this post

Link to post
Share on other sites
Does it actually only return one name (GROUND) or two names (GROUND & whatever) per hit ?

Once you have pushed your first name, you can try using glLoadName()

Could you post a copy of your hit record ?

And... do you remember that nothing is returned until you come back to glRenderMode(GL_RENDER) ?

Edit: once you are done, you can erase the last name on the stack.

Edited by - Fruny on February 18, 2002 4:16:11 AM

Share this post

Link to post
Share on other sites
It is returning 1 hit with 0 names (if that is possible).

I''ll quickly try using glLoadName() and see if that makes a difference, thanks.

and yeah I''m switching back to GL_Render

Share this post

Link to post
Share on other sites
Okay when I inistialise I PushName(-1), then I use glLoadName to set the name for each quad/polygon and I always get the same results no matter what I click.

Hits = 1
number of names for hit = 1

z1 is 4248731479;
z2 is 4250548850

the name is -1

void processHits (GLint hits, GLuint buffer[])
GLint i, j;

GLuint names, *ptr;
Output("Hits = %d", hits);
ptr = (GLuint *) buffer;

for (i = 0; i < hits; i++)
{ /* for each hit */
names = *ptr;

Output(" number of names for hit = %d\n", names); ptr++;
Output(" z1 is %u;", *ptr); ptr++;
Output(" z2 is %u\n", *ptr); ptr++;

for (j = 0; j < names; j++)
{ /* for each name */

Output(" the name is %d ", *ptr); ptr++;
Output(" ");
Output(" ");


Share this post

Link to post
Share on other sites
More checking

Structure of the hit record (Red Book, p536)
for each hit
- number of names N
- zmin
- zmax
- N names

The number of hits is the value returned by glRenderMode()

Edit: ok, you got it ;p

Edited by - Fruny on February 18, 2002 4:43:05 AM

Share this post

Link to post
Share on other sites
I don't know, you code seems ok...

more stupid questions
- are you indeed going through the for loops ?
- is your projection matrix really the same as in render mode ? (i.e. are you clicking on an object)
- do you have bad karma ?

correction : your projection matrix looks fine...

Edited by - Fruny on February 18, 2002 4:53:35 AM

Share this post

Link to post
Share on other sites
a) Yeah going through the loops as I can see them rendered and am pretty sure they are being rendered in SELECT mode too.

b)I believe so, because when I click on nothing, black background.. no hits are returned only when I click on a ground tile.

c) God yes! You have no idea what kind of problems I''ve been having. All of a sudden my news server has randomly started dropping posts, been getting 404 errors all over the place, and Gravity freezes on splash screen.

Share this post

Link to post
Share on other sites
Here is an overview of my process

glClearColor (0.0, 0.0, 0.0, 0.0);

if (mode == SELECT) {


// Set Camera Angle.

cameraPos[2], // camera location

cameraLookAt[2], // looking at

0.0f); // up vector

// Update Keyboard input

// -----------------------

sinput.DInputUpdate(); //Update DirectInput to make sure it''s still alive

if(KEY_DOWN(DIK_ESCAPE)) //Check to see if the user wants to quit

// -----------------------

// Handle keyboard input





if (mode == SELECT)
s3d.BufferSwap(); //Finally, swap the buffers

Share this post

Link to post
Share on other sites
Just another test : try clicking at the edge of several tiles so that your 5x5 picking window gets several hits... and post the results back.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!