i have a little problem adding textures to my scene.
I create my textures using the photoshop RAW-format. size 256*256 * 3 colors (RGB)(filesize: 196608 bytes)
loaded with
// then, texture-parameters, lightning parameters and so… are set…
}
and now the problem. 2 files, same size. one is loaded and displayed, the other not. fileattributes are set correct, filename is also no problem, filesize is equal…even access rights…
one is loaded and displayed, if i create another texture (for example with the same filename) it won’t be displayed…
Next, stop with the debugger at
return pic;
and look if fgets has loaded something.
To check it better, fill the memory “pic” you allocated before with 0’s.
Next, you never close the file! fclose(x)
is needed, otherwise you wont get another
file handle in w9x.
I close the files. this code wasn’t copied out of my original source, cause i’m not at the machine where i wrote it
The files are opened. but I’ll try to check this out a little bit better. even if fgets will succeed.
but i think this is not the error. caus eat some textures you’ll se some parts of them on the poly. ?!?
finally I could solve it.
I changed char* to void* and fgets to fread.
but i still don’t know why it works with the one file and not with the other (now it works with all)(filesize & access rithts are the same).
i think there some probs with strings and so…
Like the previous poster said, fgets is not the function to use for loading binary data.
The short description for the function is:
The fgets function reads a string from the input stream argument and stores it in string. fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n – 1, whichever comes first. The result stored in string is appended with a null character. The newline character, if read, is included in the string.
Instead of fgets you should use fread, like this:
char *loadtech(char *fname)
{
int bytesRead = 0;
char *pic = null;
FILE *x = null;
pic = (char *) malloc(196608);
if (pic == NULL)
return null;
x = fopen(fname, “rb”);
if (x == NULL)
return null;
bytesRead = fread(pic, sizeof(char), 196608, x);
if (bytesRead != 196608)
{
free(pic);
fclose(x);
return null;
}
fclose(x);
return pic;
}
This should give you the basic error checking that you should implement always when you are trying to get some system resources. It will save you alot of trouble later if you do so.
Janne / Endymio - TDT Productions
[This message has been edited by Janne (edited 11-19-2000).]