tags:

views:

27

answers:

1

Hey guys,

This is a follow up question from http://stackoverflow.com/questions/3204189/add-contents-to-the-end-of-a-float-array-like-this . I'm looking to dynamically create 3D boxes. Here's my Questions

  • I want to add a box to the list e.g add....

    // FRONT
             -2.0f, -1.5f,  -6.0f,
              2.0f, -1.5f,  -6.0f,
             -2.0f,  1.5f,  -6.0f,
              2.0f,  1.5f,  -6.0f,
             // BACK
             -2.0f, -1.5f, -10.0f,
             -2.0f,  1.5f, -10.0f,
              2.0f, -1.5f, -10.0f,
              2.0f,  1.5f, -10.0f,
             // LEFT
             -2.0f, -1.5f,  -6.0f,
             -2.0f,  1.5f,  -6.0f,
             -2.0f, -1.5f, -10.0f,
             -2.0f,  1.5f, -10.0f,
             // RIGHT
              2.0f, -1.5f, -10.0f,
              2.0f,  1.5f, -10.0f,
              2.0f, -1.5f,  -6.0f,
              2.0f,  1.5f,  -6.0f,
             // TOP
             -2.0f,  1.5f,  -6.0f,
              2.0f,  1.5f, -6.0f,
             -2.0f,  1.5f, -6.0f,
              2.0f,  1.5f, -10.0f,
             // BOTTOM
             -2.0f, -1.5f,  -6.0f,
             -2.0f, -1.5f, -10.0f,
              2.0f, -1.5f,  -6.0f,
              2.0f, -1.5f, -10.0f,
    

The above values would make up 1 box, how would I do so?

  • I'd like to use glDrawArrays() to then draw the entire list (all of the boxes) how would I make it do so?

            FloatBuffer makeFloatBuffer(float[] arr) {
    ByteBuffer bb = ByteBuffer.allocateDirect(arr.length*4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(arr);
    fb.position(0);
    return fb;
    

    }

keep in mind, I'm sending everything through a floatbuffer. and then drawing like so..

            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);

I'm completely new to Point3D, OpenGL and graphics in general so any help would be greatly appreciated.

Thanks.

+2  A: 

Now that you've added the opengl tag I understand why you need float[] structures (or at least floats instead of doubles).

Here is demo application. To me it looks like a good piece of code for studying opengl basics, including the vertex arrays. From other question I see that you work on an android project. So I just hope that it's applicable to android too.

Andreas_D
Problem with that is I have to send it through a `Floatbuffer` and then draw it.. I've edited my question to show more code
Ulkmun
+1; I know nothing about OpenGL in Java, and I'm not sure how applicable my answer on the other question is for OP, but I hope others can guide him.
polygenelubricants