[SOLVED] MeshVertexColor : how to enable Alpha
Posted: Sat Sep 07, 2013 7:03 pm
Hi,
I don't understand how to enable vertex alpha.
[solution below]
I don't understand how to enable vertex alpha.
[solution below]
Code: Select all
#CameraSpeed = 3
#SQRT13 = 0.57735026
If InitEngine3D() And InitSprite()
If OpenWindow(1, 0, 0, 800, 600, "Loading", #PB_Window_BorderLess |#PB_Window_ScreenCentered |#PB_Window_SystemMenu) And
OpenWindowedScreen(WindowID(1), 0, 0, 800, 600)
; Define all the vertices and their attributes
CreateMesh(0)
MeshVertexPosition(-100, 100, -100)
MeshVertexNormal(-#SQRT13, #SQRT13, -#SQRT13)
MeshVertexColor(RGBA(255, 0, 0, 100))
MeshVertexPosition(100, 100, -100)
MeshVertexNormal(#SQRT13, #SQRT13, -#SQRT13)
MeshVertexColor(RGB(255, 0, 0))
MeshVertexPosition(100, -100, -100)
MeshVertexNormal(#SQRT13, -#SQRT13, -#SQRT13)
MeshVertexColor(RGBA(Random(255), Random(255), Random(255), 180))
MeshVertexPosition(-100, -100, -100)
MeshVertexNormal(-#SQRT13, -#SQRT13, -#SQRT13)
MeshVertexColor(RGBA(Random(255), Random(255), Random(255), 100))
MeshVertexPosition(-100, 100, 100)
MeshVertexNormal(-#SQRT13, #SQRT13, #SQRT13)
MeshVertexColor(RGBA(Random(255), Random(255), Random(255), 220))
MeshVertexPosition(100, 100, 100)
MeshVertexNormal(#SQRT13, #SQRT13, #SQRT13)
MeshVertexColor(RGBA(Random(255), Random(255), Random(255), 150))
MeshVertexPosition(100, -100, 100)
MeshVertexNormal(#SQRT13, -#SQRT13, #SQRT13)
MeshVertexColor(RGBA(Random(255), Random(255), Random(255), 10))
MeshVertexPosition(-100, -100, 100)
MeshVertexNormal(-#SQRT13, -#SQRT13, #SQRT13)
MeshVertexColor(RGBA(Random(255), Random(255), Random(255), 200))
; Define all the faces, based on the vertex index
MeshFace(0, 2, 3)
MeshFace(0, 1, 2)
MeshFace(1, 6, 2)
MeshFace(1, 5, 6)
MeshFace(4, 6, 5)
MeshFace(4, 7, 6)
MeshFace(0, 7, 4)
MeshFace(0, 3, 7)
MeshFace(0, 5, 1)
MeshFace(0, 4, 5)
MeshFace(2, 7, 3)
MeshFace(2, 6, 7)
FinishMesh(1)
mesh=MeshID(0)
tex=CreateTexture(1, 512, 512)
If StartDrawing(TextureOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend) ; needed for alphablending
Box(0, 0, 512, 512, RGBA(78, 176, 160, 255))
StopDrawing()
EndIf
mat=CreateMaterial(0, tex)
MaterialCullingMode(0, #PB_Material_NoCulling) ; double face
MaterialBlendingMode(0, #PB_Material_AlphaBlend) ; allow alphablending and vertex alpha
DisableMaterialLighting(0, 1)
CreateEntity(0, mesh, mat)
CreateCamera(10, 0, 0, 100, 100)
MoveCamera(10, 0, 0, 1000, #PB_Absolute)
CameraLookAt(10, 0, 0, 0)
Repeat
RotateEntity(0, 1, 1, 1, #PB_Relative) ; rolling box
RenderWorld()
FlipBuffers()
Until WaitWindowEvent(1)=#PB_Event_CloseWindow
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End