【发布时间】:2015-04-18 14:58:17
【问题描述】:
当我尝试将项目放到笔记本电脑上运行时,一切正常,但 3D 拾取却一团糟。当我单击 3D 对象时,它会选择不同的对象。
我在另一台笔记本电脑上试过,结果相同。然后,我尝试将台式计算机的显示器固定到笔记本电脑上,以查看天气是否存在分辨率问题。但它仍然给出了相同的结果。但它在我的台式电脑上完全可以正常工作。
我的台式机上有 Nvidia 760gtx gpu,笔记本电脑只有 Intel HD 4500 gpu。是因为gpu吗?我。我迷路了。我什么都试过了。 这是我选择 3D 对象的代码。
public void select(int xx, int yy )
{
// The selection buffer
IntBuffer selBuffer = ByteBuffer.allocateDirect(1280).order(ByteOrder.nativeOrder()).asIntBuffer();
int buffer[] = new int[256];
IntBuffer vpBuffer = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asIntBuffer();
// The size of the viewport. [0] Is <x>, [1] Is <y>, [2] Is <width>, [3] Is <height>
int[] viewport = new int[4];
// The number of "hits" (objects within the pick area).
int hits;
// Get the viewport info
GL11.glGetInteger(GL11.GL_VIEWPORT, vpBuffer);
vpBuffer.get(viewport);
// Set the buffer that OpenGL uses for selection to our buffer
GL11.glSelectBuffer(selBuffer);
// Change to selection mode
GL11.glRenderMode(GL11.GL_SELECT);
// Initialize the name stack (used for identifying which object was selected)
GL11.glInitNames();
GL11.glPushName(0);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity();
/* create 5x5 pixel picking region near cursor location */
GLU.gluPickMatrix( (float) xx, (float) yy, 0.001f, 0.001f,IntBuffer.wrap(viewport));
GLU.gluPerspective(fov, screenResolutionx/screenResolutiony, near, far);
render();
GL11.glPopMatrix();
// Exit selection mode and return to render mode, returns number selected
hits = GL11.glRenderMode(GL11.GL_RENDER);
System.out.println("hits: " + hits);
selBuffer.get(buffer);
// Objects Were Drawn Where The Mouse Was
if (hits > 0) {
// If There Were More Than 0 Hits
choose = buffer[3]; // Make Our Selection The First Object
int depth = buffer[1]; // Store How Far Away It Is
for (int i = 1; i < hits; i++) {
// Loop Through All The Detected Hits
// If This Object Is Closer To Us Than The One We Have Selected
if (buffer[i * 4 + 1] < depth) {
choose = buffer[i * 4 + 3]; // Select The Closer Object
depth = buffer[i * 4 + 1]; // Store How Far Away It Is
}
}
System.out.println("Chosen: " + choose);
}
}
【问题讨论】:
-
请问有人知道这个问题吗?