Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3660972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:15:27+00:00 2026-05-19T01:15:27+00:00

I would like to load textures, and then have them be used by multiple

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:15:27+00:00Added an answer on May 19, 2026 at 1:15 am
    1. yes, this would work
    2. no need to make them be a reference: you store/pass a copy of a pointer (it’s fast), and you don’t plan to change this pointer outside
    3. there’re many different ways to do this, and the right one depends on your other code requirements.

    e.g. you can use a global instance of textures:

    textures.cpp:

    static std::vector load_once_textures();
    std::vector<GLuint> const& get_textures()
    {
        static std::vector<GLuint> const the_textures = load_once_textures();
        return the_textures;
    }
    
    std::vector load_once_textures()
    {
        // loading
    }
    

    textures.h

    std::vector<GLuint> const& get_textures();
    

    it’s a simple approach and safe enough because textures will be loaded once and loading doesn’t have a problem of static initialization order ambiguity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am loading a Texture2D that contains multiple sprite textures. I would like to
I have been working on a web page and would like to load multiple
I would like to have the choice in a variable_load function (as used to
I have a 100 megabytes SQLite database file that I would like to load
I would like to load a BMP file, do some operations on it in
I would like to load a specific ConfigurationSection but the way the CLR loads
I'm trying to improve performance under high load and would like to implement opcode
I am relatively new to using jQuery and would like to use the load
I would like to have a reference for the pros and cons of using
i would like to load xml into dataset with only 2 columns (name, price)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.