我正在尝试使用鼠标选择不同的对象,我正在使用glReadPixels函数,但它不起作用,它总是显示为我的鼠标没有采摘任何东西。这是选择的代码:
void selectThing() {
GLint viewport[4];
GLubyte pixel[3] = {0};
glGetIntegerv(GL_VIEWPORT, viewport);
glReadPixels(mouseX, viewport[3] - mouseY, 60, 60, GL_RGBA, GL_UNSIGNED_BYTE, (void *)pixel);
printf("%d %d %d\n", pixel[0], pixel[1], pixel[2]);
if (pixel[0] == 0)
printf("Selected");
if (pixel[1] == 0)
printf("Selected");
if (pixel[2] == 0)
printf("Selected");
if (pixel[3] == 0)
printf("Selected");
else
printf("Not selected");
}
这是我的MouseFunction:
void clickThing (int button, int state, int x, int y) {
int count= 0;
if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {
printf("Count: %d\n", count);
count++;
mouseX = x;
mouseY = y;
mode = CLIC;
}
else
printf("Not selected \n");
}
有没有更好的方法来挑选在窗户周围飞来飞去的物体?