• Advertisement


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

Loading an image into a surface

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

I am trying to do something very simple: load an image into a surface, using DirectX8. I have used the function D3DXCreateTextureFromFile() successfully for my textures, but now I need to do the same thing for a surface. I thought of creating a texture, and then accessing its surface, but this seems ineficient. Below is what I have tried, but I get an error (see code comments) when calling D3DXLoadSurfaceFromFile. Some help would really be appreciated in debugging this.
HRESULT hr; // for DirectX return values

IDirect3DSurface8* pSurface = NULL; // Surface to hold height map

D3DXIMAGE_INFO imageInfo; // Information on the height map image

const char strFile[] = "heightmap.bmp";	// Image containing height map

// Find out the image's width and height

D3DXGetImageInfoFromFile( strFile, &imageInfo );

// Create a surface

hr = m_pd3dDevice->CreateImageSurface( imageInfo.Width, imageInfo.Height, D3DFMT_R8G8B8, &pSurface );
if( FAILED(hr) )
	return hr;

// Use D3DX to copy image data into surface

hr = D3DXLoadSurfaceFromFile( pSurface, NULL, NULL, strFile, NULL, 0, 0, &imageInfo );
if( FAILED(hr) )
	// The code fails here, with value D3DERR_INVALIDCALL

	// Also, if I try to pop up a MessageBox at this point, 

	// I get an Unhandled exception: Access Violation

	return hr;
The image being loaded (strFile) is valid, and accessible by the program. imageInfo.Width and imageInfo.Height were both 128 when I ran the code (these are the correct dimensions). Perhaps is CreateImageSurface() the wrong function call? I looked through the SDK documentation for ways of creating Surfaces, and that was the best function I could find. The remarks for this function said:
Image surfaces are place holders, they are surfaces that cannot be used in any Microsoft® Direct3D® operations except locking and IDirect3DDevice8::CopyRects.
These restrictions don't seem to be a problem, since all I want to do is load an image into it, and read its data. edit: tried to fix code formatting edit2: tried to fix code formatting again edit3: again edit4: giving up (WHAT IS HAPPENING TO THE CARRIAGE RETURNS?) Edited by - FrigidHelix on February 23, 2002 6:21:37 PM Edited by - FrigidHelix on February 23, 2002 6:22:55 PM Edited by - FrigidHelix on February 23, 2002 6:24:48 PM Edited by - FrigidHelix on February 23, 2002 6:25:57 PM

Share this post

Link to post
Share on other sites
but what if you were to do this?


then lock surface
get pitch


unlock surface

i did this, and it doesn''t seem to work.
any ideas?


Share this post

Link to post
Share on other sites

  • Advertisement