Click here to Skip to main content
11,803,019 members (78,324 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VC6 C++ OpenGL
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 );
    glPushName( 5 );
	glMatrixMode( GL_PROJECTION );
	gluPickMatrix( CursorDownPos.x, 500 - CursorDownPos.y, PICK_AREA, PICK_AREA, nViewport );
	glMatrixMode( GL_MODELVIEW );
	DrawRect();// this function will draw the rectangle
	glMatrixMode( GL_PROJECTION );
	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

1 solution

Rate this: bad
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.[^]
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
0 KrunalRohit 356
1 OriginalGriff 335
2 CPallini 270
3 F-ES Sitecore 270
4 Sergey Alexandrovich Kryukov 234
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,735
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 7 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100