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!
Code:
//texture.cpp
#include "texture.h"
#include "iostream"
static GLuint textureBank[256];
static bool textureFree[256];
static int numTextures;
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;
}
}
Code:
#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();
};