PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Drawing on a Surface

Hi everyone, I´m doing a arena-style game and I want to draw the corpses and blood and stuff right on the background surface, so I dont need to redraw everything everytime.. I created a simple function to do this thru surface´s DC´s but it damn slow :cry:
if anyone have any other Idea(faster than this one) it would be greatly appreciated.


thanks, and here is my code:

Code:

void RotateSample::DrawOnSurface(int destx, int desty,Surface* &dest, Surface* source)
{ dest->Unlock(false);
HDC HDC1;
HDC HDC2;

int sw = source->GetWidth();
int sh = source->GetHeight();

HDC1 = dest->GetDC(false);
HDC2 = source->GetDC(false);

TransparentImage(HDC1,destx,desty,sw,sh,HDC2,0,0,sw,sh, RGB(255,0,255));

dest->ReleaseDC(HDC1); //as you can imagine, here occurs the slow down, where the changes are made
source->ReleaseDC(HDC2);
}
Use a...
Code:
Rasterizer* DisplayDevice::CreateRasterizer( Surface* target )
...function to create Rasterizer with custom target surface.

You can use blit functions with it and much more that rasterizer allows. In your case you just set up ColorMask for source surface and blit it.

P.S. Any drawings on canvas are dramatically decrease performance.

P.P.S. Thanks for the question. I'm going to realize double-buffered output to increase performance much more. :wink:
That´s some cool code ! :P
Too bad I already brainstormed here to create a function for my use..
for the sake of curiosity here it is( it is messy, if you want to use you´ll have to modify it for your purposes :lol: )

Code:

void RotateSample::DrawOnSurface(int destx, int desty, int color , bool background)
{

if (background )
{
Surface::LockInfo buffer;
Rect* rect;

m_background->Lock(buffer, false, 0 );


if (destx > 0 && destx < 240 && desty > 0 && desty < 319)
buffer.pixels[desty * 240 + destx] =color;

m_background->Unlock(false);
} else
{
Surface::LockInfo buffer;

display->GetBackBuffer()->Lock( buffer );

if (destx > 0 && destx < 240 && desty > 0 && desty < 319)
{
int dy = buffer.pitch >> 1;
buffer.pixels[desty * dy + destx] = color;
}

}

}


with this you can draw a pixels to the m_background surface, or you can draw a pixel directly to the display buffer
damn, when I posted I thought it was a little messy, but now after looking at it on the forum, it is much more messier! 8O

anyway, anyone who needs this kind of code will know how to adapt it for his own purposes
( but I doubt anyone will use it anyway )
xpfde · 25 Apr 2003, 12:32 UTC — How can I draw a image on a surface?
How can I draw a image on a surface?I am a new one,help me.thanks
xpfde · 29 Apr 2003, 09:43 UTC — How can I draw a image on a surface?
xpfde wrote:
How can I draw a image on a surface?I am a new one,help me.thanks

I Got It,Thanks