Jump to content
  • Advertisement
Sign in to follow this  

Problem loading texture files

This topic is 3309 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

Hi, I posted this to the beginers forum but didn't get any help so I am hoping that this second post will be allowed. Thank you I am not understanding why my load texture function is returning NULL when I run it. The file is in the correct place but it just isn't loading. The .bmp listed loads into some example code that I have so I don't think that it is a problem with the image file. My best guess is that somehow I am not getting the path correct. Is there some way to post the contents of a HRESULT to a MessageBox for understanding why my function call has failed? the prototype
	ID3D10Texture2D	*loadTexture2DFromFile (LPCWSTR filename);

the call
	// load textures
	g_pTexture1 = loadTexture2DFromFile (TEXT("./spaceAce.bmp"));

the function
// getTexture2DFromFile
// loads a 2D texture object to memory and returns a pointer to it

ID3D10Texture2D	*loadTexture2DFromFile (LPCWSTR filename)
	// local variables
	ID3D10Texture2D	*pTexture = NULL;
	ID3D10Resource	*pResource = NULL;

	// local declarations
	HRESULT hr = D3DX10CreateTextureFromFile (g_pD3D10Device, filename, NULL, NULL, &pResource, NULL);
	if (FAILED(hr))
		MessageBox(NULL, filename, L"Texture Load Failure", MB_OK);
		return NULL;
	pResource->QueryInterface(__uuidof(ID3D10Texture2D), (LPVOID*) &pTexture);

	// return
	return pTexture;

when I run the code I get the Messagebox error message with the path of the bmp that I am trying to load. What have I done wrong?

Share this post

Link to post
Share on other sites
When your running the code are you running it from within the compiler (start debugging) or running the exe that is created after you compile?

Does it still happen if you fully define the file path to the file that you are loading?

IE: g_pTexture1 = loadTexture2DFromFile (TEXT("c:/folder/spaceAce.bmp"));

If its only happening when you start debugging, theres a pathing issue with how you've set up your project.

I found that by default a project created in VS2008 that 'start debug' would call for the files to be in:
<drive>\<project path>\<Project Name>\<Project Name> (this is where the Resource files are held)
however would compile the executables to be in:
<drive>\<project path>\<Project Name>\Debug (for the debug release)

So if your using implicit folder pathing, you need to store the resources within the project resource directory if your running the inbuilt debugger and store the resources within the debug folder if you run the executable directly.

To output the HRESULT, you will need to append it to a string or similar then output that full string to the message box.

so something like (pseudo)

hresult = <function returning a hresult>;
std::string tempOutput = "Error occured HRESULT = ";

Share this post

Link to post
Share on other sites
The function returns NULL both in debug mode and when I run the "release" build of the code. Also a full static path being passed to the function doesn't change the behavoir of the program. I have the .bmp in question in the <project>/<project> folder, the <project>/Release folder and the c:\ folder and the program refuses to load the resource from any location. Given the location of the NULL return the program isn't even loading as a resource file as this fails before the translation from Resource to 2DTexture I think it is failing to translate from text to path some how :(

Share this post

Link to post
Share on other sites
Are you creating your D3D10 device with the debug layer? Use D3D10_CREATE_DEVICE_DEBUG with CreateDevice.

Are you linking with the debug D3DX for D3D10?

Use d3dx10d.lib in your link input instead of d3dx10.lib.

If you do both of those things, then you should have a relevant message in the debug output when you run your program. Most likely it is a path problem.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!