我正在为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的截图。
答案 0 :(得分:0)
我觉得麻烦在你的坐标系中。宽度,高度,细胞,细胞,细胞大小是否浮动?你怎么计算它们? api的目标是什么?
答案 1 :(得分:0)
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
到onDrawFrame的开头。但现在我不知道如何只绘制变化的区域,而不是全屏。