Semi-transparent textures

Everything related to 3D programming
troy
User
User
Posts: 51
Joined: Sat May 31, 2003 2:59 pm

Semi-transparent textures

Post 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?
--
troy
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Semi-transparent textures

Post 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()

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 285
Joined: Thu Jul 09, 2015 9:07 am

Re: Semi-transparent textures

Post 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
troy
User
User
Posts: 51
Joined: Sat May 31, 2003 2:59 pm

Re: Semi-transparent textures

Post by troy »

Got it. Thanks guys!
--
troy
Post Reply