glRenderMode函数始终返回1 [英] glRenderMode function always returns 1

查看:162
本文介绍了glRenderMode函数始终返回1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我在vc ++中使用OpenGL
我已经画了一个矩形,现在我想选择那个矩形,并想在单击时更改矩形的颜色.
为此,我在openGL中使用了拾取功能,但是即使我也单击矩形外部,glRenderMode(GL_RENDER)函数始终返回1.
我的代码是

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 );

推荐答案

glRenderMode()返回1表示您单击了任何绘制的对象.

您应该检查选择缓冲区nSelBuf中的值.
所选对象的详细信息将在选择缓冲区中提供.

PICK_AREA的值为1,对吗?.

请分享整个代码.或DrawRect()的实现.

以下链接将有助于理解opengl中的选择.
http://content.gpwiki.org/index.php/OpenGL:Tutorials:Picking [ ^ ]
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[^]


这篇关于glRenderMode函数始终返回1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆