Depth buffer problem on Samsung Galaxy S2

Problems with Canvas, OpenGL, etc...

Depth buffer problem on Samsung Galaxy S2

Postby max111 » Mon Jul 11, 2011 3:33 pm

Hi,

I have a problem with ZBuffer.
On emulator everythink is OK, but on Samsung Galaxy S2 zbuffer is lost between onDrawFrame calls.

Emulator displays first triangle with a hole (other triangle from zbuffer).
On Samsung S2 after a while is only first triangle without any hole (zbuffer is lost).
What is wrong?

Here is my test program:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.mk;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.nio.ByteOrder;
  5. import java.nio.FloatBuffer;
  6. import java.nio.ShortBuffer;
  7.  
  8. import javax.microedition.khronos.egl.EGLConfig;
  9. import javax.microedition.khronos.opengles.GL10;
  10.  
  11. import android.app.Activity;
  12. import android.opengl.GLSurfaceView;
  13. import android.opengl.GLSurfaceView.Renderer;
  14. import android.opengl.GLU;
  15. import android.os.Bundle;
  16. import android.util.Log;
  17. import android.view.Window;
  18. import android.view.WindowManager;
  19.  
  20. public class MainActivity extends Activity implements Renderer {
  21.  
  22.         private GLSurfaceView glView;
  23.  
  24.         @Override
  25.         public void onCreate(Bundle savedInstanceState) {
  26.                 super.onCreate(savedInstanceState);
  27.  
  28.                 this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  29.                 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  30.                                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
  31.  
  32.                 glView = new GLSurfaceView(this);
  33.                 glView.setRenderer(this);
  34.                 setContentView(glView);
  35.         }
  36.  
  37.         private final static int VERTS = 3;
  38.         private static FloatBuffer mVerticesTriangleFar;
  39.         private static FloatBuffer mVerticesTriangleNear;
  40.         private static ShortBuffer mIndicesBuffer;
  41.  
  42.         private static float[] triangle_far = {
  43.                 -0.5f, -0.5f, 0.5f,
  44.                 0.5f, -0.5f, 0.5f,
  45.                 -0.0f, 0.5f, 0.5f };
  46.  
  47.         private static float[] triangle_near = {
  48.                 -0.2f, -0.2f, 0.2f,
  49.                 0.2f, -0.2f, 0.2f,
  50.                 -0.0f, 0.2f, 0.2f };
  51.  
  52.         private static short[] indices = { 0, 1, 2 };
  53.  
  54.         static {
  55.                 ByteBuffer byteBuf = ByteBuffer.allocateDirect(VERTS * 3 * 4);
  56.                 byteBuf.order(ByteOrder.nativeOrder());
  57.                 mVerticesTriangleFar = byteBuf.asFloatBuffer();
  58.  
  59.                 byteBuf = ByteBuffer.allocateDirect(VERTS * 3 * 4);
  60.                 byteBuf.order(ByteOrder.nativeOrder());
  61.                 mVerticesTriangleNear = byteBuf.asFloatBuffer();
  62.  
  63.                 ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
  64.                 ibb.order(ByteOrder.nativeOrder());
  65.                 mIndicesBuffer = ibb.asShortBuffer();
  66.  
  67.                 for (int i = 0; i < VERTS; i++)
  68.                         for (int j = 0; j < 3; j++)
  69.                                 mVerticesTriangleFar.put(triangle_far[i * 3 + j]);
  70.  
  71.                 for (int i = 0; i < VERTS; i++)
  72.                         for (int j = 0; j < 3; j++)
  73.                                 mVerticesTriangleNear.put(triangle_near[i * 3 + j]);
  74.  
  75.                 for (int i = 0; i < VERTS; i++)
  76.                         mIndicesBuffer.put(indices[i]);
  77.  
  78.                 mVerticesTriangleFar.position(0);
  79.                 mVerticesTriangleNear.position(0);
  80.                 mIndicesBuffer.position(0);
  81.  
  82.         }
  83.  
  84.         private int ile = 1;
  85.  
  86.         @Override
  87.         public void onDrawFrame(GL10 gl) {
  88.                 gl.glMatrixMode(GL10.GL_MODELVIEW);
  89.                 gl.glLoadIdentity();
  90.                 GLU.gluLookAt(gl, 0, 0, -5, 0, 0, 0, 0, 1f, 0);
  91.  
  92.                 if (ile < 120) {
  93.                         //near triangle to zbuffer
  94.                         gl.glClear(GL10.GL_DEPTH_BUFFER_BIT);
  95.                         gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  96.                         gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVerticesTriangleNear);
  97.                         gl.glDrawElements(GL10.GL_TRIANGLES, VERTS, GL10.GL_UNSIGNED_SHORT,
  98.                                         mIndicesBuffer);
  99.                        
  100.                         ile ++;
  101.                 }
  102.                 Log.d("MK", "ile = " + ile);
  103.                
  104.  
  105.                 gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  106.  
  107.                 //far triangle
  108.  
  109.                 gl.glColor4f(1.0f, 1.0f, 0f, 0.5f);
  110.                 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  111.                 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVerticesTriangleFar);
  112.                 gl.glDrawElements(GL10.GL_TRIANGLES, VERTS, GL10.GL_UNSIGNED_SHORT,
  113.                                 mIndicesBuffer);
  114.         }
  115.  
  116.         @Override
  117.         public void onSurfaceChanged(GL10 gl, int width, int height) {
  118.                 gl.glViewport(0, 0, width, height);
  119.                 float ratio = (float) width / height;
  120.                 gl.glMatrixMode(GL10.GL_PROJECTION);
  121.                 gl.glLoadIdentity();
  122.                 gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);
  123.         }
  124.  
  125.         @Override
  126.         public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  127.                 gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
  128.                
  129.                 gl.glClearDepthf(1.0f);
  130.                 gl.glDepthFunc(GL10.GL_LEQUAL);
  131.                 gl.glEnable(GL10.GL_DEPTH_TEST);
  132.                 gl.glDepthMask(true);
  133.                 gl.glClear(GL10.GL_DEPTH_BUFFER_BIT);
  134.         }
  135.  
  136.         @Override
  137.         protected void onResume() {
  138.                 super.onResume();
  139.                 glView.onResume();
  140.         }
  141.  
  142.         @Override
  143.         protected void onPause() {
  144.                 super.onPause();
  145.                 glView.onPause();
  146.         }
  147.  
  148. }
  149.  
Parsed in 0.045 seconds, using GeSHi 1.0.8.4
max111
Freshman
Freshman
 
Posts: 2
Joined: Mon Jul 11, 2011 3:13 pm

Top

Re: Depth buffer problem on Samsung Galaxy S2

Postby Ghost » Mon Jul 11, 2011 6:25 pm

Sorry for posting without having an answer, but can I ask why don't you just use something like this:
Code: Select all
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

at the beginning of your onDrawFrame method?

And also it appears to me, that you clear ZBuffer only first 120 times. Though I'm not sure if it has anything to do with the problem.
Ghost
Developer
Developer
 
Posts: 26
Joined: Fri Feb 11, 2011 2:50 pm

Re: Depth buffer problem on Samsung Galaxy S2

Postby max111 » Mon Jul 11, 2011 9:34 pm

This is only a test program, "120" is random value to show a problem.
In my destination program (2.5d technique) I have a static 3d scene and I want to set my zbuffer only once (in the first onDrawFrame calling) - for example:

private boolean firstTime = true;
...
@Override
public void onDrawFrame(GL10 gl) {
...
if (firstTime) {
firstTime = false;
//fill z-buffer
}
...
}
max111
Freshman
Freshman
 
Posts: 2
Joined: Mon Jul 11, 2011 3:13 pm

Re: Depth buffer problem on Samsung Galaxy S2

Postby Ghost » Wed Jul 13, 2011 7:42 am

Have you found an answer yet?
If you want, you could upload your demo solution, so I could try to run it on my xperia. Maybe something will work out.
Ghost
Developer
Developer
 
Posts: 26
Joined: Fri Feb 11, 2011 2:50 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests