Hey everyone, once again another question. I have a Sprite Class, that holds a pointer to a GLuint called TextureHandle. My Tile Class creates an instance of Sprite, and has a function called CopyTextureTile(GLuint texture).
void Tile::CopyTextureTile(GLuint texture)
{
TileSprite.TextureHandle = new GLuint;
TileSprite.TextureHandle = &texture
}
There is what that function looks like. My texture manager has a function returning GLuint to get a private texture manager texture. That looks like this.
GLuint TextureManager::GetTexture(char TextureID)
{
if(TextureID == '0')
return TerrainTextures[0];
else if(TextureID == '1')
return TerrainTextures[1];
else if(TextureID == '2')
return TerrainTextures[2];
else if(TextureID == '3')
return TerrainTextures[3];
else if(TextureID == '4')
return TerrainTextures[4];
else if(TextureID == '5')
return TerrainTextures[5];
else if(TextureID == '6')
return TerrainTextures[6];
else if(TextureID == '7')
return TerrainTextures[7];
else if(TextureID == '8')
return TerrainTextures[8];
else if(TextureID == '9')
return TerrainTextures[9];
else
MessageBox(NULL, "That's not a valid texture", "RPG", MB_ICONEXCLAMATION);
return NULL;
}
My Map class has a 100 x 100 array of "Tile." The constructor calls loadMap to load up the map from a file. It then takes the info from the file, and copies the textures into the Tile.Sprite.TextureHandle, via CopyTextureTile. That Constructor looks like this.
Map::Map()
{
if(!LoadMap())
MessageBox(NULL, "The map was not loaded", "RPG", MB_ICONEXCLAMATION);
for(int yIndex = 0; yIndex < 100; yIndex++)
{
for(int xIndex = 0; xIndex < 100; xIndex++)
{
MapArray[yIndex][xIndex].ID = MapFileLines[yIndex][xIndex];
MapArray[yIndex][xIndex].CopyTextureTile(TexMan.GetTexture(MapArray[yIndex][xIndex].ID));
}
}
}
MapFileLines[yIndex][xIndex] is a character that was previously read from a file.
Later, when I want to render the tiles though, the TextureHandle gives me problems.In my Render Class, I have two functions, RenderTile, and RenderMap.
void Renderer::RenderTile(float x, float y, GLuint Texture)
{
static int count=0;
float outx, outy, outx2, outy2;
outx = (100.0 / (x * 16.0)) - 1.5;
outx2 = (100.0 / (x * 16.0)) - 1.4375;
outy = (100.0 / (y * 16.0)) - 1.5;
outy2 = (100.0 / (y * 16.0)) - 1.4375;
glBegin(GL_QUADS);
glBindTexture(GL_TEXTURE_2D, Texture);
glTexCoord2f(0.0, 0.0); glVertex2f(outx, outy);
glTexCoord2f(0.0, 1.0); glVertex2f(outx, outy2);
glTexCoord2f(1.0, 1.0); glVertex2f(outx2, outy2);
glTexCoord2f(1.0, 0.0); glVertex2f(outx2, outy);
glEnd();
count++;
}
void Renderer::RenderMap()
{
for(int y = 0; y <= 100; ++y)
{
for(int x = 0; x <= 100; ++x)
{
RenderTile((float)x, (float)y, *TestMap.MapArray[x][y].TileSprite.TextureHandle); //This line
}
}
}
When I dereference the pointer to pass it as a GLuint, it has some sort of memory leak, and Windows comes up with a serious error. Could someone point out what I am doing wrong with my pointer?
Sorry if I rambled and made things hard to understand.
Thanks!