Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VC6 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 21:08pm
Edited 3-Jul-12 19: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)

Advertise | Privacy | Mobile
Web03 | 2.8.150327.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