Page 1 of 1

Creating Textures and Materials at runtime

Posted: Tue Oct 25, 2016 10:33 pm
by tastyraspberry
Hi all,

I am a bit stumped. I get two red balls on my screen, not one red and one blue. Can anyone see where I am going wrong?

Michael

Code: Select all

XIncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

Screen3DRequester()
CreateNode(0, 0, 0, 0)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, -5, 0)

CreateLight(#PB_Any, RGB(255, 255, 255), 0, 5, 0)

CreateSphere(0, 0.5)
CreateSphere(1, 1)

;textures and materials for the balls
TextureRed.i = CreateTexture(#PB_Any , 32, 32)
StartDrawing(TextureOutput(TextureRed))
Box(0, 0, TextureWidth(TextureRed), TextureHeight(TextureRed), RGB(255, 0, 0))
StopDrawing()
MaterialRed.i = CreateMaterial(#PB_Any, TextureID(TextureRed))

TextureBlue.i = CreateTexture(#PB_Any, 256, 256)
StartDrawing(TextureOutput(TextureBlue))
Box(0, 0, TextureWidth(TextureBlue), TextureHeight(TextureBlue), RGB(0, 0, 255))
StopDrawing()
MaterialBlue.i = CreateMaterial(#PB_Any, TextureID(TextureBlue))


RedBall = CreateEntity(#PB_Any, MeshID(0),  MaterialID(MaterialRed), -1, 0, 0)
BlueBall = CreateEntity(#PB_Any, MeshID(1), MaterialID(MaterialBlue), 1, 0, 0)  

Repeat
  Screen3DEvents()
  
  ExamineKeyboard()
  
  CameraFollow(0, NodeID(0), 0, 10, 10, 1, 1, #True)
  
  RenderWorld()
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape)

Re: Creating Textures and Materials at runtime

Posted: Tue Oct 25, 2016 11:18 pm
by Comtois
It's a bug with new parameter.
While waiting a fix , write last parameter
TextureRed.i = CreateTexture(#PB_Any , 32, 32, "")
TextureBlue.i = CreateTexture(#PB_Any, 256, 256, "")

Re: Creating Textures and Materials at runtime

Posted: Tue Oct 25, 2016 11:21 pm
by tastyraspberry
oh thank you!

I didn't realise there was a 'new parameter'! Will check the forum!

It now works..

Sigh of relief!

Michael