Jump to content
  • Advertisement
Sign in to follow this  
thuong

problem with copy data

This topic is 4422 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 All, i have problem with copy data i have backbuffer format: D3DFMT_R5G6B5: 16-bit RGB pixel format with 5 bits for red, 6 bits for green, and 5 bits for blue. following is my code: LPDIRECT3DSURFACE9 pRenderTarget = NULL; m_pDevice->GetRenderTarget(0, &pRenderTarget); m_pDevice->GetRenderTargetData(pRenderTarget, pTemp); // Lock surface D3DLOCKED_RECT lockedRect; pTemp->LockRect(&lockedRect, NULL, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK) D3DSURFACE_DESC textureDesc; pTemp->GetDesc(&textureDesc); // reverse the buffer int iPitch = lockedRect.Pitch; BYTE *pData = (BYTE*)lockedRect.pBits + (iPitch * (textureDesc.Height - 1)); BYTE *pDestData = m_pMyBuffer; (init with : width * height * 4) for (int i = 0; i < textureDesc.Height; i ++) { int iDestIndex = 0; int iSourceIndex = 0; for (int j = 0;j < textureDesc.Width;j++) { int iPixel = pData[iSourceIndex++]; int iHi = pData[iSourceIndex++]; iHi = iHi << 8; iPixel = iPixel | iHi; int iBlue = iPixel & 0x1F; // 5 bit for blue int iGreen = (iPixel >> 5) & 0x3F; // 6 bit for green int iRed = (iPixel >> 11) & 0x1F; / 5 biet for red pDestData [iDestIndex++] = iBlue; pDestData [iDestIndex++] = iGreen; pDestData [iDestIndex++] = iRed; pDestData [iDestIndex++] = 0xFF; } pDestData += iPitch * 3 / 2; } pData -= iPitch; } when i display this buffer(m_pMyBuffer) then incorrect. my code is not work ok, but i can not see anything error, pls anybody help me???

Share this post


Link to post
Share on other sites
Advertisement
Are you using the debug runtimes with the debug output set to maximum? Is there any debug output? Do you check that all of the D3D calls succeed? Did you create the device with the D3DCREATE_LOCKABLE_BACKBUFFER (or whatever it is) flag?
What do you mean it "doesn't look right"? Any chance of a screenshot?
I'm not sure what this is supposed to do, but it doesn't look right:
pDestData += iPitch * 3 / 2;

Share this post


Link to post
Share on other sites
Since you created your destdata with width*height*4 you can use width * 4 safely. You should not use the sources' pitch for your destination data since they are in no way related.

Change the line:

pDestData += iPitch * 3 / 2;

to:

pDestData += width * 4;

or:

pDestData += textureDesc.Width * 4;

depending on how you want the target data arranged.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!