I wished for a FAST version of ... GetPixel () and SetPixelV(). My wish never came true.
So I had to create my "Quick Pixels" library to do the job. And today, I have achieved
something that Microsoft should have put into the GDI32.DLL 30 years ago. It is fast.
It is REALLY !@#$%^& FAST! And it is SUPER EASY to use.
SUB DrawPhongBall(Radius AS SINGLE, hdc AS HDC)
'=======================================================
' A much simpler and much improved Phong Ball Generator
' Now adds reflection (shine) to the surface
'=======================================================
DIM AS INT r = RND2(1, 255) ' Random red component
DIM AS INT g = RND2(1, 255) ' Random green component
DIM AS INT b = RND2(1, 255) ' Random blue component
DIM AS INT shine = 250 ' Shine intensity
OpenBmpData (hdc)
FOR INT Y = -Radius TO Radius
FOR INT X = -Radius TO Radius
DIM RAW distance = HYPOT(X, Y)
IF distance <= Radius THEN
DIM AS FLOAT alpha = 1.0 - (distance / Radius) ' Equation for semi-transparency
DIM AS FLOAT shineAlpha = (1.0 - (distance / Radius)) * (shine / 255) ' Adjust shine based on distance
DIM RAW AS DWORD GradientColor = RGB(r * alpha, g * alpha, b * alpha)
DIM RAW AS DWORD ShineColor = RGB(shineAlpha * 255, shineAlpha * 255, shineAlpha * 255)
' Blend the main color and shine color
GradientColor = (GradientColor BAND &H00FFFFFF) BOR ((ShineColor BAND &H00FFFFFF) << 24)
SetPixelFast(X + Radius, Y + Radius, GradientColor)
END IF
NEXT
NEXT
CloseBmpData (hdc)
END FUNCTION
The original version of this demo did not have those three highlighted lines of code. The original
version used BCX_PSET(0, X + Radius, Y + Radius, GradientColor, hdc) instead
of the SetPixelFast statement.
The original version took 15 seconds to draw 100 phong-shaded balls of varying sizes
and store them into an array of bitmaps for quick display.
My new "Quick Pixels" library reduced those 15 seconds down to 1 second.
I'll be uploading at least four new demos, after BCX 8.0.6 is released. Until then, I just
wanted to give some of you something to look forward to.
So tell me, is anyone looking forward to this?