N
Nick L
I'm working on a function which creates a pointers to an array of unsigned
ints based off a number read from a file. I then continue to read file names
from the file, convert the name to a char* and use it to load an texture
from some outside functions. My problem lies in the "for loop", the Code
goes as follows.
//I create the array of pointers, I'm using 2 just for the sake of an
example
MapTextures = new unsigned int[2];
//Start up a for loop
for(int I = 0; I < 2; I++)
{ //I then read the filename from the file.
LevelStream >> Cmd;
//Convert the string I read to a char*
Name = strdup (Cmd.c_str());
//Use the filename to load the coorisponding image into the first
element on the array
MapTextures = LoadTextureWithAlpha(Name);
}
This is the way I'd like to do it, but for some reason it does'nt work and
for the life of me I can't figure out why. When the code executes it will
read both file names and convert them just fine, but it will only load one
texture. The following code I tried while I was troubleshooting and it works
perfectly.
LevelStream >> Cmd;
Name = strdup (Cmd.c_str());
MapTextures[0] = LoadTextureWithAlpha(Name);
LevelStream >> Cmd;
Name = strdup (Cmd.c_str());
MapTextures[1] = LoadTextureWithAlpha(Name);
This way is'nt preferable because it involves hardcoding a set amount, and I
really really want to know why the method involving the "for loop" will only
load the one texture. Given that this peice of code works it would, to me,
imply that the problem I'm having in the "for loop" lies in the fact that it
is a for loop and not the functions within.
Does it have something to do with the way a for loop is handled after
being compiled? Or am I just missing something obvious?
Thanks
Nick
ints based off a number read from a file. I then continue to read file names
from the file, convert the name to a char* and use it to load an texture
from some outside functions. My problem lies in the "for loop", the Code
goes as follows.
//I create the array of pointers, I'm using 2 just for the sake of an
example
MapTextures = new unsigned int[2];
//Start up a for loop
for(int I = 0; I < 2; I++)
{ //I then read the filename from the file.
LevelStream >> Cmd;
//Convert the string I read to a char*
Name = strdup (Cmd.c_str());
//Use the filename to load the coorisponding image into the first
element on the array
MapTextures = LoadTextureWithAlpha(Name);
}
This is the way I'd like to do it, but for some reason it does'nt work and
for the life of me I can't figure out why. When the code executes it will
read both file names and convert them just fine, but it will only load one
texture. The following code I tried while I was troubleshooting and it works
perfectly.
LevelStream >> Cmd;
Name = strdup (Cmd.c_str());
MapTextures[0] = LoadTextureWithAlpha(Name);
LevelStream >> Cmd;
Name = strdup (Cmd.c_str());
MapTextures[1] = LoadTextureWithAlpha(Name);
This way is'nt preferable because it involves hardcoding a set amount, and I
really really want to know why the method involving the "for loop" will only
load the one texture. Given that this peice of code works it would, to me,
imply that the problem I'm having in the "for loop" lies in the fact that it
is a for loop and not the functions within.
Does it have something to do with the way a for loop is handled after
being compiled? Or am I just missing something obvious?
Thanks
Nick