“消费者关闭了输入渠道或发生了错误。” - 尝试在android上使用openGL绘制一个矩形

时间:2012-11-05 06:57:49

标签: java android opengl-es

这大约是我第二次在Android上使用openGL,我似乎无法解读这两个奇怪的错误消息:

E/InputDispatcher(60): channel '407a76f8 root.AirGates/root.AirGates.AirGatesActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
E/InputDispatcher(60): channel '407a76f8 root.AirGates/root.AirGates.AirGatesActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

我试图将下面的所有openGL代码分开:

设置视口:

GL10 graphics = glGraphics.getGlGraphics();

graphics.glClearColor(0.0f, 0.0f, 0.0f, 1);
graphics.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());

graphics.glMatrixMode(GL10.GL_PROJECTION);
graphics.glLoadIdentity();

graphics.glOrthof(0, glGraphics.getWidth(), 0, glGraphics.getHeight(), 1, -1);

在渲染之前(设置顶点索引和值):

// allocate a 'raw' byte buffer, then 'cast it' into a ShortBuffer a short has 2 bytes of memory and there are 6 values
// (6 values because 2 tris with 3 vertices each, make up a quad)
// 0---1
// | / |
// 3---2
ByteBuffer tempBuffer = ByteBuffer.allocate(6 * 2);
tempBuffer.order(ByteOrder.nativeOrder());
vertexNumIndexes = tempBuffer.asShortBuffer();
vertexNumIndexes.put(new short[]{0,1,3, 1,2,3});
vertexNumIndexes.flip();

// need to allocate memory to hold the vertices: float is 4 bytes, times 4 vertices, times 2 (each vertex has an x and y)
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * 2 * 4);
byteBuffer.order(ByteOrder.nativeOrder());
vertices = byteBuffer.asFloatBuffer();
Point temp;
for(int counter = 0; counter < 4; counter++){
    temp = gate.getPoint(counter);
    vertices.put(temp.x);
    vertices.put(temp.y);
}
vertices.flip();

// values in 'vertices' are:
// 140.18016, 387.5
// 339.81982, 387.5
// 339.81982, 412.5
// 140.18016, 412.5

在我的实际render()方法中调用:

GL10 graphics = glGraphics.getGlGraphics();

// set colour, RGBA
graphics.glColor4f(1, 1, 0, 1);

graphics.glEnableClientState(GL10.GL_VERTEX_ARRAY);
graphics.glVertexPointer(2, GL10.GL_FLOAT, 0, vertices);
graphics.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT, vertexNumIndexes);
graphics.glDisableClientState(GL10.GL_VERTEX_ARRAY);

我的应用程序弹出,全屏黑色(由视口设置),然后退出。知道这意味着什么吗?我正试图绘制一个简单的红色矩形(由2个三角形组成)。

0 个答案:

没有答案