Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6OpenGL
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,
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 2-Jul-12 20:08pm
Edited 3-Jul-12 18:27pm
v5

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
Jijesh Balakrishnan at 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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 800
1 OriginalGriff 503
2 Abhinav S 253
3 thatraja 245
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,282
1 OriginalGriff 4,750
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 7 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid