1
我为我的应用程序实现了一个简单的颜色选择器,除了正在绘制的对象没有确切的颜色ID之外,它正常工作。因此,22,0,0,23,0,0,24,0,0的颜色ID可能被glReadPixles拾取为22,0,0。我也尝试禁用抖动,但不知道是否有另一个gl设置我必须禁用或启用获取对象绘制,因为有确切的颜色ID。Android颜色挑选不正确颜色
if(picked)
{
GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT | GLES10.GL_DEPTH_BUFFER_BIT);
GLES10.glDisable(GLES10.GL_TEXTURE_2D);
GLES10.glDisable(GLES10.GL_LIGHTING);
GLES10.glDisable(GLES10.GL_FOG);
GLES10.glPushMatrix();
Camera.Draw(gl);
for(Actor actor : ActorManager.actors)
{
actor.Picking();
}
ByteBuffer pixels = ByteBuffer.allocate(4);
GLES10.glReadPixels(x, (int)_height - y, 1, 1, GLES10.GL_RGBA, GLES10.GL_UNSIGNED_BYTE, pixels);
for(Actor actor : ActorManager.actors)
{
if(actor._colorID[0] == (pixels.get(0) & 0xff) && actor._colorID[1] == (pixels.get(1) & 0xff) && actor._colorID[2] == (pixels.get(2) & 0xff))
{
actor._location.y += -1;
}
}
GLES10.glPopMatrix();
picked = false;
}
public void Picking()
{
GLES10.glPushMatrix();
GLES10.glTranslatef(_location.x, _location.y, _location.z);
GLES10.glVertexPointer(3, GLES10.GL_FLOAT, 0, _vertexBuffer);
GLES10.glColor4f((_colorID[0] & 0xff)/255.0f,(_colorID[1] & 0xff)/255.0f, (_colorID[2] & 0xff)/255.0f, 1.0f);
GLES10.glDrawElements(GLES10.GL_TRIANGLES, _numIndicies,
GLES10.GL_UNSIGNED_SHORT, _indexBuffer);
GLES10.glPopMatrix();
}