【问题标题】:Draw line on background image, OpenGL Android在背景图像上画线,OpenGL Android
【发布时间】:2014-08-20 16:17:25
【问题描述】:

我有画白线的课:

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
     }

如何摆脱它?

我相信它应该很简单。

谢谢,

【问题讨论】:

  • 您确定要使用 OpenGL ES 1?为什么?
  • @StefanHanke 这有意义吗?我看不出区别
  • 有什么区别?你现在在学习 OpenGL (ES) 吗?
  • @StefanHanke 一点都没有,我没有经验,但尝试在 2 年休息后重建我的游戏。

标签: android opengl-es


【解决方案1】:

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

    glView = new GLSurfaceView(this);           // Allocate a GLSurfaceView
    glView.setZOrderOnTop(true);

控制表面视图的表面是否放置在其顶部 窗户。通常它被放置在窗户后面,以允许它(对于 大部分)似乎与层次结构中的视图复合。经过 设置这个,你会导致它被放置在窗口上方。这表示 这个 SurfaceView 所在的窗口的所有内容都不会是 在其表面上可见。

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

【讨论】:

    猜你喜欢
    • 2017-10-12
    • 1970-01-01
    • 2012-12-13
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2019-08-29
    • 1970-01-01
    相关资源
    最近更新 更多