Unofficial OpenGL Software Development Kit  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Modules | Classes | Typedefs
Static Mesh

API for static mesh objects.

The glmesh::Mesh class is used to build a static mesh object which can be bound and rendered with OpenGL. There are a number of functions to generate meshes, but you can build your own mesh object from your own data if you so desire.

Some of the classes listed under the immediate mode API can be very useful for creating static meshes. VertexFormat is very handy for creating VAOs. Also, CpuDataWriter can be used to create vertex data for a mesh. You can upload it to a buffer object, and then store it in a glmesh::Mesh object.

Here is an example of how to manually build meshes:

#include <memory>
#include <glload/gl_all.h>
#include <glload/gll.hpp>
#include <glmesh/glmesh.h>
void RenderScene(glmesh::Mesh *);
glmesh::Mesh *BuildMesh()
//Loading succeeded. Create the vertex format.
//First attribute is attribute index 0, a vec4 of floats.
//Second attribute is attribute index 1, a vec4 of normalized, unsigned bytes.
glmesh::VertexFormat vfmt(attribs);
//attribs is no longer necessary; all of the info is stored in vfmt.
//Now, use a CpuDataWriter to create our buffer object.
glmesh::CpuDataWriter writer(vfmt, 4); //4 is just a hint; it's non-binding.
writer.Attrib(30.0f, 0.0f, 30.0f, 1.0f);
writer.Attrib<GLubyte>(255, 0, 255, 255);
writer.Attrib(30.0f, 0.0f, -30.0f, 1.0f);
writer.Attrib<GLubyte>(255, 128, 255, 255);
writer.Attrib(-30.0f, 0.0f, 30.0f, 1.0f);
writer.Attrib<GLubyte>(128, 0, 0, 255);
writer.Attrib(-30.0f, 0.0f, -30.0f, 1.0f);
writer.Attrib<GLubyte>(192, 128, 255, 255);
GLuint bufferObject = writer.TransferToBuffer(GL_ARRAY_BUFFER, GL_STATIC_DRAW);
//We're done with writer now.
//Create a set of mesh variant VAOs. We will have two:
//one for position+color, and one for just position.
GLuint vaos[2];
glGenVertexArrays(2, vaos);
//Must bind the buffer, so that the VAOs can store the buffer.
glBindBuffer(GL_ARRAY_BUFFER, bufferObject);
//Has both attributes.
//Has only attribute index 0.
vfmt.BindAttribute(0, 0); //Just one attribute.
//Done with the buffer
glBindBuffer(GL_ARRAY_BUFFER, 0);
variants["all"] = vaos[0];
variants["pos-only"] = vaos[1];
//Create the rendering command, as a 4-element triangle strip.
cmdList.DrawArrays(gl::TRIANGLE_STRIP, 0, 4);
//Build the mesh and return it.
std::vector<GLuint> buffers(1, bufferObject);
return new glmesh::Mesh(buffers, vaos[0], cmdList, variants);
int main(int argc, char *argv[])
//Initialize OpenGL and bind the context
//glload must be initialized for glmesh to work.
if(glload::LoadFunctions() == glload::LS_LOAD_FAILED)
//exit in some way
std::auto_ptr<glmesh::Mesh *> pMesh = BuildMesh();
//check for exit; otherwise, draw frame.
pMesh.release(); //Delete the mesh.
void RenderScene(glmesh::Mesh *pMesh)
//Clear the screen and set up shaders, textures, etc.
pMesh->Render("all"); //Uses both attributes
pMesh->Render("pos-only"); //Uses just the position
pMesh->Render(); //Same as "all", because that's what we used for the main VAO.


 Mesh Generators


class  glmesh::RenderCmdList
 A list of rendering commands to be used by a Mesh. More...
class  glmesh::Mesh
 An object that represents a static collection of mesh data. More...


typedef std::map< std::string,
GLuint > 
 A list of variations of named variations of a mesh. Each name maps to a VAO to render from.