Ok, before I start describing my problem let me say that I used the search function of this board but found nowhere a good answer.
I tried to create a classic 2D Starfield which is scrolling from right to left with some stars moving faster than others and have different colors and so on ...
Of course I used a DeviceIndependantBitmap section to solve this task. But my stars are neither drawn nor moving. I post something from my code and hope someone can help me and see where is the mistake.
Variable declaration:
Initialization stuff:
Drawing when timer is ringing:
WM_Paint Message is just with BeginPaint,BitBlt,EndPaint ... should be alright
InitStars function:
DrawStars function (without making different colors for the stars, something easy for the beginning):
The mistake must be somewhere in this code snippets I think. But where? This is the 1Mio. $ Question ;-)
I would be glad about any help.
If one needs additional info, just ask.
I tried to create a classic 2D Starfield which is scrolling from right to left with some stars moving faster than others and have different colors and so on ...
Of course I used a DeviceIndependantBitmap section to solve this task. But my stars are neither drawn nor moving. I post something from my code and hope someone can help me and see where is the mistake.
Variable declaration:
SS_SIZE equ sizeof STAR
STAR STRUCT
x dd ?
y dd ?
plane dd ?
STAR ENDS
stars STAR NUM_OF_STARS dup(<?>)
should be enough to figure out if here is the mistakeInitialization stuff:
.if uMsg == WM_INITDIALOG
mov canvas.bmiHeader.biSize,sizeof canvas.bmiHeader
mov canvas.bmiHeader.biWidth,ScreenWidth
mov canvas.bmiHeader.biHeight,ScreenHeight
mov canvas.bmiHeader.biPlanes,1
mov canvas.bmiHeader.biBitCount,32
invoke GetDC,hwndDlg
mov hDC,eax
invoke CreateCompatibleDC,hDC
mov canvasDC,eax
invoke CreateDIBSection,hDC,addr canvas,DIB_RGB_COLORS,addr canvas_buffer,0,0
mov canvasBmp,eax
invoke SelectObject,canvasDC,canvasBmp
invoke ReleaseDC,hDC,0
invoke InitStars
invoke SetTimer,hwndDlg,0,100,0
Drawing when timer is ringing:
.elseif uMsg == WM_TIMER
mov edi,canvas_buffer ;only for
mov ecx,ScreenWidth * ScreenHeight ;wiping away
xor eax,eax ;old frame
rep stosd ;that was drawn
; invoke MoveStars ;even with leaving out the movement nothing happens
invoke DrawStars
invoke RedrawWindow,hwndDlg,0,0,RDW_INVALIDATE
WM_Paint Message is just with BeginPaint,BitBlt,EndPaint ... should be alright
InitStars function:
InitStars PROC USES ECX EBX
xor ebx,ebx
xor ecx,ecx
.while ecx < NUM_OF_STARS
invoke _random,ScreenWidth ;_random function works good, I tested it
mov ,eax
invoke _random,ScreenHeight
mov ,eax
invoke _random,16
mov ,eax
add ebx,SS_SIZE ;this should bring me to the beginning of the next stars struct in the array
inc ecx
.endw
ret
InitStars ENDP
DrawStars function (without making different colors for the stars, something easy for the beginning):
DrawStars PROC USES ECX EAX EBX EDX EDI
xor ebx,ebx
xor ecx,ecx
.while ecx < NUM_OF_STARS
invoke PutPixel,,,00FFFFFFh ;PutPixel also works correct, tested it
add ebx,SS_SIZE ;same as above, should jump to next struct in array
inc ecx
.endw
ret
DrawStars ENDP
The mistake must be somewhere in this code snippets I think. But where? This is the 1Mio. $ Question ;-)
I would be glad about any help.
If one needs additional info, just ask.
putpixel is incredibly slow for this, you can access the dib directly, and plot.. dma style.. much faster
also, are you handling WM_PAINT on the area, then bitblt the bitmap into the area... thats how i do it :)
also, are you handling WM_PAINT on the area, then bitblt the bitmap into the area... thats how i do it :)