Skip to main content
gamedev.net
🔒 Locked

copyRects()

Started by musikit 3 replies 550+ views
Original Post
musikit
musikit
I''m having a problem with CopyRects. I have this code (below) which i got from a book (forget which). It works perfectly on my desktop computer running a Geforce3, however, on my laptop with a S3 Twister K it doesn''t seem to work for 640x480 mode, but works for 800x600 mode. After debugging the program i''ve tracked the problem down to the following call. hr = g_lpD3DDevice->CopyRects(pSurface, pSrcRect, 1,pTexSurface, &destPoint); which is returning an INVALIDCALL when i call it in 640x480 mode. the format for the screen is 16-bit R5G6B5 and the bitmap is 800x600 big in 32-bit X8R8G8B8 mode. any help is appreciated. thanks. //----------------------------------------------------------------------------- void CreateTextureFromSurface(LPDIRECT3DDEVICE8 g_lpD3DDevice,LPDIRECT3DSURFACE8 pSurface, RECT* pSrcRect, LPDIRECT3DTEXTURE8* ppTexture) { HRESULT hr = 0; int width = pSrcRect->right - pSrcRect->left; int height = pSrcRect->bottom - pSrcRect->top; D3DSURFACE_DESC surfDesc; pSurface->GetDesc(&surfDesc); hr = D3DXCreateTexture(g_lpD3DDevice, width, height,1, 0, surfDesc.Format, D3DPOOL_DEFAULT, ppTexture); // Retrieve the surface image of the texture. LPDIRECT3DSURFACE8 pTexSurface; LPDIRECT3DTEXTURE8 pTexture = *ppTexture; pTexture->GetLevelDesc(0, &surfDesc); pTexture->GetSurfaceLevel(0, &pTexSurface); // Create a clean surface to clear the texture with. LPDIRECT3DSURFACE8 pCleanSurface; D3DLOCKED_RECT lockRect; hr = g_lpD3DDevice->CreateImageSurface(surfDesc.Width, surfDesc.Height, surfDesc.Format, &pCleanSurface); hr = pCleanSurface->LockRect(&lockRect, NULL, 0); memset((BYTE*)lockRect.pBits, 0, surfDesc.Height * lockRect.Pitch); hr = pCleanSurface->UnlockRect(); hr = g_lpD3DDevice->CopyRects(pCleanSurface, NULL, 0,pTexSurface, NULL); pCleanSurface->Release(); // Copy the image to the texture. POINT destPoint = { 0, 0 }; hr = g_lpD3DDevice->CopyRects(pSurface, pSrcRect, 1, pTexSurface, &destPoint); pTexSurface->Release(); }
intransigent-seal
intransigent-seal
Where are you trying to copy to?

From the DirectX Docs,
Section: DirectX Graphics->Direct3D C/C++ Reference->Interfaces->IDirect3DDevice8->CopyRects

quote:
This method does not support stretch, color key, alpha blend, format conversion, or clipping of either source or destination rectangles. Note that this method will fail unless all the source rectangles and their corresponding destination rectangles are completely contained within the source and destination surfaces respectively. The format of the two surfaces must match, but they can have different dimensions.


John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
musikit
musikit
I''m trying to copy from the directx8surface which contains a bitmap to a directx8texture so i can display it using the d8xsprite class.

the surface formats are the same. i''m not trying to do color key or alpha blending. i''m just trying to copy from a surfacec to a texture.

thanks.
musikit
musikit
Ok, if someone could help me understand this i''d appreciate it.

after more debugging it seems to be turning out that when i use D3DXCreateTexture to create a texture 640x480 big, it''s getting dropped to a texture of 512x512 big. not being large enough for me bitmap. however when i ask for a texture 800x600 big it gives me a texture 1024x1024 big, ok with me. is there a way to ask it to always give you back a texture that is as least as big as the one i asked for, ie when i ask for a 640x480 it gives me a 1024x1024?

Am i missing something fundemental that i should be checking for in my code?

thxs.

intransigent-seal
intransigent-seal
You may know this already, but incase you don''t:
For almost all hardware, textures must be a power of two in width and height. They can be different powers of two (for example 16 x 32), but they must be powers of two.

I believe that D3DXCreateTexture attempts to resize the texture to be a power of two (so in theory, there shouldn''t be a problem). But I suggest you control it yourself by providing your own power-of-two sizes.

Hope that helps,

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.

Topic Locked

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

Sign in to reply to this topic.