【发布时间】:2013-01-27 17:02:47
【问题描述】:
首先是第一次来,大家好。 在包括这个网站在内的网上搜索了几天后,我未能解决这个问题:
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity(); //load identity
GLU.gluLookAt(gl, 0, -5, -25, 0, 0, 0, 0, 2, 0); //set camera
if (fingerInput.isClicking()){
/* Color Picking 4 START */
gl.glDisable(GL10.GL_TEXTURE_2D); //turn off texturing, lighting and fog
gl.glDisable(GL10.GL_FOG);
gl.glDisable(GL10.GL_LIGHTING);
while (i<squares.size()){ //draw picking colors
squares.get(i).pickingDraw(gl); //note: picking is the same as draw() only with id colors and not textures
i++;
}
i=0;
gl.glReadPixels(fingerInput.getStart().x, screen_height-fingerInput.getStart().y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixels); //read what was the color id pressed, store it in 'pixels' (a 4 slots array buffer)
Log.d("tlog","at coords: ("+(screen_height-fingerInput.getStart().x)+", "+(screen_height-fingerInput.getStart().y)+")");
for (j=0; j<4; j++){
RGBA[j] = (int)(pixels.get(j) & 0xff);
if (RGBA[j] < 0) RGBA[j]+=256; //correcting error caused by java using unsigned bytes and opengl singed bytes
}
无论如何,出于挑选的目的,每个正方形都用唯一的颜色绘制,(目前绘制 3 个正方形,颜色为 99,96 和 93 红色,0s 为蓝绿色 alpha) glReadPixels 在单击 (99,0,0) 或 (91,0,0) 时返回。
如果框是彩色的 (x,0,0,255),它会返回一个值,就好像它有一个可能值列表,它们之间有 8 个空格。 (91,99,107..) 将每个读取的颜色值“四舍五入”到最接近的“可能”值。
【问题讨论】: