2d opengl clipping - irregular shape

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

2d opengl clipping - irregular shape

Postby st1lgar » Tue Oct 19, 2010 11:53 pm

Hi,
I'm new to opengl and android and couldn't find an answer in the forums so here I am...

I need to be able to 'draw' only the intersection of two triangles. I tried to use stencil test but it doesn't work in the android emulator.

Then I tried to use depth test and it works but only for a fraction of a second, then the screen goes blank.

I have a config with depth size 8.

What am I doing wrong? :(

This is the code I wrote for drawing the 2D 'scene' to verify that clipping works
Code: Select all
      gl.glEnable(GL10.GL_DEPTH_TEST);
      
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT   | GL10.GL_STENCIL_BUFFER_BIT);
      
      gl.glColorMask(false, false, false, false);

      outlineColor.setAsActive(gl);
      
      triangleOne(gl);

      gl.glDepthFunc(GL10.GL_EQUAL);
      
      gl.glColorMask(true, true, true, true);
      
      fillColor.setAsActive(gl);
      
      triangleTwo(gl);
      
      gl.glDisable(GL10.GL_DEPTH_TEST);




Code: Select all
/*Base on the left side of the screen, top on the middle of the right side of the screen*/
   private void triangleOne(GL10 gl) {
      float[] coords = { 1f, height, width, height / 2, 1f, 1f };
      drawItem(gl, 2, coords);
   }

/*Base on the right side of the screen, top on the middle of the left side of the screen*/
   private void triangleTwo(GL10 gl) {
      float[] coords = { width, height, width, 1f, 1f, height / 2 };
      drawItem(gl, 2, coords);
   }

   private void drawItem(GL10 gl, int size, float[] coords){
      fillColor.setAsActive(gl);
      FloatBuffer vertexBuffer;
      ByteBuffer vbb = ByteBuffer.allocateDirect(coords.length * 4);
      vbb.order(ByteOrder.nativeOrder());
      vertexBuffer = vbb.asFloatBuffer();
      vertexBuffer.put(coords);
      vertexBuffer.position(0);

      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
      gl.glVertexPointer(size, GL10.GL_FLOAT, 0, vertexBuffer);
      gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vertexBuffer.capacity() / size);
      gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
   }



Please help
Thanks
st1lgar
Freshman
Freshman
 
Posts: 2
Joined: Tue Oct 19, 2010 11:07 pm

Top

Re: 2d opengl clipping - irregular shape

Postby st1lgar » Thu Oct 21, 2010 3:54 pm

Someone responded to me in another forum

gl.glDepthFunc(GL10.GL_ALWAYS);

has to be placed in the above code just above

triangleOne(gl);

Hope it helps someone else as well...

Thanks goes to Reuben Scratton
st1lgar
Freshman
Freshman
 
Posts: 2
Joined: Tue Oct 19, 2010 11:07 pm

Top

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

Who is online

Users browsing this forum: No registered users and 2 guests