Archived

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

Problem with CopyRects function of DirectX 8

This topic is 5847 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 reading the book The Zen of Direct3d Game Programming I am up to the part where they make a class for sprites. The class sprite has an initialization file which takes the sprite from a bitmap and puts it into a surface. It uses the CopyRects function. However, this has caused a problem. The problem somehow is related to the format of the 2 surfaces. The format has to be the same and the format in my 2 surfaces is not. How would I make the 2 formats the same? Here is how I called the CopyRects function: r = g_pDevice->CopyRects( m_pSpriteSurface, &SpriteRect, 1, m_pActiveSurface, &SpritePoint ); if (FAILED(r)) { SetError("Ah, the problem remains copying rects"); return E_FAIL; }

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
load the bitmap into memory, then convert each pixel to the correct format, then place onto the surface.

Or, much easier, and faster - find the format of the bitmap, then create a surface using that format, and to the correct size. Load bitmap to surface.

Share this post


Link to post
Share on other sites
Ok, I am not sure how to do that.

How do I find the format of the bitmap and then create a surface using that format?

This is what I have now, but it doesn't work

r = LoadBitmapToSurface( strPathName, &m_pSpriteSurface, g_pDevice );

// in the LoadBitmapToSurface function, I have this line
g_result = pDevice->CreateImageSurface(Bitmap.bmWidth, Bitmap.bmHeight,D3DFMT_X8R8G8B8, ppSurface);

// then right after i call the LoadBitmapToSurface function I have
// this line:
r = g_pDevice->CreateImageSurface( m_SpriteWidth, m_SpriteHeight, D3DFMT_A8R8G8B8, &m_pActiveSurface );

//and finally the CopyRects function call that was above.

What is wrong?

Edited by - GameDev135 on December 9, 2001 7:50:57 PM

Share this post


Link to post
Share on other sites
first off, load your bitmaps using real bitmap code you make. (its easy format wotsit.org has the specs). basically you read the header (BITMAPINFOHEADER) into the struct. check the struct for the format and size of the bitmap, then load the bitmap data which is right after the header (make sure you remeber that each scanline is DWORD aligned). when readin the bitmap and putting it onto the surface you convert the pixels you read into the pixel format of the surface you are writing to.

also side note D3DFMT_X8R8G8B8 != D3DFMT_A8R8G8B8. dx may allow it since they are the same pixel size, but more then likly dx wont since they are technically different (in one the alpha channel is ignored).

why do you need to use copyrects? i assume for bliting sprites to the back buffer. if so use dx7 (where you will have the same problem but at least dx7 with directdraw is meant for 2d stuff). or use textured quads (in which case you wont need to convert the format of the bmp just select the texture and draw the quad. see tutorials on this here at gamedev and on the net.

Share this post


Link to post
Share on other sites