- White + Alpha Blend
- Color + Alpha Blend
- Color + Add Blend
- Color + Color Blend

Code: Select all
DisableExplicit
Procedure CreateQuad(x.f, y.f, v, RGBA)
MeshVertexPosition(0+x, 0+y, 0)
MeshVertexTextureCoordinate(0, 0)
MeshVertexColor(RGBA)
MeshVertexPosition(1+x, 0+y, 0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexColor(RGBA)
MeshVertexPosition(1+x, 1+y, 0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexColor(RGBA)
MeshVertexPosition(0+x, 1+y, 0)
MeshVertexTextureCoordinate(0, 1)
MeshVertexColor(RGBA)
MeshFace(v+0, v+1, v+2)
MeshFace(v+2, v+3, v+0)
EndProcedure
Procedure UpdateBlendingPreview(Mesh, Color)
UpdateMesh(Mesh, 0)
Protected R=Red(Color)
Protected G=Green(Color)
Protected B=Blue(Color)
#count=10
Protected v, y.f, x.f, k.f, RGBA
v=0 : y.f=0 : x.f=0
For i=0 To #count
k.f=i/#count
RGBA=RGBA(255, 255, 255, 255*k)
CreateQuad(x, y, v, RGBA)
v+4 : y+1.2
Next
FinishMesh(0)
UpdateMesh(Mesh, 1)
v=0 : y.f=0 : x.f+1.2
For i=0 To #count
k.f=i/#count
RGBA=RGBA(R, G, B, 255*k)
CreateQuad(x, y, v, RGBA)
v+4 : y+1.2
Next
FinishMesh(0)
UpdateMesh(Mesh, 2)
v=0 : y.f=0 : x.f+1.2
For i=0 To #count
k.f=i/#count
RGBA=RGBA(R*k, G*k, B*k, 255)
CreateQuad(x, y, v, RGBA)
v+4 : y+1.2
Next
FinishMesh(0)
UpdateMesh(Mesh, 3)
v=0 : y.f=0 : x.f+1.2
For i=0 To #count
k.f=i/#count
RGBA=RGBA(R*k, G*k, B*k, 255)
CreateQuad(x, y, v, RGBA)
v+4 : y+1.2
Next
FinishMesh(0)
NormalizeMesh(Mesh)
EndProcedure
Procedure UpdateColorCode(SelectedColor)
Protected R=Red(SelectedColor)
Protected G=Green(SelectedColor)
Protected B=Blue(SelectedColor)
SetGadgetText(1, "$"+Hex(SelectedColor)+" RGB("+R+","+G+","+B+")")
EndProcedure
If InitEngine3D()=0 Or InitSprite()=0
MessageRequester("Engine3D / Sprite", "Failed")
EndIf
win=OpenWindow(#PB_Any, 0, 0, 800, 600, "Blending 3D Tester", #PB_Window_BorderLess |#PB_Window_ScreenCentered |#PB_Window_SystemMenu)
If IsWindow(win)=0 Or OpenWindowedScreen(WindowID(win), 266, 0, WindowWidth(win)-266, WindowHeight(win))=0
MessageRequester("Window / Screen", "Failed")
EndIf
Mesh=CreateMesh(#PB_Any, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
CreateQuad(x, y, v, RGBA)
AddSubMesh(#PB_Mesh_TriangleList)
CreateQuad(x, y, v, RGBA)
AddSubMesh(#PB_Mesh_TriangleList)
CreateQuad(x, y, v, RGBA)
AddSubMesh(#PB_Mesh_TriangleList)
CreateQuad(x, y, v, RGBA)
FinishMesh(0)
cam=CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(cam, 0, 0, 100)
CameraBackColor(cam, RGB(100, 100, 100))
CameraProjectionMode(cam, #PB_Camera_Orthographic)
tex=CreateTexture(#PB_Any, 256, 256)
StartDrawing(TextureOutput(tex))
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
BackColor(RGBA(255, 0, 0, 255))
GradientColor(0.2, RGBA(255, 255, 0, 255))
GradientColor(0.3, RGBA(0, 255, 0, 255))
GradientColor(0.5, RGBA(0, 255, 255, 255))
GradientColor(0.6, RGBA(0, 0, 255, 255))
GradientColor(0.8, RGBA(255, 255, 255, 255))
FrontColor(RGBA(255, 255, 255, 100))
CircularGradient(0, 0, 280)
Box(0, 0, 256, 256)
StopDrawing()
mat=CreateMaterial(#PB_Any, TextureID(tex))
MaterialBlendingMode(mat, #PB_Material_AlphaBlend)
MaterialCullingMode(mat, #PB_Material_NoCulling)
DisableMaterialLighting(mat, 1)
mat2=CopyMaterial(mat, #PB_Any)
MaterialBlendingMode(mat2, #PB_Material_Add)
mat3=CopyMaterial(mat, #PB_Any)
MaterialBlendingMode(mat3, #PB_Material_Color)
;set submesh materials
SetMeshMaterial(Mesh, MaterialID(mat), 0)
SetMeshMaterial(Mesh, MaterialID(mat), 1)
SetMeshMaterial(Mesh, MaterialID(mat2), 2)
SetMeshMaterial(Mesh, MaterialID(mat3), 3)
CreateNode(0)
AttachNodeObject(0, MeshID(Mesh))
ScaleNode(0, 65, 65, 1)
MoveNode(0, 0, -400, 0)
;canvas color picker
CanvasGadget(0, 5, 5, 256, 512)
StartDrawing(CanvasOutput(0))
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
cx.f=0 : ck.f=1.0/6.0
BackColor(RGBA(255, 0, 0, 255)) : cx+ck
GradientColor(cx, RGBA(255, 255, 0, 255)) : cx+ck
GradientColor(cx, RGBA(0, 255, 0, 255)) : cx+ck
GradientColor(cx, RGBA(0, 255, 255, 255)) : cx+ck
GradientColor(cx, RGBA(0, 0, 255, 255)) : cx+ck
GradientColor(cx, RGBA(255, 0, 255, 255)) : cx+ck
FrontColor(RGBA(255, 0, 0, 255))
LinearGradient(0, 0, 255, 0)
Box(0, 0, 256, 512)
ResetGradientColors()
BackColor(RGBA(0, 0, 0, 255))
GradientColor(0.4, RGBA(0, 0, 0, 0))
GradientColor(0.6, RGBA(255, 255, 255, 0))
FrontColor(RGBA(255, 255, 255, 255))
LinearGradient(0, 0, 0, 511)
Box(0, 0, 256, 512)
StopDrawing()
;color code
StringGadget(1, 5, 530, 256, 20, "")
;init Blending preview with selected color
SelectedColor=RGB(255, 51, 173)
UpdateBlendingPreview(Mesh, SelectedColor)
UpdateColorCode(SelectedColor)
Repeat
RenderWorld()
FlipBuffers()
If WindowEvent()=#PB_Event_Gadget
If EventGadget()=0 And EventType()=#PB_EventType_LeftClick
mx=GetGadgetAttribute(0, #PB_Canvas_MouseX)
my=GetGadgetAttribute(0, #PB_Canvas_MouseY)
StartDrawing(CanvasOutput(0))
SelectedColor=Point(mx, my)
StopDrawing()
UpdateBlendingPreview(Mesh, SelectedColor)
UpdateColorCode(SelectedColor)
EndIf
EndIf
Until WaitWindowEvent(1)=#PB_Event_CloseWindow