CSCI441 OpenGL Library 5.9.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
CSCI441::ModelLoader Class Referencefinal

Loads object models from file and renders using VBOs/VAOs. More...

#include <ModelLoader.hpp>

Public Member Functions

 ModelLoader ()
 Creates an empty model.
 
 ModelLoader (const char *filename)
 Loads a model from the given file.
 
 ~ModelLoader ()
 Frees memory associated with model on both CPU and GPU.
 
 ModelLoader (const ModelLoader &)=delete
 do not allow models to be copied
 
ModelLoaderoperator= (const ModelLoader &)=delete
 do not allow models to be copied
 
bool loadModelFile (std::string filename, bool INFO=true, bool ERRORS=true)
 Loads a model from the given file.
 
void setAttributeLocations (GLint positionLocation, GLint normalLocation=-1, GLint texCoordLocation=-1) const
 Enables VBO attribute array locations.
 
bool draw (GLuint shaderProgramHandle, GLint matDiffLocation=-1, GLint matSpecLocation=-1, GLint matShinLocation=-1, GLint matAmbLocation=-1, GLenum diffuseTexture=GL_TEXTURE0) const
 Renders a model.
 
GLuint getNumberOfVertices () const
 Return the number of vertices the model is made up of. This value corresponds to the size of the Vertices, TexCoords, and Normals arrays.
 
GLfloat * getVertices () const
 Return the vertex array that makes up the model mesh.
 
GLfloat * getNormals () const
 Return the normal array that corresponds to the model mesh.
 
GLfloat * getTexCoords () const
 Return the texture coordinates array that corresponds to the model mesh.
 
GLuint getNumberOfIndices () const
 Return the number of indices to draw the model. This value corresponds to the size of the Indices array.
 
GLuint * getIndices () const
 Return the index array that dictates the order to draw the model mesh.
 

Static Public Member Functions

static void enableAutoGenerateNormals ()
 Enable auto-generation of vertex normals.
 
static void disableAutoGenerateNormals ()
 Disable auto-generation of vertex normals.
 

Detailed Description

Loads object models from file and renders using VBOs/VAOs.

Constructor & Destructor Documentation

◆ ModelLoader()

CSCI441::ModelLoader::ModelLoader ( const char *  filename)
inlineexplicit

Loads a model from the given file.

Parameters
filenamefile to load model from

Member Function Documentation

◆ disableAutoGenerateNormals()

void CSCI441::ModelLoader::disableAutoGenerateNormals ( )
inlinestatic

Disable auto-generation of vertex normals.

Warning
Must be called prior to loading in a model from file
Note
No normals are generated by default
To enable, call enableAutoGenerateNormals

◆ draw()

bool CSCI441::ModelLoader::draw ( GLuint  shaderProgramHandle,
GLint  matDiffLocation = -1,
GLint  matSpecLocation = -1,
GLint  matShinLocation = -1,
GLint  matAmbLocation = -1,
GLenum  diffuseTexture = GL_TEXTURE0 
) const
inline

Renders a model.

Parameters
shaderProgramHandleshader program handle that
matDiffLocationuniform location of material diffuse component
matSpecLocationuniform location of material specular component
matShinLocationuniform location of material shininess component
matAmbLocationuniform location of material ambient component
diffuseTexturetexture number to bind diffuse texture map to
Returns
true if draw succeeded, false otherwise

◆ enableAutoGenerateNormals()

void CSCI441::ModelLoader::enableAutoGenerateNormals ( )
inlinestatic

Enable auto-generation of vertex normals.

Warning
Must be called prior to loading in a model from file
Note
If an object model does not contain vertex normal data, then normals will be computed based on the cross product of vertex winding order.
No normals are generated by default
To disable, call disableAutoGenerateNormals

◆ getIndices()

GLuint * CSCI441::ModelLoader::getIndices ( ) const
inline

Return the index array that dictates the order to draw the model mesh.

Returns
pointer to the index array
Note
For use with IBOs

◆ getNormals()

GLfloat * CSCI441::ModelLoader::getNormals ( ) const
inline

Return the normal array that corresponds to the model mesh.

Returns
pointer to the normal array
Note
For use with VBOs

◆ getNumberOfIndices()

GLuint CSCI441::ModelLoader::getNumberOfIndices ( ) const
inline

Return the number of indices to draw the model. This value corresponds to the size of the Indices array.

Returns
the number of indices when drawing the model

◆ getNumberOfVertices()

GLuint CSCI441::ModelLoader::getNumberOfVertices ( ) const
inline

Return the number of vertices the model is made up of. This value corresponds to the size of the Vertices, TexCoords, and Normals arrays.

Returns
the number of vertices within the model

◆ getTexCoords()

GLfloat * CSCI441::ModelLoader::getTexCoords ( ) const
inline

Return the texture coordinates array that corresponds to the model mesh.

Returns
pointer to texture coordinate array
Note
For use with VBOs

◆ getVertices()

GLfloat * CSCI441::ModelLoader::getVertices ( ) const
inline

Return the vertex array that makes up the model mesh.

Returns
pointer to vertex array
Note
For use with VBOs

◆ loadModelFile()

bool CSCI441::ModelLoader::loadModelFile ( std::string  filename,
bool  INFO = true,
bool  ERRORS = true 
)
inline

Loads a model from the given file.

Parameters
filenamefile to load model from
INFOflag to control if informational messages should be displayed
ERRORSflag to control if error messages should be displayed
Returns
true if load succeeded, false otherwise

◆ setAttributeLocations()

void CSCI441::ModelLoader::setAttributeLocations ( GLint  positionLocation,
GLint  normalLocation = -1,
GLint  texCoordLocation = -1 
) const
inline

Enables VBO attribute array locations.

Parameters
positionLocationattribute location of vertex position
normalLocationattribute location of vertex normal
texCoordLocationattribute location of vertex texture coordinate

The documentation for this class was generated from the following file: