1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
class Bitmap
{
public:
unsigned int Width =0;
unsigned int Height =0;
unsigned int *Pixels=NULL;
BITMAPINFO BitInfo;
Bitmap(unsigned int SizeWidth, unsigned int SizeHeight, COLORREF NewColor=RGB(0,0,0))
{
New(SizeWidth,SizeHeight,NewColor);
}
void New(unsigned int SizeWidth, unsigned int SizeHeight, COLORREF NewColor=RGB(0,0,0))
{
if(Pixels==NULL) free(Pixels);
Pixels = (unsigned int*) malloc(SizeWidth*SizeHeight*sizeof(unsigned int));
Width = SizeWidth;
Height = SizeHeight;
memset(Pixels,NewColor, sizeof(&Pixels));
BitInfo.bmiHeader.biSize = sizeof(BitInfo.bmiHeader);
BitInfo.bmiHeader.biWidth = Width;
BitInfo.bmiHeader.biHeight = -Height;
BitInfo.bmiHeader.biPlanes = 1;
BitInfo.bmiHeader.biBitCount = 32;
BitInfo.bmiHeader.biCompression = BI_RGB;
}
void Draw(HDC Destination, int PosX, int PosY)
{
StretchDIBits(Destination, PosX, PosY, Width, Height, 0,0, Width, Height,Pixels, &BitInfo,DIB_RGB_COLORS, SRCCOPY );
}
void SetPixel(int PosX, int PosY, COLORREF Color)
{
Pixels[PosY*Height + PosX] = Color;
}
COLORREF SetPixel(int PosX, int PosY)
{
return Pixels[PosY*Height + PosX];
}
void DrawLine3D(Position3D Origin, Position3D Destination, COLORREF Color)
{
std::vector<Position3D> GetLineDots = GetLinePoints(Origin, Destination);
for(unsigned int x=0; x<GetLineDots.size()-1; x++)
{
unsigned int PosX = GetLineDots[x].PosX;
unsigned int PosY = GetLineDots[x].PosY;
Pixels[PosY*Height + PosX] =(unsigned int) Color;
}
}
};
|