Archived

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

Large bitmap into 256x256 texture

This topic is 5620 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 attempting to build a class capable of taking a large bitmap file (640x480, 800x600 or whatever) that will use 256x256 textures (supporting older cards) and few smaller one to render it using Directx8 - Several quads and setTexture steps will be used, of course. I know how to manage the quads, multiple textures and render states, but I hit a snag at load time: I don't know how to create a texture from -part- of a surface. With the following code I've managed to load the whole file in a surface and its descriptor tell me they're right. But the copyrect invariably fails on me. I've tried with POOL_MANAGED and SYSTEMMEM alike, with and without unlocking the rects. No success. I must be missing something very basic, I'd appreciate any help. Please keep in mind that I'd rather avoid DDraw from Directx7 and that splitting the file into several BMPs defeats my purpose: To make the file size independent from the device size.
    
// experiment in loading a large texture

	HRESULT hr;
	LPDIRECT3DSURFACE8	pFullSurface, pDestSurface;
	D3DXIMAGE_INFO		SurfInfo;
	// Create a useless surface since it can't be 'CreateSurfaceFromFile'd.

	// This func automatically puts it into SystemMem, so the size limit isn't here.

	Direct3D.GetDeviceInterface()->CreateImageSurface(1
		, 1, D3DFMT_A8R8G8B8
		, &pFullSurface); 
	hr=D3DXLoadSurfaceFromFile(pFullSurface
		, NULL //no palette

		, NULL //whole surface

		, "Xfile/640x480test.bmp"
		, NULL //whole source rect

		, D3DX_FILTER_POINT // could be D3DX_FILTER_LINEAR or D3DX_FILTER_DEFAULT

		, 0 // disable colorkey

		, &SurfInfo);
	
	// Create a 256x256 texture, with the surface's format.

	aTexture[4] = new CTexture();
	aTexture[4]->m_pDevice=Direct3D.GetDeviceInterface();
	hr= D3DXCreateTexture(Direct3D.GetDeviceInterface()
		, 1, 1, 1 // single mipmap, I don't need any other work done here.

		, 0 //not a render target

		, SurfInfo.Format, D3DPOOL_SYSTEMMEM // Tried with SystemMem too.

		, &aTexture[4]->m_pTexture);
	aTexture[4]->m_pTexture->GetSurfaceLevel(0,&pDestSurface);

	// Now we're ready to copy.

	RECT				rcSource[] = { 0, 0, 255, 255};
	POINT				ptDest[]   = { 0, 0};
	D3DLOCKED_RECT		FullSurfaceLockinfo, TexLockInfo;
	hr=pFullSurface->LockRect(&FullSurfaceLockinfo,
		NULL //Full surface lock, that way I may copy several rects from it

		D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE);
	hr=aTexture[4]->m_pTexture->LockRect(0 // Only necessary texture level

		, &TexLockInfo, NULL // Full texture lock

		, 0);// standard lock

	hr=Direct3D.GetDeviceInterface()->CopyRects( pFullSurface, rcSource
		, 1, pDestSurface, ptDest);
	hr=pFullSurface->UnlockRect();
	hr=aTexture[4]->m_pTexture->UnlockRect(0); // Tex level 0, only one.

    
=^.^= [edited by - Spacecat on July 26, 2002 11:53:04 AM] [edited by - Spacecat on July 26, 2002 12:08:00 PM]

Share this post


Link to post
Share on other sites
I would suggest the following:

1) Custom-load the entire 640x480 bitmap info into a system-memory buffer.
2) Copy 256x256 pixels of image data into a Surface.
3) Create the D3D texture with the Surface from #2.
4) Loop 2 & 3 until the entire 640x480 is ready to be rendered on-screen.



MatrixCubed
http://MatrixCubed.cjb.net

Share this post


Link to post
Share on other sites
quote:
Original post by MatrixCubed
I would suggest the following:

1) Custom-load the entire 640x480 bitmap info into a system-memory buffer.
2) Copy 256x256 pixels of image data into a Surface.
3) Create the D3D texture with the Surface from #2.
4) Loop 2 & 3 until the entire 640x480 is ready to be rendered on-screen.



Well, my code pretty much does that: The LoadSurfaceFromFile creates a surface / aka buffer with the whole file. No problem thus far.

Step 3 is my problem: The copyrect that -should- manage to copy from the surface just fails and I''ve no idea why. Using a 256x256 surface as intermediary is an idea, but I still have to use the copyrect since ''CreateTextureFromSurface'' does not exist.

If you could show me working DX8 code that fills a texture with surface data, I''d love it, it''s a just-above-basic thing I can''t seem to find anywhere.

Share this post


Link to post
Share on other sites