OpenGL::GLM - Interface to the GLM library for loading Alias Wavefront OBJ files
use OpenGL::GLM; $model = new OpenGL::GLM($filename); $model->Unitize; $model->Draw(GLM_SMOOTH);
This module is a perl interface to the GLM library, by Nate Robbins and Jeff Rogers, for loading Alias Wavefront 3d object files and displaying them through OpenGL.
Note that no OpenGL::GLM objects should be created until an OpenGL context has first been established, by, eg, opening a GLUT or SDL OpenGL window.
my $object = new OpenGL::GLM('camel.obj');
Reads a model description from a Wavefront .OBJ file, and returns an OpenGL::GLM object. Takes one argument, the name of the file.
my $scale = $object->Unitize;
``Unitizes'' a model by translating it to the origin and scaling it to fit in a unit cube around the origin. Returns the scalefactor used.
$model->Scale($scalefactor);
Scales a model by a given amount.
$model->ReverseWinding;
Reverse the polygon winding for all polygons in this model. Default winding is counter-clockwise. Also changes the direction of the normals.
$model->FacetNormals;
Generates facet normals for a model (by taking the cross product of the two vectors derived from the sides of each triangle). Assumes a counter-clockwise winding.
$model->VertexNormals($angle,$keep_existing);
Generates smooth vertex normals for a model. First builds a list of all the triangles each vertex is in. Then loops through each vertex in the the list averaging all the facet normals of the triangles each vertex is in. Finally, sets the normal index in the triangle for the vertex to the generated smooth normal. If the dot product of a facet normal and the facet normal associated with the first triangle in the list of triangles the current vertex is in is greater than the cosine of the angle parameter to the function, that facet normal is not added into the average normal calculation and the corresponding vertex is given the facet normal. This tends to preserve hard edges. The angle to use depends on the model, but 90 degrees is usually a good start.
=over 2
$model->LinearTexture;
Generates texture coordinates according to a linear projection of the texture map. It generates these by linearly mapping the vertices onto a square.
$model->SpheremapTexture;
Generates texture coordinates according to a spherical projection of the texture map. Sometimes referred to as spheremap, or reflection map texture coordinates. It generates these by using the normal to calculate where that vertex would map onto a sphere. Since it is impossible to map something flat perfectly onto something spherical, there is distortion at the poles. This particular implementation causes the poles along the X axis to be distorted.
$model->WriteOBJ($filename,$mode);
Writes a model description in Wavefront .OBJ format to a file. $mode is a bitwise OR of values describing what is written to the file:
GLM_FLAT and GLM_SMOOTH should not both be specified.
$model->Draw($mode);
Renders the model to the current OpenGL context using the mode specified. $mode is a bitwise OR of values describing what is to be rendered:
GLM_FLAT and GLM_SMOOTH should not both be specified.
$model->List($mode);
Generates and returns a display list for the model using the mode specified. $mode is a bitwise OR of values describing what is to be rendered:
GLM_FLAT and GLM_SMOOTH should not both be specified.
$model->Weld($epsilon);
Eliminate (weld) vectors that are within an epsilon of each other. $epsilon is the maximum difference between vertices ; 0.00001 is a good start for a unitized model.
GLM_2_SIDED GLM_COLOR GLM_FLAT GLM_MATERIAL GLM_MAX_SHININESS GLM_MAX_TEXTURE_SIZE GLM_NONE GLM_SMOOTH GLM_TEXTURE
Jonathan Chin, <jon-opengl-glm@earth.li>
Copyright (C) 2005 by Jonathan Chin. Released and distributed under the GPL.