Jump to content
  • Advertisement
Sign in to follow this  
Progames25

D3DXLoadSurfaceFromResource

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


Link to 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


Link to 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


Link to 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


Link to 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


Link to 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


Link to 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


Link to 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


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!