The C version declares some of the variables as "static" which means, the variables retain their value in subsequent calls to the window procedure. In your Pascal code, the same variables are NOT static, just plain local variables, this causes them to lose their value.
Specifically, the value of the bitmap handle obtained in the WM_CREATE is lost when WM_CREATE ends, therefore the WM_PAINT is using some garbage that is occupying the bitmap handle when the WM_PAINT is processed.
Solution: ensure the variables declared as "static" in the C code are either global variables in your code or writable type constants (which is what "static" is in FPC.)
HTH.