Archived

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

Creating a texture from the screen shot

This topic is 5596 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'm trying to make a texture based on my screenshot, this is my code
//creating texture and surface

hr=D3DXCreateTexture(m_p2DApp->m_pd3dDevice,800,600,0,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&m_pTextureBG);
m_p2DApp->m_pd3dDevice->CreateImageSurface(800, 600, D3DFMT_A8R8G8B8, &frontbuf);

//get the front buffer
hr = m_p2DApp->m_pd3dDevice->GetFrontBuffer(frontbuf);

//lock the texture and surface
D3DLOCKED_RECT lockedrect1;
D3DLOCKED_RECT lockedrect2;
RECT rect;
rect.top=0;rect.left=0;rect.bottom=600;rect.right=800;
ZeroMemory(&lockedrect1,sizeof(lockedrect1));
ZeroMemory(&lockedrect2,sizeof(lockedrect2));
hr= m_pTextureBG->LockRect(0,&lockedrect1,&rect,0);
hr= frontbuf->LockRect(&lockedrect2,&rect,D3DLOCK_READONLY);

//copy rectangle from surface to texture
unsigned char *pSurfBits1=static_cast(lockedrect1.pBits);
unsigned char *pSurfBits2=static_cast(lockedrect2.pBits);
memcpy(pSurfBits1,pSurfBits2,800*600);

m_pTextureBG->UnlockRect(0);
frontbuf->UnlockRect();
 
this doesn't work !! my texture is nothing but a blank texture, I've tried to save the surface using D3DXSaveSurfaceToFile and the result is fine so nothing wrong with the surface Can somebody help me ?? [edited by - yanuart on August 17, 2002 12:30:25 AM]

Share this post


Link to post
Share on other sites
A much more efficient way to do this is to render to a texture. There are plenty of good tutorials on that, so I won''t go into it here.

Oh, and your memcpy will fail if your bpp is greater than 8. Which it probably is.



Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites