C++: Reference and Pointer question (example regarding OpenGL)
- by Jay
I would like to load textures, and then have them be used by multiple objects. Would this work?
class Sprite
{
GLuint* mTextures; // do I need this to also be a reference?
Sprite( GLuint* textures ) // do I need this to also be a reference?
{
mTextures = textures;
}
void Draw( textureNumber )
{
glBindTexture( GL_TEXTURE_2D, mTextures[ textureNumber ] );
// drawing code
}
};
// normally these variables would be inputed, but I did this for simplicity.
const int NUMBER_OF_TEXTURES = 40;
const int WHICH_TEXTURE = 10;
void main()
{
std::vector<GLuint> the_textures;
the_textures.resize( NUMBER_OF_TEXTURES );
glGenTextures( NUMBER_OF_TEXTURES, &the_textures[0] );
// texture loading code
Sprite the_sprite( &the_textures[0] );
the_sprite.Draw( WHICH_TEXTURE );
}
And is there a different way I should do this, even if it would work?
Thanks.