C++: Reference and Pointer question (example regarding OpenGL)
Posted
by
Jay
on Stack Overflow
See other posts from Stack Overflow
or by Jay
Published on 2011-01-02T05:34:34Z
Indexed on
2011/01/02
5:54 UTC
Read the original article
Hit count: 235
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.
© Stack Overflow or respective owner