Okay. So I made this code to draw a grid of rectangles to the screen
Code:
for(int i = 0; i < _x; ++i)
{
for(int j = 0; j < _y; ++j)
{
if(scr[_i][_j] != scr[i][j])
{
hBrush = ::CreateSolidBrush(scr[i][j]);
hPen = ::CreatePen(PS_SOLID, 1, scr[i][j]);
oldPen = (HPEN) ::SelectObject(hdc, hPen);
oldBrush = (HBRUSH) ::SelectObject(hdc, hBrush);
}
::Rectangle(hdc, i * width, j * height,
(i + 1) * width, (j + 1) * height);
if(scr[_i][_j] != scr[i][j])
{
::SelectObject(hdc, oldPen);
::SelectObject(hdc, oldBrush);
::DeleteObject(hPen);
::DeleteObject(hBrush);
}
_j = j;
_i = i;
}
}
Of course it's impractical, I'll try to manage a DIB instead of a grid like this later, but right now it's not working. The logic is that, if the pixel immediately previous to the one being drawn is the same color, then don't recreate the color and delete it again and just use the same things. It skips pixels when I do this though, and works fine if I comment out those if's. Is there any way to fix this?