简体   繁体   中英

How to update vertex buffer on android?

I have trouble updating vertices information on android. Basically, the FloatBuffer initially contains a shape of a cube, but I want to transform this shape on button pressed, so I have to update the vertices value each time UI button is pressed. I used the following function to change the FloatBuffer :

public float increment(float value)
    {
        float v = 0.0f;
        for(int i = 0; i < boxf.length; i++)
        {
            if(i % 3 == 2 && boxf[i] > 0.0f)
            {
                this_boxf[i] += value;
                box.put(i, this_boxf[i]);
                v = box.get(i);
            }
        }
        return v;
    }

and this is the draw function:

public void draw(GL10 gl) {
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, box);
        gl.glNormalPointer(GL10.GL_FLOAT,0, normals);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4);
            gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4);
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
    }

The cube appears correctly, but when I tried to change its FloatBuffer , nothing changes. I read around on google and it seems I have to use glBufferData . However, there's no such function for GL10 . How would I accomplish this?

If your render mode is set to RENDERMODE_WHEN_DIRTY then the draw() function will only be called when the view is invalidated or requestRender() is called, so you aren't going to see any change when you update your vertex buffer.

In order to see your changes, you can either set your render mode to RENDERMODE_CONTINUOUSLY or else call requestRender() on your GLSurfaceView object after you update your vertex buffer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM