The fastest way to draw 2D via directly setting pixel values?

  • Thread starter Thread starter alikim
  • Start date Start date
A

alikim

Guest
Below is an example of the code I use in my Win32 project:



HBITMAP _hbDIB;
uc *_bitDIB;
HDC _hdc, _hdcMem;
HWND _cWnd;


...


void SetDIB(HWND hwnd, int width, int height, unsigned char **p, HBITMAP *hBmp)
{
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
bmi.bmiColors[0].rgbBlue = 0;
bmi.bmiColors[0].rgbGreen = 0;
bmi.bmiColors[0].rgbRed = 0;
bmi.bmiColors[0].rgbReserved = 0;

HDC hdc = GetDC(hwnd);
*hBmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)p, NULL, 0);
ReleaseDC(hwnd, hdc);
}


...


void Draw()
{

ui xp, yp;

while(cond) {
xp = RND;
yp = RND;

for(ui i = 0; i < 200; i++)
for(ui j = 0; j < 250; j++)
*((int*)_bitDIB + (xp+i) + (yp+j) * CWW) = 0x00FF0000 + 0x00000001 * j + 0x00000100 * i;

BitBlt(_hdc, 0, 0, CWW, CWH, _hdcMem, 0, 0, SRCCOPY);
}
}


// main


_cWnd = CreateWindow(...);


...

SetDIB(_cWnd, CWW, CWH, &_bitDIB, &_hbDIB);

_hdc = GetDC(_cWnd);
_hdcMem = CreateCompatibleDC(_hdc);
SelectObject(_hdcMem, _hbDIB);

CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Draw, NULL, 0, NULL);




My questions are:

1. Is this the fastest way to draw 2D via directly setting pixel values?

2. Does it use a built-in Intel Graphics chip or my actual video card?

3. If it doesn't use the video card, how can I draw using it ( I have NVIDIA)?


Thank you!

Continue reading...
 
Back
Top