Advertisement

Bitmap loading problem - NeHeOop + lesson 6.

Started by January 09, 2004 07:51 PM
4 comments, last by anykey 21 years, 1 month ago
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]
Sorry, In Example.cpp

Texa->texture should be Texture->texture.

Advertisement
Try using this function to set the filename before loading

void Tex_Clas::SetFilename(const char* filename){// stlen doesn''t account for NULL char at end of stringint length = strlen(filename) + 1; tex_fname = new char[length];strcpy(tex_fname, filename, length);}


Thankyou MessageBox.
I have implemented a SetFileName Fuction for my Tex_Class and it looks like it should work but still the Texture is not loading.

I have tried moving the Texture(Tex_Class) Variable declaration into WinMain and passing a pointer to the GL_Window Initialize and Draw functions that call the LoadGLTexture (and LoadBMP) and the glBindTexture functions.

I have tried setting tex_fname and Filename to "Data/NeHe.bmp" in all sorts of wierd places and ways (Class Constructor, LoadGLTexture, WinMain,...) and still the same thing.

I will probably slap myself when I figure this one out because I am sure it will be something simple or stupid.

Anyway - Back to the drawing board.
Thanks again.
Can nobody help or offer some advice/abuse or even a sexy come on line. I have been at this for a couple of days now (on and off) and still nada. I am learning C++ and OpenGL and this is the first problem I have given myself that I can not solve, Am I stupid?

Should I not be passing in the Texture (Tex_Class) pointer to the LoadGLTexture (Tex_Class Member) Function and instead use this inside the function or somthing???

I have read elsewhere that I need Opengl initilised before loading the bitmap, I think I am but maybe I am missing something?

Please if you can offer a little help or a nudge in the right direction it would be much appreciated.

Thankyou.

PS, Sorry about this ''bump''
*slap* Damn I am THE IDIOT *slap* Damn stupid me *double backhanded self slap to the face*.

Der...

glEnable *slap slap* (GL_TEXTURE_2D); *slap* helps a little.

ha ha.

Now I am the ''super sleek ultra noob opengl master'' all stand back and bask in my glory *slap*.

I should relable this thread ''slap me'', and flames should be allowed and encouraged.

Not too bad for my first bug.

This topic is closed to new replies.

Advertisement