Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


D3DXLoadSurfaceFromMemory Help!!!

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

Hey guys, I can''t get D3DXLoadSurfaceFromMemory to work, What am I doing wrong? I know the rest of the code works, I''ve tested it with D3DXLoadSurfaceFromFile, with a BMP. The function reads a 24bit RGB value and puts it in memory for each pixel. The image data is 600 pixels wide by 8 pixels high.
void LoadRBDtoSurface(char *filename, LPDIRECT3DSURFACE8 *surface, LPDIRECT3DDEVICE8 D3DDevice,
					  int width, int height)
	ifstream fin;
	int i=0;
	RECT rect;
	rect.top = 0;
	rect.left = 0;
	rect.bottom = height;
	rect.right = width;

	BYTE red;
	BYTE green;
	BYTE blue;
	BYTE *ptr;
	D3DDevice->CreateImageSurface(width, height, D3DFMT_X8R8G8B8,surface);
	ptr = new BYTE[width*height*3];
	fin.open(filename, filebuf::binary);

		ptr[i] = red;
		ptr[i] = green;
		ptr[i] = blue;
	D3DXLoadSurfaceFromMemory(*surface, NULL, NULL, &ptr,D3DFMT_R8G8B8, 1800, NULL, &rect, D3DX_FILTER_NONE,0);
	delete [] ptr;
- master_ball ---------------------------- We R 138

Share this post

Link to post
Share on other sites
code looks fine... will you please post what kind of an error you are getting (no texture, distorted texture, crash, etc...) that would help to pinpoint it anyway. also, i am not certain, but shouldnt the fourth parameter of D3DXLoadSurfaceFromMemory be (VOID*)&ptr instead of &ptr ? Not a big deal anyway, probably just gives you a warning.

also, make sure your file is correctly loading (throw some text output in there with some counters to make sure you are getting the correct amount of data)... in fact you should check that you get all the data out of a loaded file (my old instructor would take this opporitunity to beat you black and blue with a VERY thick book on code robustness)

Brett Lynnes

Share this post

Link to post
Share on other sites
Thank you SO much for replying!!! What happens is that I clear the surface, get the back buffer, then do a copyrects from the surface in my function to the back buffer. After I release it, then present it. Like I said, it works fine with loading the same file from a bitmap.
I tried outputting the data to a file from the 'homemade' format to a file and they match perfectly. I'm guessing its something to do with that pointer. When I run the program, it crashes when I present the backbuffer after I copy the 'homemade' surface info to the backbuffer. Does it matter how the RGB info is stored in memory? Do you have to put it in memory backwards, as a bitmap is stored to a disk? Do you have to have a 2 dimensional memory to load from?

- master_ball

We R 138

[edited by - master_ball on September 14, 2002 3:53:39 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!