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

## 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 on other sites
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 on other sites
Moving to the DX forum.

##### 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 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 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 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 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 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 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*.

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• ### Forum Statistics

• Total Topics
632906
• Total Posts
3009155
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!