Android Nexus4上奇怪的opengl es图片

Android Nexus4上奇怪的opengl es图片,android,opengl-es,nexus-s,nexus-4,Android,Opengl Es,Nexus S,Nexus 4,我正在为android实现opengl es活动。我在Nexus4上看到了一张奇怪的照片。在nexus-s上,一切都如我所料。以下是我的渲染器代码: public void onSurfaceChanged(GL10 gl, int width, int height) { Log.d(TAG, "onSurfaceChanged"); if (height == 0) { height = 1; } this.width = width;

我正在为android实现opengl es活动。我在Nexus4上看到了一张奇怪的照片。在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;
}
表面上的公共空隙已更改(GL10 gl,整型宽度,整型高度){
Log.d(标签“onSurfaceChanged”);
如果(高度==0){
高度=1;
}
这个。宽度=宽度;
高度=高度;
cellsh=高度/单元大小;
cellsw=宽度/单元大小;
gl.glViewport(0,0,宽度,高度);//重置当前视口
gl.glMatrixMode(GL10.gl_投影);//选择投影矩阵
gl.glLoadIdentity();//重置投影矩阵
gl.glDisable(GL10.gl_DEPTH_TEST);//禁用Z坐标
gl.glOrthof(0f,宽度,高度,0,0,1);
gl.glMatrixMode(GL10.gl_MODELVIEW);//选择MODELVIEW矩阵
gl.glLoadIdentity();
}
@凌驾
已创建曲面上的公共空白(GL10 gl,
javax.microedition.khronos.egl.EGLConfig配置){
Log.d(标记“onSurfaceCreated”);
gl.glShadeModel(GL10.glu平滑);
gl.glClearColor(0.0f、0.0f、0.0f、0.5f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.gl_深度_试验);
gl.glDepthFunc(GL10.gl_LEQUAL);
gl.glHint(GL10.gl\u透视图\u校正\u提示,GL10.gl\u最佳);
}
公共框架(GL10 gl){
gl.glLoadIdentity();
gl.glClearColor(0.0f、0.0f、0.0f、0.5f);
gl.glTranslatef(cellSize/2,cellSize/2,0f);
对于(int i=0;i
这是NexusS和Nexus4的截图。
我想问题出在你的坐标系上。宽度、高度、cellsh、cellsw、cellSize是否浮动?你是怎么计算的?
什么是目标api?

丑陋的Nexus 4图片通过添加

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

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

您设备的视频RAM似乎处于一种奇怪的状态。重新启动设备后,您能否重现结果?您是否检查了总账功能的所有返回代码是否正常?模式是否重复。看起来记忆有问题。但其他opengl es应用程序看起来不错。我认为某些内部opengl实现中存在问题,因为例如,若我拖动最上面的抽屉,我会在渲染和其他系统ui元素的背景上看到时钟…:)如果我将gl.glClear(GL10.gl_COLOR_BUFFER| GL10.gl_DEPTH_BUFFER| BIT)放在nexus Sproblem上,则不会有任何bug消失;到OnDrawFrame(),但如果我不想每帧重画整个屏幕,我能做什么?如果我只想重画修改过的方块怎么办?如果我真的感兴趣的话,再问一个问题。总的来说,我会说你总是希望每一帧都清晰地开始。我不知道任何真实世界的反例。目标API是7。这个。宽度=宽度;高度=高度;cellsh=高度/单元大小;cellsw=宽度/单元大小;