|
Post by Rod on Mar 26, 2023 3:27:13 GMT -5
The mask bmp must be a two colour bmp. SpriteCreator writes 24bit bmp, you need a two colour, 1bit bmp. Take the .bmp you have, load it into Paint or whatever tool you have and save as a two color bmp. Here are two bmps, a 24bit color image of the car and a 1bit black and white mask image. They work in your last complete program where I load the mask image as mask and get its handle hm. hm is used in the plgblt call. car and mask imageJob done I think, good new technique for animation.
|
|
|
Post by held12345 on Mar 26, 2023 4:47:36 GMT -5
Hello, when I do this, the car is no longer visible on the screen. something else needs to be done. auto11x.bmp is 1 bit. -----hm as ulong,_ 'mask bmp handle, null = not used hm is mask handle------ nomainwin
WindowWidth = 800 WindowHeight = 550
Open "msimg32.dll" for DLL as #m
graphicbox #1.g, 50,50,500,300
open "Blitter" for graphics_nf_nsb as #1 #1 "trapclose [quit]"
loadbmp "largebmp","sprites\large.bmp" loadbmp "sprite","sprites\auto11.bmp" loadbmp "mask","sprites\auto11x.bmp" hm=hbmp("mask")
#1.g "down"; #1.g "getbmp bmp 0 0 500 300"
scrDC=GetDC(hwnd(#1.g)) bufDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("bmp") oldBmp=SelectObject(bufDC,hBitmap) bakDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("largebmp") oldBmp=SelectObject(bakDC,hBitmap) carDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("sprite") oldBmp=SelectObject(carDC,hBitmap) STRUCT lpPoint,_ x1 as long,_ y1 as long,_ x2 as long,_ y2 as long,_ x3 as long,_ y3 as long
bmpWidth=128 bmpHeight=128 a=0 gosub [drehen]
timer 10, [keyCheck] wait
[quit] close#1 end
[keyCheck] if keyState(87) then dx=cos(aa) dy=sin(aa) x=x+dx*2 y=y+dy*2 gosub [drehen] end if
if keyState(83) then dx=cos(aa) dy=sin(aa) x=x-dx*2 y=y-dy*2 gosub [drehen] end if
if keyState(65) then a=a-5 gosub [drehen] end if
if keyState(68) then a=a+5 gosub [drehen] end if result=blit(bufDC,0,0,500,300,bakDC,0,0) calldll #gdi32, "PlgBlt",_ bufDC as ulong,_ 'device context of graphicbox lpPoint as struct,_ 'array of points carDC as ulong,_ 'memory DC 0 as long,_ 'ulx source 0 as long,_ 'uly source 128 as long,_ 'width source 128 as long,_ 'height source hm as ulong,_ 'mask bmp handle, null = not used hm is mask handle 0 as long,_ 'ulx mask 0 as long,_ 'uly mask re as long 'nonzero=success result=blit(scrDC,0,0,500,300,bufDC,0,0) wait [drehen] x1=-1*bmpWidth/2:y1=-1*bmpHeight/2 x2=1*bmpWidth/2:y2=-1*bmpHeight/2 x3=-1*bmpWidth/2:y3=1*bmpHeight/2 pi=acs(-1) cx=bmpWidth/2:cy=bmpHeight/2 r=1 aa=a*pi/180 c=cos(aa):s=sin(aa) lpPoint.x1.struct = int(cx+r*(c*x1-s*y1)+x) lpPoint.y1.struct = int(cy+r*(s*x1+c*y1)+y) lpPoint.x2.struct = int(cx+r*(c*x2-s*y2)+x) lpPoint.y2.struct = int(cy+r*(s*x2+c*y2)+y) lpPoint.x3.struct = int(cx+r*(c*x3-s*y3)+x) lpPoint.y3.struct = int(cy+r*(s*x3+c*y3)+y) return
function keyState(keycode) calldll #user32, "GetAsyncKeyState", _ keycode AS long, _ keyState AS long end function
Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As ulong,_ 'memory device context hObject As long,_ 'handle of object SelectObject As long 'returns previously selected object End Function
function blit(dDC,x,y,w,h,sDC,sx,sy) CallDll #gdi32, "BitBlt", _ dDC as ulong,_ 'The destination DC x as long,_ 'x location on destination y as long,_ 'y location on destination w as long,_ 'width to transfer h as long,_ 'height to transfer sDC as ulong,_ 'The source DC sx as long,_ 'x location in source sy as long,_ 'y location in source _SRCCOPY as ulong,_ 'The operation to be performed blit as long 'nonzero if successful end function
function TransparentBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSource, xSource, ySource, wSource, hSource, clrTransp) calldll #m, "TransparentBlt", _ hdcDest as ulong, _ 'handle to destination DC xDest as long, _ 'x-coord of destination upper-left corner yDest as long, _ 'y-coord of destination upper-left corner wDest as long, _ 'width of destination rectangle hDest as long, _ 'height of destination rectangle hdcSource as ulong, _ 'handle to source DC xSource as long, _ 'x-coord of source upper-left corner ySource as long, _ 'y-coord of source upper-left corner wSource as long, _ 'width of source rectangle hSource as long, _ 'height of source rectangle clrTransp as ulong, _ 'color to make transparent TransparentBlt as long end function
Attachments:
|
|
|
Post by held12345 on Mar 26, 2023 4:48:44 GMT -5
this is 1 bit greeting Attachments:
|
|
|
Post by Rod on Mar 26, 2023 8:16:19 GMT -5
When I use the most recent code you posted and the two bmps that I put in the .zip it works perfectly for me.
|
|
|
Post by Rod on Mar 26, 2023 8:27:15 GMT -5
Post both bmps you are trying to use, not as images because they will be converted but as links or as a .zip till I see what is wrong with the bmps you are using.
|
|
|
Post by held12345 on Mar 26, 2023 11:13:22 GMT -5
hello thanks for help. her is the zip with auto.bmp ans maskauto.bmp greeting Attachments:auto-maskauto.zip (1.2 KB)
|
|
|
Post by Rod on Mar 26, 2023 12:10:00 GMT -5
you have the mask inverted, the visible portion is white the invisible is black.
|
|
|
Post by held12345 on Mar 26, 2023 13:41:26 GMT -5
left and right don't work. Thanks. greeting Attachments:
|
|
|
Post by held12345 on Mar 26, 2023 13:49:34 GMT -5
invert and noinvert.
greeting
|
|
|
Post by tsh73 on Mar 26, 2023 14:22:45 GMT -5
Using your last code, auto1.bmp from "here is the auto1.bmp and large.bmp" post and maxkinvert.bmp from last post works for me.
|
|
|
Post by held12345 on Mar 26, 2023 16:59:46 GMT -5
hello thanks for help.
I have difficulties with the buffer . can you make it visible and rotate the sprite in there.
----------------------- bufDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("bmp") oldBmp=SelectObject(bufDC,hBitmap) ---------------------- I don't know if it's because of my inline graphics from the notebook. he appears very briefly and disappears again.
greeting
|
|
|
Post by Rod on Mar 27, 2023 11:16:04 GMT -5
The buffer is desirable because Windows does not let us choose when the screen is refreshed. By using a buffer you draw graphics at leisure uninterrupted by screen refreshes. Then when it is complete you flick the buffer to the screen so fast that Windows can't interfere. Then the screen image remains stable and unchanged until you next flick the buffer into view.
All this is tried and tested. If you start drawing directly to the screen and dispense with the buffer you will find your image gets torn and flashes in an ugly way.
So it is not the buffer that is at fault but perhaps you are not understanding when to flip, you only flip when the complete drawing is ready, background first to clear the buffer then the car image, only then flip the buffer to the screen.
If the car is disappearing it is because you are drawing the background to the screen or flipping the buffer when the background is drawn after the car.The drawing order is important.
So we need to see your code.
|
|
|
Post by held12345 on Mar 27, 2023 15:10:28 GMT -5
I can't find the error in the program. so I think it doesn't work with the buffer.
Thanks. greeting
nomainwin
WindowWidth = 800 WindowHeight = 550
Open "msimg32.dll" for DLL as #m
graphicbox #1.g, 50,50,500,300
open "Blitter" for graphics_nf_nsb as #1 #1 "trapclose [quit]"
loadbmp "largebmp","sprites\large.bmp" loadbmp "sprite","sprites\auto11.bmp" loadbmp "mask","sprites\maskautoinvert.bmp" hm=hbmp("mask")
#1.g "down"; #1.g "getbmp bmp 0 0 500 300"
scrDC=GetDC(hwnd(#1.g)) bufDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("bmp") oldBmp=SelectObject(bufDC,hBitmap) bakDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("largebmp") oldBmp=SelectObject(bakDC,hBitmap) carDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("sprite") oldBmp=SelectObject(carDC,hBitmap) STRUCT lpPoint,_ x1 as long,_ y1 as long,_ x2 as long,_ y2 as long,_ x3 as long,_ y3 as long
bmpWidth=128 bmpHeight=128 a=0 gosub [drehen]
timer 10, [keyCheck] wait
[quit] close#1 end
[keyCheck] if keyState(87) then dx=cos(aa) dy=sin(aa) x=x+dx*2 y=y+dy*2 gosub [drehen] end if
if keyState(83) then dx=cos(aa) dy=sin(aa) x=x-dx*2 y=y-dy*2 gosub [drehen] end if
if keyState(65) then a=a-5 gosub [drehen] end if
if keyState(68) then a=a+5 gosub [drehen] end if result=blit(bufDC,0,0,500,300,bakDC,0,0) calldll #gdi32, "PlgBlt",_ bufDC as ulong,_ 'device context of graphicbox lpPoint as struct,_ 'array of points carDC as ulong,_ 'memory DC 0 as long,_ 'ulx source 0 as long,_ 'uly source 128 as long,_ 'width source 128 as long,_ 'height source hm as ulong,_ 'mask bmp handle, null = not used hm is mask handle 0 as long,_ 'ulx mask 0 as long,_ 'uly mask re as long 'nonzero=success result=blit(scrDC,0,0,500,300,bufDC,0,0) wait [drehen] x1=-1*bmpWidth/2:y1=-1*bmpHeight/2 x2=1*bmpWidth/2:y2=-1*bmpHeight/2 x3=-1*bmpWidth/2:y3=1*bmpHeight/2 pi=acs(-1) cx=bmpWidth/2:cy=bmpHeight/2 r=1 aa=a*pi/180 c=cos(aa):s=sin(aa) lpPoint.x1.struct = int(cx+r*(c*x1-s*y1)+x) lpPoint.y1.struct = int(cy+r*(s*x1+c*y1)+y) lpPoint.x2.struct = int(cx+r*(c*x2-s*y2)+x) lpPoint.y2.struct = int(cy+r*(s*x2+c*y2)+y) lpPoint.x3.struct = int(cx+r*(c*x3-s*y3)+x) lpPoint.y3.struct = int(cy+r*(s*x3+c*y3)+y) return
function keyState(keycode) calldll #user32, "GetAsyncKeyState", _ keycode AS long, _ keyState AS long end function
Function GetDC(hWnd) CallDLL #gdi32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As ulong,_ 'memory device context hObject As long,_ 'handle of object SelectObject As long 'returns previously selected object End Function
function blit(dDC,x,y,w,h,sDC,sx,sy) CallDll #gdi32, "BitBlt", _ dDC as ulong,_ 'The destination DC x as long,_ 'x location on destination y as long,_ 'y location on destination w as long,_ 'width to transfer h as long,_ 'height to transfer sDC as ulong,_ 'The source DC sx as long,_ 'x location in source sy as long,_ 'y location in source _SRCCOPY as ulong,_ 'The operation to be performed blit as long 'nonzero if successful end function
Attachments:
|
|
|
Post by Rod on Mar 31, 2023 7:22:59 GMT -5
This was a really simple error, you were calling the wrong dll for getDC it should be user32 not gdi32. So please take more care copying code. This code shows the car and moves it about the screen and it can be rotated. Use the sprites I wrapped in a .zip if you are still having problems.
TransparentBlit function has been removed but I suspect that you will need it eventually for drawing text or other graphic manipulations. In any event they all coexist without issue and act on the DC whether it is a buffer or the screen.
nomainwin
WindowWidth = 800 WindowHeight = 550
Open "msimg32.dll" for DLL as #m
graphicbox #1.g, 50,50,500,300
open "Blitter" for graphics_nf_nsb as #1 #1 "trapclose [quit]"
loadbmp "largebmp","large.bmp" loadbmp "sprite","auto24bit.bmp" loadbmp "mask","mask1bit.bmp" hm=hbmp("mask")
#1.g "down"; #1.g "getbmp bmp 0 0 500 300"
scrDC=GetDC(hwnd(#1.g))
bufDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("bmp") oldBmp=SelectObject(bufDC,hBitmap)
bakDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("largebmp") oldBmp=SelectObject(bakDC,hBitmap)
carDC=CreateCompatibleDC(scrDC) hBitmap=hbmp("sprite") oldBmp=SelectObject(carDC,hBitmap)
STRUCT lpPoint,_ x1 as long,_ y1 as long,_ x2 as long,_ y2 as long,_ x3 as long,_ y3 as long
bmpWidth=128 bmpHeight=128 a=0 gosub [drehen]
timer 10, [keyCheck] wait
[quit] timer 0 close#1 end
[keyCheck] if keyState(87) then dx=cos(aa) dy=sin(aa) x=x+dx*2 y=y+dy*2 gosub [drehen] end if
if keyState(83) then dx=cos(aa) dy=sin(aa) x=x-dx*2 y=y-dy*2 gosub [drehen] end if
if keyState(65) then a=a-5 gosub [drehen] end if
if keyState(68) then a=a+5 gosub [drehen] end if
result=blit(bufDC,0,0,500,300,bakDC,0,0) calldll #gdi32, "PlgBlt",_ bufDC as ulong,_ 'device context of graphicbox lpPoint as struct,_ 'array of points carDC as ulong,_ 'memory DC 0 as long,_ 'ulx source 0 as long,_ 'uly source 128 as long,_ 'width source 128 as long,_ 'height source hm as ulong,_ 'mask bmp handle, null = not used hm is mask handle 0 as long,_ 'ulx mask 0 as long,_ 'uly mask re as long 'nonzero=success result=blit(scrDC,0,0,500,300,bufDC,0,0)
wait
[drehen] x1=-1*bmpWidth/2:y1=-1*bmpHeight/2 x2=1*bmpWidth/2:y2=-1*bmpHeight/2 x3=-1*bmpWidth/2:y3=1*bmpHeight/2 pi=acs(-1) cx=bmpWidth/2:cy=bmpHeight/2 r=1 aa=a*pi/180 c=cos(aa):s=sin(aa) lpPoint.x1.struct = int(cx+r*(c*x1-s*y1)+x) lpPoint.y1.struct = int(cy+r*(s*x1+c*y1)+y) lpPoint.x2.struct = int(cx+r*(c*x2-s*y2)+x) lpPoint.y2.struct = int(cy+r*(s*x2+c*y2)+y) lpPoint.x3.struct = int(cx+r*(c*x3-s*y3)+x) lpPoint.y3.struct = int(cy+r*(s*x3+c*y3)+y) return
function keyState(keycode) calldll #user32, "GetAsyncKeyState", _ keycode AS long, _ keyState AS long end function
Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As ulong,_ 'memory device context hObject As long,_ 'handle of object SelectObject As long 'returns previously selected object End Function
function blit(dDC,x,y,w,h,sDC,sx,sy) CallDll #gdi32, "BitBlt", _ dDC as ulong,_ 'The destination DC x as long,_ 'x location on destination y as long,_ 'y location on destination w as long,_ 'width to transfer h as long,_ 'height to transfer sDC as ulong,_ 'The source DC sx as long,_ 'x location in source sy as long,_ 'y location in source _SRCCOPY as ulong,_ 'The operation to be performed blit as long 'nonzero if successful end function
|
|
|
Post by held12345 on Mar 31, 2023 8:39:07 GMT -5
Hello, thanks for your help.
where is the zip you mentioned in your help?
Thanks. greeting
|
|