NO

Author Topic: BitBlt  (Read 5265 times)

Online HellOfMice

  • Member
  • *
  • Posts: 105
  • Never be pleased, always improve
BitBlt
« on: January 29, 2023, 05:46:50 PM »
I would like to make sprites using BitBlt. I join a program to see the problem I have.

I have  read this : https://social.msdn.microsoft.com/Forums/vstudio/en-US/3ff67e63-3ea3-4235-8763-94f7ef3c7b9c/windows-api-understanding-srcinvert-in-the-bitblt-function?forum=windowsgeneraldevelopmentissues
But No Good result!

I would like some help.

My program is at: https://www.mediafire.com/file/aj0eykop4e3r2ab/Navette.7z/file

Thank you for your help.
« Last Edit: January 29, 2023, 06:01:15 PM by HellOfMice »
--------------------------------
Kenavo

Online HellOfMice

  • Member
  • *
  • Posts: 105
  • Never be pleased, always improve
Re: BitBlt
« Reply #1 on: January 30, 2023, 06:45:19 AM »
Now it is OK
Here is the result
I remove the files from Mediafire

How I did?

Code: [Select]
HBITMAP CreateBitmapMask(HWND __hWnd,HBITMAP __hBmpObject,HBITMAP __hBmpMask,LPBITMAP __lpBitmap)
{
HDC _hDC, _hDCObject, _hDCMask, _hDCNewMask ;
HBITMAP _hBmpObjectOld, _hBmpMaskOld, _hBmpNewMask, _hBmpNewMaskOld ;

_hBmpNewMask = NULL ;

GetObject(__hBmpObject,sizeof(BITMAP),__lpBitmap) ;

_hDC = GetDC(__hWnd) ;
if(_hDC)
{
_hDCObject = CreateCompatibleDC(_hDC) ;
if(_hDCObject)
{
_hDCMask = CreateCompatibleDC(_hDC) ;
if(_hDCMask)
{
_hDCNewMask = CreateCompatibleDC(_hDC) ;
if(_hDCNewMask)
{
_hBmpNewMask = CreateCompatibleBitmap(_hDC,__lpBitmap->bmWidth,__lpBitmap->bmHeight) ;
if(_hBmpNewMask)
{
_hBmpNewMaskOld = SelectObject(_hDCNewMask,_hBmpNewMask) ;
if(_hBmpNewMaskOld)
{
_hBmpMaskOld = SelectObject(_hDCMask,__hBmpMask) ;
if(_hBmpMaskOld)
{
_hBmpObjectOld = SelectObject(_hDCObject,__hBmpObject) ;
if(_hBmpObjectOld)
{
SetTextColor(_hDCObject,0x00FF00) ;

BitBlt(_hDCNewMask,0,0,__lpBitmap->bmWidth,__lpBitmap->bmHeight,_hDCMask,0,0,SRCCOPY) ;
BitBlt(_hDCNewMask,0,0,__lpBitmap->bmWidth,__lpBitmap->bmHeight,_hDCObject,0,0,SRCINVERT) ;

SelectObject(_hDCObject,_hBmpObjectOld) ;
}

SelectObject(_hDCMask,_hBmpMaskOld) ;
}

SelectObject(_hDCNewMask,_hBmpNewMaskOld) ;
}
}

DeleteDC(_hDCNewMask) ;
}

DeleteDC(_hDCMask) ;
}

DeleteDC(_hDCObject) ;
}

ReleaseDC(__hWnd,_hDC) ;
}

return (_hBmpNewMask) ;
}

First I create the mask.
The mask is green and black
I want to keep the black part.

Code: [Select]
static void Navette_OnPaint(HWND __hWnd)
{
PAINTSTRUCT _Ps ;
RECT _Rc ;
BITMAP _Bitmap ;
HDC _hDC, _hDCMem, _hDCMask, _hDCBackground ;
HBITMAP _hBitmap, _hBitmapOld, _hBmpBgOld, _hBmpMask, _hBmpMaskOld ;
DWORD _dwNewWidth, _dwNewHeight ;

_hDC = BeginPaint(__hWnd,&_Ps) ;
if(_hDC)
{
_hDCMem = CreateCompatibleDC(_hDC) ;
if(_hDCMem)
{
_hDCBackground = CreateCompatibleDC(_hDC) ;
if(_hDCBackground)
{
_hBmpBgOld = SelectObject(_hDCBackground,lpBackground->hImgBitmap) ;
if(_hBmpBgOld)
{
_hBmpMask = CreateBitmapMask(__hWnd,lpNavette->hImgBitmap,lpNavette_Mask->hImgBitmap,&_Bitmap) ;
if(_hBmpMask)
{
_hDCMask = CreateCompatibleDC(_hDC) ;
if(_hDCMask)
{
_hBmpMaskOld = SelectObject(_hDCMask,_hBmpMask) ;
if(_hBmpMaskOld)
{
GetClientRect(__hWnd,&_Rc) ;

_hBitmap = CreateCompatibleBitmap(_hDC,_Rc.right,_Rc.bottom) ;
if(_hBitmap)
{
_hBitmapOld = SelectObject(_hDCMem,_hBitmap) ;
if(_hBitmapOld)
{
ImageResize(lpBackground->BitmapInfo.bmiHeader.bV5Width,lpBackground->BitmapInfo.bmiHeader.bV5Height,_Rc.right,_Rc.bottom,&_dwNewWidth,&_dwNewHeight) ;

SetStretchBltMode(_hDC,COLORONCOLOR) ;
SetStretchBltMode(_hDCMem,COLORONCOLOR) ;
BitBlt(_hDCBackground,100,100,_Bitmap.bmWidth,_Bitmap.bmHeight,_hDCMask,0,0,SRCPAINT) ;
StretchBlt(_hDCMem,0,0,_dwNewWidth,_dwNewHeight,_hDCBackground,0,0,lpBackground->BitmapInfo.bmiHeader.bV5Width,lpBackground->BitmapInfo.bmiHeader.bV5Height,SRCCOPY) ;
BitBlt(_hDC,(_Rc.right - _dwNewWidth) / 2,(_Rc.bottom - _dwNewHeight) / 2,_dwNewWidth,_dwNewHeight,_hDCMem,0,0,SRCCOPY) ;

SelectObject(_hDCMem,_hBitmapOld) ;
}

DeleteObject(_hBitmap) ;
}

SelectObject(_hDCMask,_hBmpMaskOld) ;
}

DeleteDC(_hDCMask) ;
}

DeleteObject(_hBmpMask) ;
}

SelectObject(_hDCBackground,_hBmpBgOld) ;
}

DeleteDC(_hDCBackground) ;
}

DeleteDC(_hDCMem) ;
}

EndPaint(__hWnd,&_Ps) ;
}

return ;
}

The problem is that americans painted some part of the shuttle in black.
If they used RED I would have not any problem.
« Last Edit: January 30, 2023, 06:48:18 AM by HellOfMice »
--------------------------------
Kenavo

Online HellOfMice

  • Member
  • *
  • Posts: 105
  • Never be pleased, always improve
Re: BitBlt
« Reply #2 on: January 30, 2023, 09:25:07 AM »
All the sources for the Navette program are at : https://www.mediafire.com/file/ef38r19ythcesog/Navette.7z/file


Now the shuttle is moving.


Is someone asked me the goal of this program, it is for making the shuttle to advance...
--------------------------------
Kenavo

Offline John Z

  • Member
  • *
  • Posts: 860
Re: BitBlt
« Reply #3 on: January 30, 2023, 10:24:42 AM »
Hi Hello...

"If they used RED I would have not any problem."  :)

Got it I'll try for warp speed.  Congratulations on figuring it out too.
Will be interesting to see the code in action.


John Z

P.S. Why does the program name keep changing  ;D ;D ;D

P.P.S.  Have suggested in the past Pelles Forum raise the upload size limit a bit, 1Meg is fairly small these days.

Update:  Very cool.  Not a barn burner but like to see it moving across the sky !
Update2:  Be sure to run it full screen... in a tiny window the shuttle does not traverse the entire picture, in full screen it does  :)
« Last Edit: January 30, 2023, 01:15:29 PM by John Z »

Online HellOfMice

  • Member
  • *
  • Posts: 105
  • Never be pleased, always improve
Re: BitBlt
« Reply #4 on: January 30, 2023, 02:18:23 PM »
It is moving but very slowly I look at why and search something to do.
The name of the program change because I want to keep the previous like it is and set the improvments on the other.
It's like a backup. It is a first idea now I see what I can do more


I have an idea for the shuttle color: White with a red point!


1 Mb must be enough for writing a pgm on a casio...
Perhaps the admin does use the forum...
--------------------------------
Kenavo

Online HellOfMice

  • Member
  • *
  • Posts: 105
  • Never be pleased, always improve
Re: BitBlt
« Reply #5 on: February 02, 2023, 07:59:54 AM »
I have updated the navette program.
Download it at : https://www.mediafire.com/file/2usflf1nvremjy7/Navette.7z/file

--------------------------------
Kenavo

Offline John Z

  • Member
  • *
  • Posts: 860
Re: BitBlt
« Reply #6 on: February 02, 2023, 12:22:44 PM »
Significant speed up!!
Also non-full screen traverses the window now :)
Well done.

John Z