Page 1 of 1

Semi-transparent textures

Posted: Sun Nov 26, 2017 1:21 pm
by troy
Why the loaded textures have a transparency, but the custom drawn ones don't? See the example, comment/uncomment the appropriate parts of the code where the texture is loaded/created:

Code: Select all

Enumeration
  #MainWindow
EndEnumeration

InitEngine3D()

  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
 
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  w.l = 800
  h.l = 600
 
  OpenWindow(0, 0, 0, w, h, "transparent texture", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(0), 0, 0, w, h, 0, 0, 0)
  AmbientColor(RGB(255, 255, 255))
 
  ;- Camera
  CreateCamera(0, 0, 0, 100, 100)
  CameraFOV(0, 50)
  MoveCamera(0, 0, 0, 100, #PB_Absolute)
  CameraLookAt(0,0,0,0)
  CameraBackColor(0, $996633)
 
  ; Cube
  wt.l = 512
  ht.l = 512
  a.l = 255
  
  ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  ; Loaded Texture - WORKS
  LoadTexture(0, "ground_diffuse.png")
  ; Material
  CreateMaterial(0, TextureID(0))
  MaterialBlendingMode(0, #PB_Material_AlphaBlend)
  SetMaterialColor(0, #PB_Material_DiffuseColor, RGBA(255, 255, 255, a))
  ;DisableMaterialLighting(0, #True)
  
  ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  ; Custom Texture - DOESN'T WORK
;  CreateTexture(0, wt, ht, "cube")
;  StartDrawing(TextureOutput(0))
;  FillArea(1, 1, -1, $ffffff)
;  FrontColor(RGB(255, 0, 255))
;  Circle(wt/2, ht/2, wt/2 - 2, $999933)
;  StopDrawing()
  ; Material
;  CreateMaterial(0, TextureID(0))
;  MaterialBlendingMode(0, #PB_Material_AlphaBlend)
;  SetMaterialColor(0, #PB_Material_DiffuseColor, RGBA(255, 255, 255, a))
  
  
  ; Mesh
  CreateCube(0, 40)
  CreateEntity(0, MeshID(0), MaterialID(0), 0, 0, 0)
  
  go.l = #True
  
  Repeat
      
    ExamineKeyboard()
  
    Repeat : Event = WindowEvent() : Until Event = 0
     
    RotateEntity(0, 0, 1, 0, #PB_Relative)
    SetMaterialColor(0, #PB_Material_DiffuseColor, RGBA(255, 255, 255, a))
    If go : a - 1 : Else : a + 1 : EndIf
    If a = 0 : go = #False : EndIf
    If a = 255 : go = #True : EndIf
     
    RenderWorld()
    FlipBuffers()
  
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

End
Also if the DisableMaterialLighting() is set to #True the transparency doesn't work either. Wierd?

Re: Semi-transparent textures

Posted: Sun Nov 26, 2017 4:25 pm
by falsam
Use RGBA colours instead of RGB if you want transparency :wink:

Code: Select all

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  ; Custom Texture - WORK
  CreateTexture(0, wt, ht, "cube")
  StartDrawing(TextureOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels) 
  FillArea(1, 1, -1, RGBA(255, 255, 255, 255))
  FrontColor(RGBA(255, 0, 255, 255))
  Circle(wt/2, ht/2, wt/2 - 2, RGBA(51, 153, 153, a))
  StopDrawing()

Re: Semi-transparent textures

Posted: Mon Nov 27, 2017 9:52 am
by pf shadoko

Code: Select all

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  ; Custom Texture - DOESN'T WORK
 CreateTexture(0, wt, ht, "cube")
 StartDrawing(TextureOutput(0))
 DrawingMode(#PB_2DDrawing_AllChannels) ;<------------
 Circle(wt/2, ht/2, wt/2 - 2, $ff999933) ;<------------
 StopDrawing()
 ; Material
 CreateMaterial(0, TextureID(0))
 MaterialBlendingMode(0, #PB_Material_AlphaBlend)
 SetMaterialColor(0, #PB_Material_DiffuseColor, RGBA(255, 255, 255, a))
__________________________________________________
Code tags added
27.11.2017
RSBasic

Re: Semi-transparent textures

Posted: Tue Nov 28, 2017 10:06 am
by troy
Got it. Thanks guys!