0

I'm implementing opengl-es activity for android. And I've met strange picture on nexus 4. While on nexus-s everything looks as I expect. Here is my Renderer code:

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;
}

And here is screenshots from Nexus S and Nexus 4.Nexus4 Nexus S

swex
  • 75
  • 1
  • 6
  • The video RAM of your device seems to be in a strange state. Can you reproduce your results after rebooting the device? Have you checked all return codes from GL functions are ok? – Jonas Bötel Nov 10 '13 at 10:00
  • exactly patterns are repeating. Looks like something wrong with memory. But other opengl-es applications looks fine. I think problem in some internal opengl realization because for example if I drag top drawer I see clocks on background of my render and other system ui elements... :) And no bug on nexus S – swex Nov 10 '13 at 17:32
  • problem goes away if I put gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); to OnDrawFrame() but what I can do if I don't want to redraw entire screen every frame? What If I want to redraw only changed squares? – swex Nov 10 '13 at 21:32
  • create another question for that if genuinely interested. In general I'd say you *always* want to start clear every frame. I don't know of any real-world counterexample. – Jonas Bötel Nov 11 '13 at 01:05

2 Answers2

0

I think trouble is in your coordinate system. Are width, height, cellsh, cellsw, cellSize float? How you calculate them? What target api is?

MrKalach
  • 9
  • 4
  • Target API is 7. this.width = width; this.height = height; cellsh = height / cellSize; cellsw = width / cellSize; – swex Nov 10 '13 at 17:27
0

ugly Nexus 4 picture fixed by adding

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

to beginning of onDrawFrame. But now I don't know how to draw only changed regions, not whole screen.

swex
  • 75
  • 1
  • 6