Jump to content
  • Advertisement

Archived

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

Green

Workaround for transparency with copyrect?

This topic is 5853 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

Hello all, Does anyone know of a way to get transparecy using copyrect or an equivalent? (I understand the function does not support this). I am trying to copy a few rectangles onto one surface. The surface is of a texture that was created with black as transparent and this transparency works beautifully. The transparency I am after is: When copying multiple rects to the one surface the rects overlap, and pieces are overwriten. Any ideas are appreciated. Many thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Hmm, now when I did ''2D in 3D'' I''d just use alpha tests to make sure some points never get rendered, then a second pass of the new texture in the same area just overwrites those pixels that ''pass'' the test.

But you''re working with surfaces. Might I ask what you are trying to accomplish? If you are working on the backbuffer (or almost) as in on a surface, you''d be better served by having several layers of sprites or geometry, even in 2D rather than mix and match bytes per se.

If you''re trying to mixup textures on the fly I''ll eat those words, of course. I''ll assume that latter case.

copyrect can''t do it, so you will have to write your own ''copyrect-with-color-key''. Thankfully the code to work with surfaces is relatively simple.

  
hr=pSurface->LockRect(&SourceLockInfo
, &rcSource //Full surface lock, that way I may copy several rects from it

, D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE);
assert(hr==S_OK);
hr=pDestSurface->LockRect(&DestLockInfo
, &rcDest //Full surface lock, that way I may copy several rects from it

, 0);
assert(hr==S_OK);

int StartX=0, StartY=0;

unsigned char* cSourceRow, *cDestRow;
cSourceRow = (unsigned char*)SourceLockInfo.pBits;
cDestRow = (unsigned char*)DestLockInfo.pBits;
for( int y = StartY; y < iTileHeight; ++y ) {
// Copy the current row pointer and do whatever

// you need to with the row bytes

//for (int x = StartX; x <= WidthX*iPixelWidth; ++x){

// Byte * width treatment

// cDestRow[x]=cSourceRow[x];

//}

// Full Row copy.

memcpy(cDestRow, cSourceRow, (iTileWidth)*iPixelWidth);
cSourceRow += SourceLockInfo.Pitch;
cDestRow += DestLockInfo.Pitch;
// Bump to the next row

}


This is an exerpt from a little proggy I''ve got hanging around. Just make sure you test your pixels before overwriting and you''re set, right?

Share this post


Link to post
Share on other sites
don''t use copyrects, textured quads will make your program much friendlier to graphics hardware.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!