我正在为 android 实现 opengl-es 活动。而且我在nexus 4 上遇到了奇怪的画面。在nexus-s 上,一切看起来都如我所料。这是我的渲染器代码:
public void onSurfaceChanged(GL10 gl, int width, int height) {
Log.d(TAG, "onSurfaceChanged");
if (height == 0) {
height = 1;
}
this.width = width;
this.height = height;
cellsh = height / cellSize;
cellsw = width / cellSize;
gl.glViewport(0, 0, width, height); // Reset The Current Viewport
gl.glMatrixMode(GL10.GL_PROJECTION); // Select The Projection Matrix
gl.glLoadIdentity(); // Reset The Projection Matrix
gl.glDisable(GL10.GL_DEPTH_TEST);// disable Z coordinate
gl.glOrthof(0f, width, height, 0, 0, 1);
gl.glMatrixMode(GL10.GL_MODELVIEW); // Select The Modelview Matrix
gl.glLoadIdentity();
}
@Override
public void onSurfaceCreated(GL10 gl,
javax.microedition.khronos.egl.EGLConfig config) {
Log.d(TAG, "onSurfaceCreated");
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}
public void onDrawFrame(GL10 gl) {
gl.glLoadIdentity();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glTranslatef(cellSize / 2, cellSize / 2, 0f);
for (int i = 0; i < cellsw; i++) {
for (int j = 0; j < cellsh; j++) {
if (Cells.firstGen()) {
if (Cells.getCell(j, i)) {
Coloriry(gl, 2);
} else {
Coloriry(gl, 1);
}
gl.glScalef(squareSize / 2f, squareSize / 2f, 1f);
quad.draw(gl); // Draw triangle ( NEW )
gl.glScalef(1 / (squareSize / 2f), 1 / (squareSize / 2f), 1);
gl.glTranslatef(0.0f, cellSize, 0.0f);
continue;
}
if (Cells.getOldCell(j, i) != Cells.getCell(j, i)) {
if (Cells.getCell(j, i)) {
Coloriry(gl, 2);
} else {
Coloriry(gl, 1);
}
gl.glScalef(squareSize / 2f, squareSize / 2f, 1f);
quad.draw(gl);
gl.glScalef(1 / (squareSize / 2f), 1 / (squareSize / 2f), 1);
}
gl.glTranslatef(0.0f, cellSize, 0.0f);
}
gl.glTranslatef(cellSize, -cellsh * cellSize, 0.0f);
}
Cells.nextGen();
frames += 1;
}
这是 Nexus S 和 Nexus 4 的屏幕截图。