|
Post by Rod on Oct 5, 2020 3:43:46 GMT -5
You will need to use LBPE to learn about bliting. This code takes the double buffer demo from the LBPE and changes the output blit to full screen. The graphics are drawn at 500x300 but stretched to DisplayWidth DisplayHeight for viewing. It looks more complex than it is. Have a browse at the lesson. Fun with the blitter. nomainwin WindowWidth = DisplayWidth WindowHeight = DisplayHeight UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 'graphicbox #1.g, 50,80,500,300 'textbox #1.t, 50,390, 500,25 graphicbox #1.g,0,0,DisplayWidth,DisplayHeight open "Blitter" for graphics nf_nsb as #1 print #1, "trapclose [quit]"
' set up our bitmaps, open device contexts and store our bitmaps in them
print #1.g, "down; fill black ; color white" for x = 1 to 50 print #1.g, "place ";int(rnd(0)*250);" ";int(rnd(0)*300) print #1.g, "size ";int(rnd(0)*4) print #1.g, "circle ";int(rnd(0)*3) next x print #1.g, "getbmp bmp 0 0 225 300" print #1.g, "drawbmp bmp 225 0" print #1.g, "place 475 40 ; size 1 ;circle 20" unloadbmp "bmp" print #1.g, "getbmp bmp 0 0 500 300" print #1.g, "getbmp bkg 0 0 500 300"
' bDC is our screen buffer, (DC handle to the graphicsbox)
bDC=GetDC(hwnd(#1.g))
' mDC is a copy of the screen in memory (double buffer)
mDC=CreateCompatibleDC(bDC) hBitmap=hbmp("bmp") oldBmp=SelectObject(mDC,hBitmap)
' gDC is a copy of the screen in memory to store reusable graphics in ' our graphics pallete if you like.
gDC=CreateCompatibleDC(bDC)
' we copy the screen but fill it with graphics of our choice ' and low and behold this amorphous data object assumes the ' size of the bmp we select into it
hBitmap=hbmp("bkg") oldBmp=SelectObject(gDC,hBitmap)
' set up a repeating loop to draw our graphics x=-1 y=-1 timer 17, [timedloop] wait
[timedloop] scan ' first thng we do now is draw from the memory to the buffer call StretchBlt,bDC,0,0,DisplayWidth,DisplayHeight,mDC,0,0,500,300
' now draw from the graphics resource to the memory
x=x+1 if x=225 then x=0 y=y+1 if y=300 then y=0 call StretchBlt,mDC,0,0,500,300,gDC,x,0,225,300 call StretchBlt,mDC,250,y,40,40,gDC,455,20,40,40 call StretchBlt,mDC,250,300-y,40,40,gDC,455,20,40,40 wait
[quit] unloadbmp "bmp" call ReleaseDC hwnd(#1), gDC call DeleteDC mDC close #1 end
'=============================Window and DC functions================================= Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",_ hWnd As ulong,_ 'window or control handle hDC As ulong,_ 'handle of DC to delete result As Long End Sub
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Sub DeleteDC hDC CallDLL #gdi32, "DeleteDC",_ hDC As ulong,_ 'memory DC to delete r As long End Sub
Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2 CallDLL #gdi32, "SetStretchBltMode",_ hDCdest As ulong,_ 'device context _COLORONCOLOR As Long,_ 'color reduction mode RESULT As Long CallDLL #gdi32, "StretchBlt",_ hDCdest As ulong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As ulong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source _SRCCOPY As long,_ 'dwRasterOperation RESULT As long End Sub
Sub TransparentBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2,crTransparent calldll #m, "TransparentBlt",_ hDCdest As uLong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As uLong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source crTransparent as ulong,_ 'color to make transparent result as long end sub
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 SetPixel(hDc,x,y,rgbColor) CallDll #gdi32, "SetPixel",_ hDc as Ulong,_ 'the handle of the Device context from GetDC x as long,_ 'the x coordinate to draw the pixel y as long,_ 'the y coordinate to draw the pixel rgbColor as long,_ SetPixel as long End Function
Sub SetBkMode hDC, flag '1=transparent '2=opaque CallDLL #gdi32, "SetBkMode",hDC As ulong,_ flag As long, RESULT As long End Sub
Sub TextOutA hDc,X,Y,text$ lengthtext=len(text$) calldll #gdi32, "TextOutA", _ hDc as ulong,_ 'device context of window or graphicbox X as long,_ 'x origin of text Y as long,_ 'y origin of text text$ as ptr,_ 'text string to display lengthtext as long,_'length of text string result as long 'nonzero if successful End Sub
sub SetTextColor hDc,crColor calldll #gdi32, "SetTextColor", _ hDc as ulong,_ 'device context of window or control crColor as long,_ 'long integer color value result as long 'returns previous text color, if successful End Sub
|
|
|
Post by Rod on Oct 7, 2020 6:35:10 GMT -5
This is a link to a dance demo I posted a while back. You will need it to get the support filesThe following code is tweaked to output full screen graphics. It just adopts your screen sixe so the graphics may be a little squashed or stretched depending on your screen format. The graphics are rendered in the background at 800x600 and scaled up each frame for display. 'Full Screen Scaling Demo 'Macaroni Merange Dance Classic 'Liberty Challenge Sep 2007 'rodbird@hotmail.com nomainwin WindowWidth = DisplayWidth WindowHeight = DisplayHeight UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) open "msimg32.dll" for dll as #m graphicbox #main.g, 0, 0, WindowWidth, WindowHeight open "Dance" for window_popup as #main 'since we go full screen you need option to allow user to quit 'here we use Q or Esc 'the setfocus is important else our keyboard input will be ignored #main.g "when characterInput [key]" #main.g "setfocus" print #main.g, "down ; fill black ; getbmp bmp 0 0 800 600"
' set up our bitmaps, open device contexts and store our bitmaps in them loadbmp "graphics","graphics.bmp"
' displayDC is our graphics screen/graphicbox displayDC=GetDC(hwnd(#main))
' bufferDC is a copy of the screen in memory used as a buffer to draw graphics to bufferDC=CreateCompatibleDC(displayDC) hBitmap=hbmp("bmp") oldBmp=SelectObject(bufferDC,hBitmap)
' sourceDC is a bitmap held in memory from which we get all our graphics sourceDC=CreateCompatibleDC(displayDC) hBitmap=hbmp("graphics") oldBmp=SelectObject(sourceDC,hBitmap)
' draw the initial stage call StretchBlt,bufferDC,0,0,800,600,sourceDC,0,0,400,300 call TransparentBlt,bufferDC,170,150,420,50,sourceDC,700,243,360,50,0 call TransparentBlt,bufferDC,190,80,400,50,sourceDC,400,243,300,50,0
' flip the buffer to the screen call StretchBlt,displayDC,0,0,WindowWidth,WindowHeight,bufferDC,0,0,800,600
' play midi playmidi "music.mid", howLong
[getreadytodance] 'set up variables and load dance array data xs=400 ys=0 xd=340 yd=300 xz=129 yz=243 dim danceX(10,15) dim danceY(10,15) for d=1 to 6 for x=1 to 15 read val danceX(d,x)=val next x for y=1 to 15 read val danceY(d,y)=val next y next d pos=0 d=6 s=6
[startdancing] 'set up a repetative call to [draw] timer 67, [draw] wait
[draw] scan ' flip the buffer to the screen so that it is visible and stable for as long as possible call StretchBlt,displayDC,0,0,WindowWidth,WindowHeight,bufferDC,0,0,800,600
'find where we are in the music m=midipos() 'print #main.g, "place 400 250" 'print #main.g, "\";midipos()
' Draw the stage again call StretchBlt,bufferDC,0,0,800,600,sourceDC,0,0,400,300
'select the dance routine if m>15 then d=5 : s=5 if m>79 then d=1 : s=1 if m>143 then d=4 : s=4 if m>175 then d=2 : s=2 if m>239 then d=3 : s=1 if m>335 then d=4 if m>431 then d=1 if m>495 then d=2 : s=2 if m>559 then d=4 : s=4 if m>623 then d=3 : s=3 if m>671 then d=5 : s=2 if m>751 then d=1 : s=1 if m>799 then d=2 : s=2 if m>879 then d=5 : s=3 if m>943 then d=1 : s=1 if m>1055 then d=5 : s=2 if m>1119 then s=3 if m>1183 then s=4 if m>1247 then d=4 : s=5 if m>1311 then d=3 if m>1375 then d=2 if m>1439 then d=1 : s=1 if m>1503 then d=2 : s=2 if m>1567 then d=3 : s=3 if m>1631 then d=4 : s=4 'check if we are finnished if m=1651 then d=6 : s=6
' draw the dancers pos=pos+1 if pos=16 then pos=1 end if call TransparentBlt,bufferDC,100,300,86,162,sourceDC,danceX(d,pos),danceY(d,pos),43,81,0 call TransparentBlt,bufferDC,200,300,86,162,sourceDC,danceX(d,pos),danceY(d,pos),43,81,0 call TransparentBlt,bufferDC,300,300,86,162,sourceDC,danceX(d,pos),danceY(d,pos),43,81,0 call TransparentBlt,bufferDC,400,300,86,162,sourceDC,danceX(d,pos),danceY(d,pos),43,81,0 call TransparentBlt,bufferDC,500,300,86,162,sourceDC,danceX(d,pos),danceY(d,pos),43,81,0 call TransparentBlt,bufferDC,600,300,86,162,sourceDC,danceX(d,pos),danceY(d,pos),43,81,0 call TransparentBlt,bufferDC,xd ,yd ,xz,yz ,sourceDC,danceX(s,pos),danceY(s,pos),43,81,0 wait
[key] k$=Inkey$ if upper$(k$)="Q" or asc(right$(k$,1))=_VK_ESCAPE then [quit] wait
[quit] timer 0 stopmidi unloadbmp "bmp" unloadbmp "graphics" call ReleaseDC hwnd(#main), displayDC call ReleaseDC hwnd(#main), bufferDC call ReleaseDC hwnd(#main), sourceDC call DeleteDC displayDC call DeleteDC bufferDC call DeleteDC sourceDC close #main close #m end '============================= data statements ================================= data 400,443,486,529,572,615,658,701,744,787,830,873,916,959,1002 data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 data 400,443,486,529,572,615,658,701,400,443,486,529,572,615,658 data 81,81,81,81,81,81,81,81,81,81,81,81,81,81,81 data 400,443,486,529,572,615,658,701,400,443,486,529,572,615,658 data 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162 data 744,787,830,873,916,959,1002,744,787,830,873,916,959,1002,1002 data 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162 data 400,443,486,400,443,486,400,443,486,400,443,486,400,443,486 data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 data 744,744,744,744,744,744,744,744,744,744,744,744,744,744,744 data 81,81,81,81,81,81,81,81,81,81,81,81,81,81,81 '=============================Window and DC functions================================= Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As Ulong,_ 'window or control handle GetDC As Ulong 'returns device context End Function
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",_ hWnd As Ulong,_ 'window or control handle hDC As Ulong,_ 'handle of DC to delete result As Long End Sub
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As Ulong,_ 'window DC CreateCompatibleDC As Ulong 'memory DC End Function
Sub DeleteDC hDC CallDLL #gdi32, "DeleteDC",_ hDC As Ulong,_ 'memory DC to delete result As Boolean End Sub
Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2 CallDLL #gdi32, "SetStretchBltMode",_ hDCdest As Ulong,_ 'device context _COLORONCOLOR As Long,_ 'color reduction mode result As Long CallDLL #gdi32, "StretchBlt",_ hDCdest As Ulong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As Ulong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source _SRCCOPY As Ulong,_ 'dwRasterOperation result As Boolean End Sub
Sub TransparentBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2,crTransparent calldll #m, "TransparentBlt",_ hDCdest As Ulong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As Ulong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source crTransparent as ulong,_ 'color to make transparent result as boolean end sub
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As Ulong,_ 'memory device context hObject As Ulong,_ 'handle of object SelectObject As Ulong 'returns previously selected object End Function
|
|