这大约是我第二次在 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 个三角形组成)。