Sign in to follow this  

Easy 'load texture from resource' question...

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

Here's an easy one! I've never done this before, and I don't really know where to start, and I can't find anything on Google that I can make heads or tails out of, and I like to make sentences run forever and ever, so I though I'd ask the experts. Here's some sample code that doesn't work, because I'm sure I'm doing something wrong...
	if (D3D_OK != D3DXCreateTextureFromResource(DXStuff->g_pd3dDevice,
		NULL,
		MAKEINTRESOURCE(IDR_JPEG1),
		&DXEnts->BlockGroup.g_QuadsTB.Texture))
	{
		wsprintf(DXStuff->critErrorCap, "%s", "CreateTexBuffer");
		wsprintf(DXStuff->critErrorText, "%s", "CreateTexBuffer: Couldn't find resource?");

		return 1;
	}
In my CPP environment, I right-clicked in my Resources to "Add Resource..." and then created a custom one called 'Jpeg'. I put the file 'resources\init.jpg' into it, and my CPP environment showed a bunch of binary data instead of the image in the IDE, so I know it loaded something. I then compiled the executable, and it increased in size in relation to the size of the file 'init.jpg', so I know that the jpeg data got compiled into the executable. The ID for my jpeg resource is IDR_JPEG1. How do I get the above to load the texture stored in the resource 'IDR_JPEG1' into my Direct3D texture buffer? And if the above is correct, how do I add a 'jpeg' or 'tga' resource to my program so that I can use it for the above texture loading function? Thanks in advance for the help, I really appreciate it!

Share this post


Link to post
Share on other sites
Look in your rcfile - open it manually. Your line with the .jpg file should read something like:

IDR_JPEG1 rcdata "<either relative or absolute path.jpg>"

Unfortunately the newer versions (don't know about 2005) of VS .net corrupt this line when you try to add the resource in the way you specified. Simply fix the .rc file manually and you'll be set. Sadly I haven't found a better fix yet.

Good luck!

Share this post


Link to post
Share on other sites
Thanks for the help, Steven Hansen! That worked great. Pretty weird that it has to be done that way, though... Guess Microsoft only wants people using bmp files in their games, heh!

Thanks again!

Share this post


Link to post
Share on other sites

This topic is 4416 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this