Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i'm using OpenGL in vc++
i've drawn a rectnagle, now i want to pick that rectangle and want to change the color of rectangle when i click on that.
for that i've used picking in openGL, but in that the glRenderMode( GL_RENDER ) function always returns 1, even if i click outside the rectangle also.
my code is,
vc++
glSelectBuffer( 50, nSelBuf );
    glGetIntegerv( GL_VIEWPORT, nViewport );
    glRenderMode( GL_SELECT );
glInitNames();
    glPushName( 5 );
	glMatrixMode( GL_PROJECTION );
	glPushMatrix();
	glLoadIdentity();

	gluPickMatrix( CursorDownPos.x, 500 - CursorDownPos.y, PICK_AREA, PICK_AREA, nViewport );
	glMatrixMode( GL_MODELVIEW );
	DrawRect();// this function will draw the rectangle
	glMatrixMode( GL_PROJECTION );
	glPopMatrix();
	int nHits = glRenderMode( GL_RENDER ); // here the nHits value will always be 1.
	glMatrixMode( GL_MODELVIEW );
Posted
Updated 3-Jul-12 18:27pm
v5

1 solution

glRenderMode() returns 1 means you clicked on any drawn object.

You should check the values in selection buffer, nSelBuf .
Details of selected objects will be available in selection buffer.

Value of PICK_AREA is 1, right ?.

Please share the entire code. or implementation of DrawRect().

The following link will be helpful to understand picking in opengl.
http://content.gpwiki.org/index.php/OpenGL:Tutorials:Picking[^]
 
Share this answer
 
Comments
Jijesh Balakrishnan 9-Jul-12 2:40am    
when i changed the order of functions, then i could execute that well
thank you for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900