• Advertisement

D3DXLoadSurfaceFromResource

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

Hello, I am having a little trouble using D3DXLoadSurfaceFromResource. I have a .rc file containing information for one bitmap: IDB_IMAGE1 BITMAP "testimage.bmp" and a header file called Resource.h that also contains the bitmap: #define IDB_IMAGE1 2000 now in a .cpp file I have this D3DXLoadSurfaceFromResource function, I am converting it from D3DXLoadSurfaceFromFile. this is what it looks like now:
result = D3DXLoadSurfaceFromResource(
image,              //destination surface
NULL,               //destination palette
NULL,               //destination rectangle
NULL,				//HMODULE
filename,           //source filename
NULL,               //source rectangle
D3DX_DEFAULT,       //controls how image is filtered
transcolor,         //for transparency (0 for none)
NULL);              //source image info (usually NULL)


filename is a TCHAR and the NULL for HMODULE I think is supposed to be something to get the bmp from my resources but I dont know how to do that... Can someone help me with this? Thanks, Progames25

Share this post

Share on other sites
Advertisement
Anyone?
Well, maybe if I reword this...
So basically im trying to figure out how to use D3DXLoadSurfaceFromResource/D3DXLoadTextureFromResource in my Project.
The one thing im having trouble with it is the HMODULE param, I understand that if it is NULL it looks for images on your system/desktop or something like that, but I have one bitmap and a resource file adn header that I want that function to look for, how do I use this properly?

Thanks,
Progames25

Share this post

Share on other sites
Moving to the DX forum.

Share this post

Share on other sites
What's the HRESULT value, and what do the debug runtimes print to the output window (you do have them enabled, right?)?

Share this post

Share on other sites
result (the HRESULT) just makes sure that the functions returns D3D_OK:
if (result != D3D_OK)
return NULL;

it checks that after a call such as the LoadTexture, loadSurface, CreateOffscreenPlainSurface, etc...

Quote:
 and what do the debug runtimes print to the output window (you do have them enabled, right?)?

Debug runtimes...since nothing rings a bell in my mind when you ask me that im not sure if they are enabled...

Thanks,
Progames25

Share this post

Share on other sites
You should not check "if(result != D3D_OK)" but rather "if(FAILED(result))" because there is more than one success value for HRESULTs.

The debug runtimes can be enabled via the DirectX Control Panel, which is typically found under the DirectX Utilities item in the start menu entry for your DirectX SDK installation.

Share this post

Share on other sites
DirectX Debug Runtimes.

Things I see that could go wrong:
1. Your image is null; you need to create the surface in advance, D3DXLoadSurfaceFromResource won't do that for you.
2. The resource name you're using is wrong - You might need to use MAKEINTRESOURCE.

Share this post

Share on other sites
Here's some code from my Engine load a texture from a resourceID, hope it helps
I seem to remember that i first tried D3DXLoadSurfaceFromResource, but could not get it to work, so i then moved on to D3DXCreateTextureFromFileInMemory, as this piece of code shows.

void CreateTextureFromResource(LPCTSTR ResourceID){D3DSURFACE_DESC desc;HRESULT			ret;HRSRC			hrsrc = NULL ;DWORD           dwsize = 0;HGLOBAL	        hglobal = NULL;LPCVOID         pvdata = NULL;	hrsrc = FindResource( myEngine->hInstance, ResourceID , "RT_RCDATA");	if (hrsrc)	{        // Get the size        dwsize = SizeofResource( myEngine->hInstance, hrsrc );        // Load it        hglobal = LoadResource( myEngine->hInstance, hrsrc );        // Lock it and get a pointer to the data        pvdata = LockResource( hglobal );		SafeRelease(g_pTexture);		SafeRelease(mySurFace);		// Create the texture        D3DXCreateTextureFromFileInMemory( m_pD3DDevice, pvdata, dwsize, &g_pTexture );        	// Unlock it        UnlockResource( hglobal );        // Free the memory        FreeResource( hglobal );        if ( g_pTexture )        {			g_pTexture->GetSurfaceLevel(0,&mySurFace);			if (mySurFace!=NULL)			{				mySurFace->GetDesc(&desc);								// Store Away real width and height				m_RealWidth = desc.Width;				m_RealHeight = desc.Height;			}		}	}}

edited to use source tag

Share this post

Share on other sites
Alright, let me check all this out.
EDIT: Removed question about DX memory leak debug output.
Also, is there any possible way at all to somehow release that memory that should have been released?
---------
Well, ok so I just made a mess.
So, lets see, im still learning how to use and set up Direct3D correctly so please bear with me. I ahve looked at the DirectX documentation about loading textures and surfaces from the project resources and all I was able to get that was helpful was info on what the params meant. Ok so im now using FAILED instead of my old error checking ways and im a little confused on the proper way to use MAKEINTRESOURCE (I get what it does but is the parameter supposed to be one of the resource IDs?). So, it might be easyer if I jsut ask this for now:
What is the proper way to use D3DXLoadSurfaceFromResource for loading a surface with the image being a .bmp that is in the project resources?

Thanks,
Progames25

[Edited by - Progames25 on January 14, 2009 8:02:21 PM]

Share this post

Share on other sites
Quote:
 Original post by Progames25...im a little confused on the proper way to use MAKEINTRESOURCE (I get what it does but is the parameter supposed to be one of the resource IDs?). So, it might be easyer if I jsut ask this for now:What is the proper way to use D3DXLoadSurfaceFromResource for loading a surface with the image being a .bmp that is in the project resources?
Yes, the parameter is a resource ID, like IDB_IMAGE1 in your case.

I've never used D3DXLoadSurfaceFromResource, so I can't comment on it's use. Personally, I stay away from the D3DXLoadSurfaceFrom* style functions, since you need to pre-create the surface, which seems a bit strange; you'd have to use D3DXGetImageInfoFrom* to get the image size and format, then use D3DXLoadSurfaceFrom*.

Share this post

Share on other sites
Ah, ok.
Well,
what would be the best way to make the surfaces and textures using images from my resources without using that?

The book I have (Beginning Game Programming Second edition by Jonathan S. Harbour uses that LoadFromFile style with the getimageinfo (and it does get a little anoying using all those), so I don't really know another way.

Thanks,
Progames25

Share this post

Share on other sites
Quote:
 Original post by Progames25Ah, ok.Well,what would be the best way to make the surfaces and textures using images from my resources without using that?The book I have (Beginning Game Programming Second edition by Jonathan S. Harbour uses that LoadFromFile style with the getimageinfo (and it does get a little anoying using all those), so I don't really know another way.Thanks,Progames25
If you need a surface, there doesn't appear to be any way. If you need a texture however, there's D3DXCreateTextureFrom*() functions.

Share this post

Share on other sites
Alright, ill try using that one and see what happenes after I fix up some stuff.

Thanks,
Progames25

Share this post

Share on other sites

• Advertisement
• Advertisement
• Popular Tags

• Advertisement
• Popular Now

• 30
• 11
• 17
• 11
• 13
• Advertisement