c++ - StretchBlt only works when nHeightDest is negative -
i'm trying use stretchblt in order copy pixels memory hdc window hdc.
memory hdc gets image invisible window renders stream using opengl.
here's code:
bitmapinfoheader createbitmapheader(int width, int height) { bitmapinfoheader header; header.bisize = sizeof(bitmapinfoheader); header.biwidth = width; header.biheight = height; header.biplanes = 1; header.bibitcount = 32; header.bicompression = bi_rgb; header.bisizeimage = 0; header.bixpelspermeter = 0; header.biypelspermeter = 0; header.biclrused = 0; header.biclrimportant = 0; return header; } ... hdc memoryhdc = createcompatibledc(windowhdc); bitmapinfo bitmapinfo; bitmapinfo.bmiheader = createbitmapheader(targetdimensions.width, targetdimensions.height); hbitmap bitmap = createdibitmap(windowhdc, &bitmapinfo.bmiheader, cbm_init, offscreenbuffer, &bitmapinfo, dib_rgb_colors); selectobject(memoryhdc, bitmap); deleteobject(bitmap); setstretchbltmode(windowhdc, coloroncolor); stretchblt(windowhdc, targetdimensions.x, targetdimensions.y, targetdimensions.width, -targetdimensions.height, memoryhdc, sourcedimensions.x, sourcedimensions.y, sourcedimensions.width, sourcedimensions.height, srccopy); deletedc(memoryhdc);
where windowhdc
hdc of window want stretchblt
copy pixels to, , offscreenbuffer
void*
pixels copied offscreen window in opengl rendering.
this code works great, except image upside down , want vertically flipped.
know happens because:
if nheightsrc , nheightdest have different signs, function creates mirror image of bitmap along y-axis
but when remove minus sign , both target , source heights same see no image in window.
check, tried put minus on sourcedimensions.height
results in no image, , same if try negate widths (both target , source).
any idea why?
thanks.
Comments
Post a Comment