Jump to content
  • Advertisement

Archived

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

LongingForDeath

Copying Surfaces to Textures

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

Hi, I think it is better to post the code first:
HRESULT	CreateTextureFromSurface (LPCTSTR tszTextureFile)
{
	HRESULT	hr;
	D3DDISPLAYMODE		d3ddm;
	RECT				rc;
	D3DLOCKED_RECT		d3dRect;
	BYTE*				pbyImage = NULL;
	D3DSURFACE_DESC		d3dDesc;
	IDirect3DSurface8*	pSurface = NULL;

	g_pD3D->GetAdapterDisplayMode (D3DADAPTER_DEFAULT, &d3ddm);
	hr = pDevice->CreateImageSurface (1024, 768, d3ddm.Format, &pSurface);
	if FAILED (hr)
	{
		MessageBox (NULL, "CreateImageSurface () failed!", "Error", MB_OK);
		return hr;
	}

	if FAILED (hr = g_pDevice->CreateTexture (256, 256, 1, 0, d3ddm.Format, D3DPOOL_MANAGED, &m_pBackgroundTexture))
	{
		MessageBox (NULL, "CreateTexture () failed!", "Error", MB_OK);
		pSurface->Release ();
		pSurface = NULL;
		return hr;
	}

	if FAILED (hr = D3DXLoadSurfaceFromFile (pSurface, NULL, NULL, tszTextureFile, NULL, D3DX_FILTER_LINEAR, 0, NULL))
	{
		MessageBox (NULL, "D3DXLoadSurfaceFromFile () failed!", "Error", MB_OK);
		pSurface->Release ();
		pSurface = NULL;
		return hr;
	}

	SetRect (&rc, 0, 0, 256, 256);
	pSurface->GetDesc (&d3dDesc);
	pbyImage = new BYTE[d3dDesc.Size];

	pSurface->LockRect (&d3dRect, &rc, D3DLOCK_READONLY);
	memcpy (pbyImage, d3dRect.pBits, d3dDesc.Size * sizeof (BYTE));
	pSurface->UnlockRect ();

	g_pBackgroundTexture->GetLevelDesc (0, &d3dDesc);

	g_pBackgroundTexture->LockRect (0, &d3dRect, NULL, 0);
	memcpy (d3dRect.pBits, pbyImage, d3dDesc.Size * sizeof (BYTE));
	g_pBackgroundTexture->UnlockRect (0);

	delete[] pbyImage;
	pSurface->Release ();
	pSurface = NULL;

	return S_OK;
}

 
With that method the bitmap won''t be displayed. But if I set the size of the surface to 256x256 there are no problems and the bitmap will be displayed. My question is: Why ? The bitmap has a size of 1024x768. I would copy 12 pieces of size 256x256 of the bitmap into 12 textures. But to do that I need a surface that fits the size of the bitmap. - LongingForDeath

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!