Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem with copy data

Started by thuong Jun 12, 2006 at 5:07 AM 2 replies 450+ views
Original Post
thuong
thuong
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???
Evil Steve
Evil Steve
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;
Endurion
Endurion
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.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
thuong
thuong
thanks very much

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.