Optimizing GDI+ drawing?
- by user146780
I'm using C++ and GDI+
I'm going to be making a vector drawing application and want to use GDI+ for the drawing.
I'v created a simple test to get familiar with it:
case WM_PAINT:
GetCursorPos(&mouse);
GetClientRect(hWnd,&rct);
hdc = BeginPaint(hWnd, &ps);
MemDC = CreateCompatibleDC(hdc);
bmp = CreateCompatibleBitmap(hdc, 600, 600);
SelectObject(MemDC,bmp);
g = new Graphics(MemDC);
for(int i = 0; i < 1; ++i)
{
SolidBrush sb(Color(255,255,255));
g->FillRectangle(&sb,rct.top,rct.left,rct.right,rct.bottom);
}
for(int i = 0; i < 250; ++i)
{
pts[0].X = 0;
pts[0].Y = 0;
pts[1].X = 10 + mouse.x * i;
pts[1].Y = 0 + mouse.y * i;
pts[2].X = 10 * i + mouse.x;
pts[2].Y = 10 + mouse.y * i;
pts[3].X = 0 + mouse.x;
pts[3].Y = (rand() % 600) + mouse.y;
Point p1, p2;
p1.X = 0;
p1.Y = 0;
p2.X = 300;
p2.Y = 300;
g->FillPolygon(&b,pts,4);
}
BitBlt(hdc,0,0,900,900,MemDC,0,0,SRCCOPY);
EndPaint(hWnd, &ps);
DeleteObject(bmp);
g->ReleaseHDC(MemDC);
DeleteDC(MemDC);
delete g;
break;
I'm wondering if I'm doing it right, or if I have areas killing the cpu. Because right now it takes ~ 1sec to render this and I want to be able to have it redraw itself very quickly.
Thanks
In a real situation would it be better just to figure out the portion of the screen to redraw and only redraw the elements withing bounds of this?