Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quick surface question

Started by REspawn Aug 8, 2007 at 5:11 PM 0 replies 650+ views
Original Post
REspawn
REspawn
Hi, im currently saving a surface to a file, opening it, skipping past the headers (128 bytes) and reading in the rest of the file to save it to a stream. Was wondering if anyone knew a better / faster way than having to go through the trouble of using an external file. I posted the code below for anyone needing a clearer picture of what im at, thanks for any help, -Dave

IDirect3DSurface9 *surface;
ifstream fileStream;
char *chunk;
long chunkSize = 0;

texture->GetSurfaceLevel(0, &surface);
D3DXSaveSurfaceToFile(L"temp.tmp", D3DXIFF_DDS, surface, NULL, NULL);
	
fileStream.open("temp.tmp", std::ios::binary);
		
chunkSize = fileLength(fileStream) - 128;
chunk = new char[chunkSize];
fileStream.ignore(128);
fileStream.read(chunk, chunkSize);
		
writeBinary(outputStream, chunkSize);
outputStream.write(chunk, chunkSize);

fileStream.close();
delete [] chunk;

surface->Release();

S1CA
S1CA
From the description and code I'm still not entirely sure what you're trying to achieve.

If you want to save the raw image data from the surface, you could:

1. IDirect3DSurface9::LockRect() to get at the raw pixels in the surface then copy that to the destination ('stream'?). You'll need to make a copy function that's aware of things like surface pitch and the sizes of different pixel formats, but it's really not that difficult.

Or

2. Do what you're currently doing but use D3DXSaveSurfaceToFileInMemory() to save the intermediate surface to memory rather than an external file. The destination ID3DXBuffer is just like your allocated 'chunk' array.


An aside: "new char[]". It just happens to work on PC, but it's wrong, it should be "new unsigned char[]".
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Topic Locked

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

Sign in to reply to this topic.