Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Has anybody out there used the CopyRects in C# successfully?

 

Basically I have a bitmap that I have loaded onto a surface that contains about a dozen tiles, all 32 x 32 pixels. I then try to render the scene by looping through my map array (20 tiles by 15 tiles )which contains the numbers 1 through 12 to represent the tile at the location.

 

What I want to do, find the tile number (lets say 3) which will start (3 * 32 ) pixels into the tile bitmap for a length and height of 32 pixels. I want to copy that rectangle to the appropriate place on back buffer.

 

The C++ code that I am trying to convert looks like this:

 

RECT SrcTileRect;

POINT DstPoint;

SrcTileRect.left = TileNumber2SourceX(TileNumber, numTileCols, tileSize);

SrcTileRect.right = SrcTileRect.left + tileSize;

SrcTileRect.top = TileNumber2SourceY(TileNumber,

numTileCols, tileSize);

SrcTileRect.bottom = SrcTileRect.top + tileSize;

DstPoint.x = Column2X(DstCol, tileSize, numMapCols) + xOffset;

DstPoint.y = Row2Y(DstRow, tileSize) + yOffset;

HRESULT hResult = m_Direct3D.GetDevice()->

CopyRects(pTileSurface, &SrcTileRect,

1, pBackBuffer, &DstPoint);

return hResult;

 

My converted C# codes is as follows:

 

DxVBLibA.RECT srcTileRect = new DxVBLibA.RECT();
DxVBLibA.POINT dstPoint = new DxVBLibA.POINT();

srcTileRect.left = this.TileNumber2SourceX( tileNumber, numTileCols, tileSize );
srcTileRect.right = srcTileRect.left + tileSize;
srcTileRect.top = this.TileNumber2SourceY( tileNumber, numTileCols, tileSize );
srcTileRect.bottom = srcTileRect.top + tileSize;

dstPoint.x = this.Column2X( dstCol, tileSize, numMapCols ) + xOffset;
dstPoint.y = this.Row2Y( dstRow, tileSize ) + yOffset;

this.OurDirect3D.DeviceD3D.CopyRects( tileSurface, &srcTileRect,	1, backBuf, &dstPoint );

 

I have everything converted fine up until the 'copyrects' line and am having problems with the &SrcTileRect and &DstPoint parameters. Error is 'cannot convert from DxVBLibA.RECT* to 'System.IntPtr'.

 

Anybody have an example of something similiar? I have used the copyrects before when I wanted to copy the entire source to the desintation (the source tile rectangle and point are both passed as null).

 

Cheers,

Devoid

Edited by divil
  • *Experts*
Posted

You can try the following. If you want to use StructureToPtr, you'll have to allocate the memory for the IntPtr first.

 

GCHandle hSrc = GCHandle.Alloc(srcTileRect, GCHandleType.Pinned);

GCHandle hDest = GCHandle.Alloc(dstPoint, GCHandleType.Pinned);

this.OurDirect3D.DeviceD3D.CopyRects(tileSurface, hSrc.AddrOfPinnedObject(), 1, backBuf, hDest.AddrOfPinnedObject());

hSrc.Free();

hDest.Free();

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...