Jump to content

  • Log In with Google      Sign In   
  • Create Account


OpenGL VBO


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Sleicreider   Members   -  Reputation: 107

Like
0Likes
Like

Posted 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 :)

Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8010

Like
0Likes
Like

Posted 11 October 2012 - 05:41 AM

It's the same, but without the intermediate vertexBuffer and indexBuffer objects. Just pass the arrays vertices and indices to the corresponding functions instead.

#3 japro   Members   -  Reputation: 887

Like
1Likes
Like

Posted 11 October 2012 - 05:44 AM

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

#4 clb   Members   -  Reputation: 1780

Like
0Likes
Like

Posted 11 October 2012 - 05:45 AM

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.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

#5 Sleicreider   Members   -  Reputation: 107

Like
0Likes
Like

Posted 11 October 2012 - 05:45 AM

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.

#6 Sleicreider   Members   -  Reputation: 107

Like
0Likes
Like

Posted 11 October 2012 - 05:47 AM

oh some of you already posted while ive written my last text ;)
ignore my last test^^

#7 Sleicreider   Members   -  Reputation: 107

Like
0Likes
Like

Posted 11 October 2012 - 05:51 AM

î 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

#8 japro   Members   -  Reputation: 887

Like
1Likes
Like

Posted 11 October 2012 - 05:54 AM

Google for "glew" and/or "gl3w".




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS