It is currently Sat Dec 16, 2017 7:37 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Semi-transparent textures
PostPosted: Sun Nov 26, 2017 1:21 pm 
Offline
User
User

Joined: Sat May 31, 2003 2:59 pm
Posts: 48
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Semi-transparent textures
PostPosted: Sun Nov 26, 2017 4:25 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 21, 2011 9:11 am
Posts: 580
Location: France
Use RGBA colours instead of RGB if you want transparency :wink:
Code:
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  ; 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 10 - PB 5.45 LTS & PB 5.60

http://falsam.com & EasySprite.js
http://purebasic.chat - Code PureBasic
Image Pure Basic Francophone Community

Sorry for my bad english and the Dunning–Kruger effect.


Top
 Profile  
Reply with quote  
 Post subject: Re: Semi-transparent textures
PostPosted: Mon Nov 27, 2017 9:52 am 
Offline
User
User

Joined: Thu Jul 09, 2015 9:07 am
Posts: 11
Code:
; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  ; 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


Top
 Profile  
Reply with quote  
 Post subject: Re: Semi-transparent textures
PostPosted: Tue Nov 28, 2017 10:06 am 
Offline
User
User

Joined: Sat May 31, 2003 2:59 pm
Posts: 48
Got it. Thanks guys!

_________________
--
troy


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye