开发者

Make a List<Point3D> , add points and draw using glDrawArrays

This is a follow up question from 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜