Jump to content

  • Log In with Google      Sign In   
  • Create Account


Sleicreider

Member Since 08 Oct 2012
Offline Last Active Jun 25 2014 08:18 AM
-----

Topics I've Started

OpenGL VBO

11 October 2012 - 05:36 AM

Hey,

I already can create Polygons/OpenGL objects in Java(Android) with OpenGL. There I used the FloatBuffer,ShortBuffer and ByteBuffer to draw my OpenGL Objects, but in c++ there are no floatbuffers etc. and I dont know what i can use else to get the same object with these buffers.

in Java i used,for example, this code:


private float vertices[] = {
-1.0f, 1.0f, 0.0f, // 0, Top Left
-1.0f, -1.0f, 0.0f, // 1, Bottom Left
1.0f, -1.0f, 0.0f, // 2, Bottom Right
1.0f, 1.0f, 0.0f, // 3, Top Right
};

private short[] indices = { 0, 1, 2, 0, 2, 3 };
private FloatBuffer vertexBuffer;
private ShortBuffer indexBuffer;

public Square() {
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
ibb.order(ByteOrder.nativeOrder());
indexBuffer = ibb.asShortBuffer();
indexBuffer.put(indices);
indexBuffer.position(0);
}

public void draw(GL10 gl) {
// Counter-clockwise winding.
gl.glFrontFace(GL10.GL_CCW);
// Enable face culling.
gl.glEnable(GL10.GL_CULL_FACE);
gl.glCullFace(GL10.GL_BACK);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisable(GL10.GL_CULL_FACE);
}

But I have really no idea, how to change this, that i can use it in c++.

Maybe someone can help me?

thanks for helping :)

PARTNERS