I cannot load a texture file into the scene even though it is a very simple program that draws rectangle and put texture on the rectanngle. The code works fine in the Visual C++ but won’t load a texture file on my Xcode. Is this related to the endian-ness issue?
How can I fix this?
Thanks in advance.
texture = new TGAImage();
texture->open("Texture exture1.tga");
i use the raw texture loader:
// Struct für das img erstellen
typedef struct _RGBIMG {
GLuint w; // X Komponente des Bildes
GLuint h; // Y Komponente des Bildes
GLubyte* data; // Datenbereich des Bildes
} RGBIMG; // Instanz erzeugen
bool load(const char* file_name, int w, int h, RGBIMG* refimg)
{
GLuint sz;
FILE* file;
long fsize;
GLubyte* p;
refimg->w = (GLuint) w;
refimg->h = (GLuint) h;
sz = (((3*refimg->w+3)>>2)<<2)*refimg->h;
refimg->data = new GLubyte [sz];
if (refimg->data == NULL) {
cout << "Speicherplatzzuweisungspobleme. " << file_name << endl;
return false;
}
file = fopen(file_name , "rb");
if (!file)
{
cout << "Datei nicht gefunden. (" << file_name << ")" << endl; return false;
}
fseek(file, 0L, SEEK_END);
fsize = ftell(file);
if (fsize != (long)sz) {
cout << "Fehlerhafte Größenangabe der Textur " << file_name << endl;
fclose(file);
return false;
}
fseek(file, 0L, SEEK_SET);
p = refimg->data;
while (fsize > 0) {
fread(p, 1, 1, file);
p++;
fsize--;
}
fclose(file);
cout << "Datei in RAM geladen. (" << file_name << ")" << endl;
return true;
}
usage:
RGBIMG img;
load(name, w, h,&img);
this code loads .raw files, w and h is the size of the raw file in pixels…
i hope this helps but also i am interestet in your tga loading problem!
the path could be a problem in your code:
texture = new TGAImage();
texture->open("Texture/texture1.tga");
would be better: in unix the backslash is a slash
system
Closed
October 19, 2021, 5:18pm
3
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.