0

我正在为 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 的屏幕截图。连结4 连结小号

4

2 回答 2

0

我认为麻烦在于您的坐标系。宽度、高度、cellsh、cellsw、cellSize 是浮动的吗?你如何计算它们?目标api是什么?

于 2013-11-10T10:58:22.733 回答
0

通过添加修复丑陋的 Nexus 4 图片

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

到 onDrawFrame 的开头。但现在我不知道如何只绘制变化的区域,而不是整个屏幕。

于 2013-11-10T21:39:09.483 回答