Jonathan
Jonathan

Reputation: 1100

How do I use GLTriangleBatch

I am developing a real world application that is to render solid white polygons on the screen, and change their alpha values as time passes. I am trying to learn how to use GLTriangleBatch to perform this (I know C++ well, but not so much about OpenGL), and have not been able to find any good examples online. So far, I have found a few resources that led me to put together the following bit of code, but I am still confused on some portions:

GLTriangleBatch myTriangles;
myTriangles.BeginMesh(1000000); // Include how many vertices you have: 1???
myTriangles.AddTriangle(...);   // Add a triangle: 2???

// Repeat for all triangles for this batch
myTriangles.End();  // Done adding triangles
myTriangles.Draw(); // Draw the triangles

I have marked the portions I am confused on with ???, and the questions appear below:

Upvotes: 0

Views: 153

Answers (1)

glampert
glampert

Reputation: 4421

This GLTriangleBatch class apparently is part of a framework provided with the OpenGL Super Bible book. It is not part of the OpenGL standard (OpenGL is a plain C API).

As for the first question, I assume the nMaxVerts parameter of BeginMesh() is the upper limit of vertexes you want to draw (each triangle = 3 verts). So you can set this to either an exact value or an over-estimate. But you'd have to find some documentation or look at the source to know for sure.

For the second question, yes verts[3] are the three positions that make the triangle. vNorms is the Face Normal of the triangle. It is used for lighting calculation. And the last member, vTexCoords[3] are the Texture Coordinates of the triangle. These are used for texture mapping. You can set them to zero if you are not applying texture to your mesh.

Upvotes: 3

Related Questions