Skip to main content
gamedev.net
🔒 Locked

Loading Resource

Started by jmhill2 Aug 8, 2003 at 2:09 AM 5 replies 650+ views
Original Post
jmhill2
jmhill2
hey guys yet another question, I''m trying to write a function that reads a file or resource bitmap and copies it to an image surface, i have the file part working, but i''m having trouble getting the resource file part to load. I''m using the D3DX functions. I not sure how to refer to the resource and also how to i get the dimensions of the resource, thanks: int cSurface::CreateImageSurface(char * filename, cDirectX * directX, int location) { HRESULT result; fstream BitmapInfo; BitmapInfo.open (filename, ios::binary | ios::in); if (BitmapInfo.is_open ()) { /* Ignore 18 bytes */ <---only works for file mode BitmapInfo.seekg (18, ios::cur); /* Get width and height of bitmap */ BitmapInfo.read ((char *)&Width, sizeof (int)); BitmapInfo.read ((char *)&Height, sizeof (int)); } result = directX->g_pd3dDevice->CreateOffscreenPlainSurface(Width, Height, directX->d3dpp.BackBufferFormat, D3DPOOL_DEFAULT,&Surface,NULL); if(FAILED(result)) return 0; if(location) /*load from file*/ result = D3DXLoadSurfaceFromFile(Surface, NULL, NULL, filename, NULL,D3DX_DEFAULT,0,NULL); else /*load from resource*/ result = D3DXLoadSurfaceFromResource <--- not working (Surface,NULL,NULL,NULL,filename,NULL,D3DX_DEFAULT,0,NULL); if(FAILED(result)) return 0; return 1; }
"Genius is rare because the means of becoming one has not been made commonly available."
Pipo DeClown
Pipo DeClown
You should learn more about resources. This is not a DirectX problem..

Resources are not loaded by their filenames, they have IDs. Check some tutorials about loading resources. (theForgers tutorials are great)

.lick
KurtCPP
KurtCPP
Hi buddy, here''s your savior.
You gotta use LoadSomethinfFromResourceEx(..) with the parameters you''d have used with ...FromFileEx().
Check DXSDK help files for the list of params and know that instead of the name of the file/resource you''ll have to write MAKEINTRESOURCE(IDR_MYRESOURCE). MAKEINTRESOURCE is a macro you can also use in plain windows programmnig, I ve been loking for long before being able to understand how it works. One more thing though, amongst the params, you''ll be asked for a module handle. Since your program looks way simple, I think the module you use is the one normally given by Windows, so simply specify null for this.

//for example, this works

hr = D3DXLoadSurfaceFromResource(m_pBoardPattern,0,0,0,
MAKEINTRESOURCE(IDB_BACKGROUND),0,D3DX_DEFAULT,0,null);
//dont forget to search in the documentation to understand what each parameter is


Voila. Hope Ive been useful.

Prog, Hex & Rock''n''Roll :
I don''t like the Prog but the Prog likes me.
Some nice poetry to sweeten your spirit and relax a bit before programming
Prog, Games & Rock'n'Roll :I don't like the Prog but the Prog likes me.
jmhill2
jmhill2
i tried using the makeintresource file but the compiler is not finding my resource IMG_BITMAP, which is defined in my *.rc file like this: IMG_BITMAP BITMAP image_black.bmp


result = D3DXLoadSurfaceFromResource(Surface,NULL,NULL,NULL,MAKEINTRESOURCE(IMG_BITMAP),NULL,D3DX_DEFAULT,0,NULL);

When I compile I see that the executable is larger, but how come the makeintresource does not find it???? thanks.
"Genius is rare because the means of becoming one has not been made commonly available."
jmhill2
jmhill2
shameless bump
"Genius is rare because the means of becoming one has not been made commonly available."
Maega
Maega
Is your IMG_BITMAP defined somewhere differently?

MAKEINTRESOURCE = Make integer from resource id.

It doesn''t work real well when your ID is defined with a different number.

ie if your IMG_BITMAP is 101 in your resource file, and it''s defined as 102 in your resource.h, it''s not going to load

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.