How to use a VBO

Oh! Thanks very much! No extra handles? Just add 3 verticies for every triangle? :o

EDIT: My triangle just flipped after I added the extra verticies and points to the vertex Data.

For the second triangle, it is as simple as creating the vertices again, like this.


vertices.put(new float[]
{
    // First Triangle
    20, 20,
    10, 40,
    30, 40,

    // Second Triangle
    40, 40,
    30, 60,
    50, 60
});

These vertices create two side by side triangles. For more triangles, you can keep adding to the buffer. However, only when using [icode]GL_TRIANGLES[/icode] mode. In that mode, OpenGL renders first three vertices as one triangle and the next three as another triangle.

However, if you are using [icode]GL_TRIANGLE_STRIP[/icode] mode, then it creates a connected shape (not necessarily a triangle). And since we find ourselves using [icode]GL_TRIANGLE_STRIP[/icode] or other primitives rarely except [icode]GL_TRIANGLES[/icode], it will create two separate triangles.

Hope this helps.

It helps. In the

verticies.put

, instead of putting each triangle, could I have just call

put

every time I want to draw another triangle?

Yes that works too.

Adding more points only flipped the triangle. Now I can’t even get the first one to appear.

Are there any good tutorials that explain VBOs and VAs? I just can’t figure any of this out.

Oh god, I finally figure it out. Sorry for the horrendous amount of posts, but all I ask now is how do I convert float points to regular integers.(instead of -o.5f, I want to use somthing like 5)

You need to change glOrtho to use pixel coordinates.

glOrtho(0, width, 0, height, -1f, 1f);

Where width and height are the dimensions of your window.

I did that and I tried the coordinates:

vertexData.put(new float[]{0, 0, 0, /**/ 10, 0, 0, /**/ 10, 10, 0});

Everything disapeared.

A lot of things could have gone wrong…

Try printing out glGetError();

It returned 0. Maybe it’s my second shape. And the Ortho you showed me is between -1f and 1f, so wouldn’t that have to be a float with a decimal still?

EDIT:

It only works when I use

glOrtho(1, -1, 1, -1, 1, -1)

maybe you might have not understood my question, but it turns out I didn’t even need to ask.

Yeah, I got those two parameters mixed up I guess. The first one is the near plane, and the far one is the far plane. I forgot that z+ is coming towards you :stuck_out_tongue:

So your glOrtho call would be like:

glOrtho(0, width, 0, height, 1, -1);

Silly goose, thanks.