GL_DYNAMIC_DRAW_ARB - how ...?

hi,

i’ve made some experiments with VBO.
and with your help i was successful with GL_STATIC_DRAW_ARB.
thanks!

now i’m playing with GL_DYNAMIC_DRAW_ARB.
first: understanding.

correct me when i’m wrong, please.

with VBO you can access fast video memory directly.
ideal for raw buffer power.

ok - now i want to write a deformation method for my vertices.
it should run as fast as possible. :stuck_out_tongue:
for simplification i begin with moving instead of deforming.

is it true when i’ve got a bunch of video mem that i can write directly into it ?
and if how can i do this ?
does anybody have some jogl code for me?
a link to a “how to write into into video buf dynamically” could be also nice.

here is a part of my test code

public void init(final GLAutoDrawable drawable)
{
    gl = drawable.getGL();
    glu = new GLU();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    int[] v = new int[]
    {
        25, 25,
        100, 325,
        175, 25,

        175, 325,
        250, 25,
        325, 325
    };

    float[] c = new float[]
    {
        1.0f, 0.2f, 0.2f,
        0.2f, 0.2f, 1.0f,
        0.8f, 1.0f, 0.2f,

        0.75f, 0.75f, 0.75f,
        0.35f, 0.35f, 0.35f,
        0.5f, 0.5f, 0.5f
    };

    vertices = DirectBufferGL.createBufInts(v); // own version of "BufferUtil" 
    colors = DirectBufferGL.createBufFloats(c);

    gl.glGenBuffersARB(2, ids, 0);


    gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, ids[0]);         // Bind The Buffer

    // i want dynamic vertex
    gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB,           // ???
            //6 * 2 * DirectBufferGL.SIZEOF_INT, vertices, GL.GL_STATIC_DRAW_ARB);
            6 * 2 * DirectBufferGL.SIZEOF_INT, vertices, GL.GL_DYNAMIC_DRAW_ARB);
            //6 * 2 * DirectBufferGL.SIZEOF_INT, vertices, GL.GL_STREAM_DRAW_ARB);

    gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, ids[1]);         // Bind The Buffer
    gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB,
            6 * 3 * DirectBufferGL.SIZEOF_FLOAT, colors, GL.GL_STATIC_DRAW_ARB);

}

/**
* 2 triangles should move in x-direction. 
* forward and backward
*/
public void display(final GLAutoDrawable drawable)
{

    if (addX > maxAdd)
        inc *= -1;

    else if (addX < minAdd)
        inc *= -1;

    addX += inc;

    //vertices-moving-loop
    /*
    for (int i=0; i<v.length; i+=2)
    {
        int val = vertices.get(i) + addX; // simple x-move
        vertices.put(i, val);
    }
    */

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);




    gl.glEnableClientState(GL.GL_VERTEX_ARRAY);



    gl.glEnableClientState(GL.GL_COLOR_ARRAY);

    gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, ids[0]);

    /*
    gl.glMapBufferARB(GL.GL_ARRAY_BUFFER_ARB, GL.GL_WRITE_ONLY_ARB);

            // vertices-moving-loop
            for (int i=0; i<v.length; i+=2) // simple x-move
            {
                int val = vertices.get(i) + addX;
                vertices.put(i, val);
            }

     gl.glUnmapBufferARB(GL.GL_ARRAY_BUFFER_ARB);
      */

    gl.glVertexPointer(2, GL.GL_INT, 0, 0);




    gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, ids[1]);
    gl.glColorPointer(3, GL.GL_FLOAT, 0, 0);


    gl.glDrawArrays(GL.GL_TRIANGLES, 0, 6); // draw everything (six vertices)

    gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL.GL_COLOR_ARRAY);

    gl.glFlush();

  
}

//-------------------------------------------------

so where should i start the vertices-moving-loop ?

thank you for help,
and best code2all !
iface

http://gui3d.org/
http://filebee.org/

The return value from glMapBufferARB is the mutable data. You can call e.g. asFloatBuffer() on the returned ByteBuffer and change the data it contains. The VertexBufferObject demo in the jogl-demos workspace contains an example of this.