Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jojo_the_fluffy_bear

Problems loading a texture.

This topic is 5281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okie doke. This is my first post to the GDnet forums, and as such, please forgive any noobish mistakes. I''ve been thinking recently that it would be nice to have textures in my programs, because quite frankly there is only so much you can do with lines, points and flat shaded polygons. The code I''m using for loading textures is taken directly out of the OpenGL Game Programming book (2nd edition). I''ve typed it word for word, looked at the source on the companion cd to the book, compiled, recompiled, smashed my fist into wall and cried long and hard in a dark corner of my cellar, but all to no avail. It simply will not work. I have a suspicion that the problem lies in the file loading part of the code, but I''m not sure how or why. Oh, and I''m using MSVC++ v.6(student edition, because I''m poor), Win32 Release and Win32 debug build, it doesn''t matter which one as they both don''t work equally well. This function resides in texture.h and is responsible for loading the textures.
#include <stdio.h>
#include <stdlib.h>

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
	
	FILE *filePtr;
	BITMAPFILEHEADER bitmapFileHeader;
	unsigned char *bitmapImage;
	int imageIdx = 0;
	unsigned char tempRGB;


	filePtr = fopen(filename, "rb");
//From what I can tell, this is where the problems start


	if(filePtr == NULL)
	{
		did_text_not_load = true; 
                //this is declared elsewhere in the code so that

                //all the cubes that should have a texture on it                 

                //are draw in green when this is true and the 

                //texture didn''t load


		return NULL;
	}

... the rest isn''t important because it never makes it past this point
Then when initializing all of the important GL stuff, the function gets called like so.
bitmapData = LoadBitmapFile("test.bmp", &bitmapInfoHeader);
.
.
.
if(did_text_not_load == true)
{
     glColor3f(0.0f, 1.0f, 0.0f);
}
And before you ask, yes I have a test.bmp file in the executable directory. So, now when the program is compiled directly from Visual Studio, it works like it normally would, save for the nice spinning green cubes. If you''ve read the code above then you will see this is what I don''t want. Even more perplexing is that when I run the program outside of Visual Studio, it crashes during startup. I''m at my wits end here, so any help you could offer would be much appreciated. Oh, and if I failed to explain my problem adequately feel free to bash me on the head. Thanks in advance! -Jojo the fluffy bear

Share this post


Link to post
Share on other sites
Advertisement
Tried NeHe tutorials ??
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06


- Iliak -

Share this post


Link to post
Share on other sites
When you run from Visual Studio, the current directory is the project directory, not the executable directory. So, you get a NULL filePtr (because the bmp is not in the current directory), hence the green cubes.

When you run from outside of VS, you are in the executable directory. The program finds the bmp file and proceeds with a non-NULL filePtr. The crash is probably ocurring in the section you''ve marked "the rest isn''t important because it never makes it past this point", or somewhere in between the call to LoadBitmapFile and the test of your flag.

Move the bmp file to you project directory, then run the code through the VS debugger. That should tell you where it''s crashing.

Share this post


Link to post
Share on other sites
I just tried the NeHe''s tutorial and that worked wonderfully, but I''m reluctant to use it for too long as I don''t like relying on any of the glaux functions (I''m just a fussy little ninny like that).

Actually, the file to load was both in the executable and project directories. But I think you''re right about the problem being somewhere else in the code.

Hey guys, thanks for your help. I appreciate it very much!

-Jojo the fluffy bear

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!