OpenGL VBO

Started by
6 comments, last by japro 11 years, 6 months ago
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 :)
Advertisement
It's the same, but without the intermediate vertexBuffer and indexBuffer objects. Just pass the arrays vertices and indices to the corresponding functions instead.
You simply use the data array directly. Also you don't really use VBOs in that java code ;). You just use draw arrays to draw array data.
example (lines 169 and following): https://github.com/progschj/OpenGL-Examples/blob/master/01shader_vbo1.cpp
In C/C++ you'll just have raw byte buffers to work with. Use a cast to view that memory area as bytes/shorts/floats as needed, i.e.

float *floatBuffer = reinterpret_cast<float*>(byteBuffer);
floatBuffer[index] = 1.0f; // Fill some float


There's a lot of code snippets available that show how to pass in memory buffers to VBOs: google for something like opengl es vbo tutorial.
so instead of the buffer i just use a array vor my vertex,index data?

ive seen lot of tutorials where they use something with glBindBuffer etc.
but all the tutorials are too difficult to understand.
oh some of you already posted while ive written my last text ;)
ignore my last test^^
î have one more problem.
im programming with QT.
how do i get the glGenBuffer,glBindBuffer objects?
i searched in google, but couldn't find anything for this
Google for "glew" and/or "gl3w".

This topic is closed to new replies.

Advertisement