As planned, the first triangle indicates the visible area, the second triangle is drawn more than this area, but only the area marked by the first triangle should be displayed, but the whole triangle is drawn from me. Similar c ++ code under windows works great.

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.ArrayList; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.opengl.GLES20; import android.opengl.GLSurfaceView; import android.opengl.GLU; public class HelloOpenGLES20Renderer implements GLSurfaceView.Renderer { FloatBuffer triangleBufferA; FloatBuffer triangleBufferB; float [] triangleA = { 0, 0, 0, // A 1, 0, 0, // B 0, 1, 0 // C }; float [] triangleB = { 0, 0, 0, // A 2, 0, 0, // B 0,2, 0 // C }; public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glEnable(GL10.GL_BLEND); gl.glDisable(GL10.GL_TEXTURE_2D); ByteBuffer bb = ByteBuffer.allocateDirect(36); bb.order(ByteOrder.nativeOrder()); triangleBufferA = bb.asFloatBuffer(); triangleBufferA.put(triangleA); triangleBufferA.position(0); ByteBuffer cc = ByteBuffer.allocateDirect(36); cc.order(ByteOrder.nativeOrder()); triangleBufferB = cc.asFloatBuffer(); triangleBufferB.put(triangleB); triangleBufferB.position(0); } public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -2.0f); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE); // задаём видимую область gl.glColor4f(1, 1, 1, 1.0f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, triangleBufferA); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3); gl.glBlendFunc(GL10.GL_DST_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); // рисуем фигуру gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, triangleBufferB); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3); gl.glFinish(); } public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); float ratio = (float) width / height; gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); } } 
  • How did you decide that simply drawing 1 triangle "sets the visible area"? OpenGL does n't work that way. - Kromster

0