在背景图像上绘制线条,OpenGL Android

时间:2014-08-20 16:17:26

标签: android opengl-es

我上课的是白线:

public class Line {

    //private FloatBuffer vertexBuffer;
    private FloatBuffer frameVertices;

    ByteBuffer diagIndices;


    float[] vertices = {
            -0.5f, -0.5f, 0.0f,
            -0.5f, 0.5f,  0.0f
    };

    public Line(GL10 gl) {
        // a float has 4 bytes so we allocate for each coordinate 4 bytes
        ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
        vertexByteBuffer.order(ByteOrder.nativeOrder());

        // allocates the memory from the byte buffer
        frameVertices = vertexByteBuffer.asFloatBuffer();

        // fill the vertexBuffer with the vertices
        frameVertices.put(vertices);

        // set the cursor position to the beginning of the buffer
        frameVertices.position(0);

    }


    /** The draw method for the triangle with the GL context */
    public void draw(GL10 gl) {

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glVertexPointer(2, GL10.GL_FLOAT, 0, frameVertices);
        gl.glColor4f(1.0f, 1.0f, 1.0f, 1f);

        gl.glDrawArrays(GL10.GL_LINE_LOOP , 0, vertices.length / 3);
        gl.glLineWidth(5.0f);

        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    }
}

工作正常。问题是:当我添加BG图像时,我看不到该行

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        glView = new GLSurfaceView(this);           // Allocate a GLSurfaceView
        //glView.setEGLContextClientVersion(1);
        glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
        glView.setRenderer(new mainRenderer(this)); // Use a custom renderer

        glView.setBackgroundResource(R.drawable.bg_day); // <- BG overlaps my line
        glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);  

        this.setContentView(glView);   // This activity sets to GLSurfaceView
     }

如何摆脱它?

我确信它应该是简单的。

谢谢,

1 个答案:

答案 0 :(得分:1)

您需要将GLSurfaceView放在活动窗口的顶部。 见setZOrderOnTop。应该像

一样简单
    glView = new GLSurfaceView(this);           // Allocate a GLSurfaceView
    glView.setZOrderOnTop(true);
  

控制表面视图的表面是否位于其顶部   窗口。通常它被放置在窗口后面,以允许它(为   大多数情况下)似乎与层次结构中的视图合成。通过   设置它,你可以将它放在窗口上方。这意味着   这个SurfaceView所在窗口的内容都不是   在其表面上可见。

相关问题包括: Android GLSurfaceView with drawable background