私が読んだopenglピッキングシステムを実装しようとしていますが、glReadPixelsで問題が発生しました。基本的に、シーン内のすべてのノードは一意の色を取得し、新しいタッチが発生すると、一意の色 ID でペイントされたノードだけでシーンをレンダリングします。保存されたカラーIDのリストで入力座標をチェックしようとしています。
glReadPixels を正しく動作させることができません。ピクセル値に対して常に 0 0 0 を返します。そこから正しいピクセル値を取得するための助けをいただければ幸いです。ありがとう
ここに関連するコードがあります
private void handleEvent(MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
int action = event.getAction();
int actionCode = action & MotionEvent.ACTION_MASK;
if (actionCode == 0) {
// Paint with colorID color
mSettings.picking(true);
dumpEvent(event);
final GL10 gl = mSettings.getGL();
ByteBuffer PixelBuffer = ByteBuffer.allocateDirect(4);
PixelBuffer.order(ByteOrder.nativeOrder());
gl. glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1);
gl.glReadPixels(x, y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, PixelBuffer);
byte b[] = new byte[4];
PixelBuffer.get(b);
String key = "" + b[0] + b[1] + b[2];
// Check for selection
mRenderer.processSelection(event, new SGColorI(pixel[0], pixel[1], pixel[2], pixel[3]));
log.pl("GL on touchdown", key);
} else if (actionCode == 2) {
mSettings.picking(false);
}
}