Question

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:

  • Question 1: Does this number of vertices have to be exact, or is it okay to over-estimate and / or underestimate? Furthermore, does this number of vertices represent the "batched" vertices, or the individual vertices of each triangle (e.g. would 2 connected triangles with 2 shared vertices require 6 vertices or 4?)

  • Question 2: The paramaters are:

    • M3DVector3f verts[3]: I assume the 3 vertices of the triangle
    • M3DVector3f vNorms: What is this, and how do I set it up?
    • M3DVector2f vTexCoords[3]: I assume this is something to do with texture, all I want is a white triangle, and to be able to vary the alpha value of it. How would I set this up?
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top