I am having problems trying to load a bitmp file.
I am using Dev-C++, NeHeOop and have used NeHe lesson 6 for the bitmap loading functions that I have put into the Tex_Class class.
The Code compiles with no errors.
The problem seems to be that *tex_fname is not being set or read properly as loadBMP and LoadGLTexture return NULL and False.
"data/NeHe.bmp" exists and is 128x128.
I have searched the threads and tried everything I can think of but to me it looks like it should work and I am out of Ideas.
Any help/ideas would be appreciated greatly.
Am I going about this the wrong way or complicating matters?
Thankyou.
I have only included the relevant source.
//NeHeGL.h
class Tex_Class
{
public:
char *tex_fname;
GLuint *texture;
AUX_RGBImageRec *LoadBMP(char *Filename);
int LoadGLTexture(Tex_Class *TC);
Tex_Class()
{
tex_fname = "";
texture = new GLuint;
}
};
Function Definitions
//NeHeGL.cpp
AUX_RGBImageRec* Tex_Class::LoadBMP(char *Filename)
{
FILE *File=NULL;
if (!Filename)
{
return NULL;
}
File=fopen(Filename,"r");
if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}
return NULL;
}
int Tex_Class::LoadGLTexture(Tex_Class *TC)
{
int Status=FALSE;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1);
if (TextureImage[0]=LoadBMP(TC->tex_fname))
{
Status=TRUE;
glGenTextures(1, &TC->texture[0]);
glBindTexture(GL_TEXTURE_2D, TC->texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
return Status;
}
Using the Class
//Example.cpp
Tex_Class *Texture = new Tex_Class;
GLuint * ptexture = Texa->texture;
//In GL_Window::Initialize() ...
Texture->tex_fname = "data/NeHe.bmp";
if (!Texture->LoadGLTexture(Texture)) {
return FALSE; //PROGRAM EXITS ON THIS RETURN, IF COMMENTED OUT DRAWS WHITE BOX
}
return TRUE;
//In GL_Window::Draw ...
glBindTexture(GL_TEXTURE_2D, ptexture[0]);
[edited by - anykey on January 9, 2004 8:52:58 PM]
[edited by - anykey on January 9, 2004 8:55:38 PM]