#include <cl.h>
Data Fields | |
CLcontext * | context |
CLcolour * | colour |
unsigned int | material_index |
unsigned int | texture_index |
GLenum | texture_env_mode |
unsigned int | num_vertices |
CLvertex * | vertices |
CLcolour * | colours |
CLnormal * | normals |
CLtexcoord * | texcoords |
CLedgeflag * | edgeflags |
unsigned int | num_primitivesets |
CLprimitiveset ** | primitivesets |
GLuint | display_list |
CLmesh
struct defines a mesh: a set of primitives that share the same vertices and surface properties such as colour, material, or texture. The material and texture properties are defined as indices into the material and texture arrays of a CLcontext
struct and a pointer to the context is stored so that the mesh can access them. Per-vertex data is stored in parallel vertex, colour, normal, texture coordinate, and edge flag arrays. These arrays are designed to be used as OpenGL vertex arrays. They can be passed to OpenGL by casting to GLfloat*
.
CLmesh* mesh;
...
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXCOORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, mesh->vertices); glNormalPointer(3, GL_FLOAT, 0, mesh->normals); glTexCoordPointer(3, GL_FLOAT, 0, mesh->texcoords);
Some members represent optional attributes. If texture_index
is -1 (maximum value for GLuint
) then no texture is used. Similarly for material_index
. If colour
is NULL, it is not used. Similarly for per-vertex arrays: colours
, normals
, texcoords
, and edgeflags
. The vertices
member is not optional and must be set if num_vertices is non-zero.
The members of this struct can be passed to a number of OpenGL functions. However, we strongly recommend using the clUpdateMesh()
and clRenderMesh()
functions rather than the code below.
CLmesh* mesh; CLprimitiveset* primitiveset; GLuint i;
...
if (!mesh->vertices) { glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, mesh->vertices); } else glDisableClientState(GL_VERTEX_ARRAY);
if (!mesh->colours) { glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_FLOAT, 0, mesh->colours); } else glDisableClientState(GL_COLOR_ARRAY);
if (!mesh->normals) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, mesh->normals); } else glDisableClientState(GL_NORMAL_ARRAY);
if (!mesh->texcoords) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, mesh->texcoords); } else glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (!mesh->edgeflags) { glEnableClientState(GL_EDGE_FLAG_ARRAY); glEdgeFlagPointer(0, mesh->edgeflags); } else glDisableClientState(GL_EDGE_FLAG_ARRAY);
if (mesh->colour) glColor4fv((GLfloat*)mesh->colour);
if (mesh->material_index != -1) clLoadMaterial(mesh->context->materials[mesh->material_index]);
if (mesh->texture_index != -1) { clLoadTexture(mesh->context->textures[mesh->texture_index]); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mesh->texture_env_mode); }
for (i = 0; i < mesh->num_primitivesets; i++) { primitiveset = mesh->primitivesets[i];
glDrawElements(primitiveset->mode, primitiveset->num_indices, GL_UNSIGNED_INT, primitiveset->indices); }
The display_list
member is an OpenGL display list ID. It is set by the clUpdateMesh()
function and called by the clRenderMesh()
function. This is the preferred method for rendering in CL. However, the display_list
member may also be set and called by the user.
For more information on CLmesh
members consult the documentation for CLcontext
, CLmaterial
, CLtexture
, CLprimitiveset
, and the OpenGL documentation for glEnableClientState()
, glVertexPointer()
, glColorPointer()
, glNormalPointer()
, glTexCoordPointer()
, glEdgeFlagPointer()
, glDrawElements()
, glGenLists()
, glNewList()
, glEndList()
, glCallList()
, and glDeleteLists()
.
Definition at line 707 of file cl.h.