How to change the background color in 3d

Everything related to 3D programming
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

How to change the background color in 3d

Post by pfaber11 »

Hello once again what I was wanting to know is how do I change the background color after openscreen() . Have tried a few
things with no success . Thanks for reading .
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: How to change the background color in 3d

Post by applePi »

in the example ..\PureBasic\Examples\Sources\Sprite.pb
there is OpenScreen function, and in the Loop there is ClearScreen(RGB(0,0,0)) . change it to ClearScreen(RGB(220,210,0)) and we get yellow background
i don't see any OpenScreen(...) in C:\PureBasic\Examples\3D except Screen3DRequester.pb which is a utility code. the background color used in the examples in PureBasic\Examples\3D is CameraBackColor(0, RGB(r, g, b))
example for CameraBackColor for windowed program:
the render code is taken from C:\PureBasic\Examples\3D\Demos\FacialAnimation.pb

Code: Select all

If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts",#PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  
  OpenWindow(0, 0, 0, 1024, 768, "Facial Animation", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, 0, 0, 0)
  
BarrelMesh = LoadMesh(#PB_Any,"barrel.mesh")
MyTexture = LoadTexture(#PB_Any,"RustyBarrel.png");"spheremap.png")
  
BarrelMaterial = CreateMaterial(#PB_Any,TextureID(MyTexture)) 
 
Barrel = CreateEntity(#PB_Any,MeshID(BarrelMesh),MaterialID(BarrelMaterial),  0, 0, 0)

CreateCamera(0, 0, 0, 100, 100)  

CameraBackColor(0, RGB(145, 190, 20))
MoveCamera(0, 3, 7, 15, #PB_Absolute)  
CameraLookAt(0, 0,0,0)   

  Repeat
    
    Repeat   
      Event = WindowEvent()
      
      If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
        Quit = 1
      
      EndIf  
      
    Until Event = 0
    
    ExamineKeyboard()
    RotateEntity(Barrel, 0,0.5,0, #PB_Relative)
    
    RenderWorld()
    FlipBuffers()
    
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
EndIf

End
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to change the background color in 3d

Post by pfaber11 »

Thanks the camerabackcolor(0,#red) did exactly what I wanted. Tried a few different things but am really happy it's sorted. Thanks again.
Post Reply