Global variable not updating

Hello! I am trying to find out why my global variables (textureBank, textureFree, numTextures) are not being updated from the texture object's constructor method texture(SDL_Surface *rawSurface). It is as if there is a local copy in that block, which appears to be updated inside the function, but outside of it retains its original value. I have tried this with and without the static keywords. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
//texture.cpp
#include "texture.h"
#include "iostream"

static GLuint textureBank[256];
static bool textureFree[256];
static int numTextures;

[CODE]void texture::generateTextureHandles()
{
    std::fill_n(textureFree, 256, true);
    glGenTextures( 256, textureBank);
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[texture::texture(SDL_Surface *rawSurface)
{
    for(int a = 0; a < 256; a++)
    {
        std::cout << "texture # " << a << " status is " << textureFree[a];

        if(textureFree[a] == true)
        {

            glTexture = a;
            numTextures++;
            textureFree[a] = false;
            std::cout << " true, taking\n";
            break;
        }
    }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
#include "gfxUtilities.h"

class texture
{
      private:
              int glTexture;
              SDL_Rect imageRect;
              SDL_Rect textureRect;

      public:
             texture();
             ~texture();
             texture(SDL_Surface *rawSurface);
             int getTextureIndex();
             void drawTexture(int x, int y);
             SDL_Rect getImageRect();
             void generateTextureHandles();
};





Is textureBank, textureFree and numTextures only used inside texture.cpp?
Topic archived. No new replies allowed.