[3D Programming] Cube 3D Preformance Test Failed, Crached!

Everything related to 3D programming
User avatar
JamieVanCadsand
User
User
Posts: 34
Joined: Sun Jun 24, 2018 12:28 pm
Location: Holland

[3D Programming] Cube 3D Preformance Test Failed, Crached!

Post by JamieVanCadsand »

Hey Programmers and 3D Developers...

I try to create an for cube loop, just an simple demo to test the 3d preformence on my laptop and computer yet...
Now i get this created script, writted in PureBasic 5.x yet:

Code: Select all

;Declare World
Declare Setup3DWorld()

;Enumerate ID's
Enumeration IDs
  #Lamp
  #Camera
  #Mesh
  #Entity
EndEnumeration



;Check if screen will be initialize
If InitEngine3D() = 0 Or InitSprite() = 0 Or InitKeyboard() = 0 Or OpenScreen(800, 600, 32, "3D Rotated Cobes", #PB_Screen_NoSynchronization) = 0
  MessageRequester("Fout!", "Scherm wilt niet initializeren", #PB_MessageRequester_Info)
  End
EndIf

;Make Procedure
Procedure Setup3DWorld()
  
  ;Create Light
  CreateLight(#Lamp, RGB(255, 255, 255), 1, 1, 1, #PB_Light_Directional)
  
  ;Create Camera
  CreateCamera(#Camera, 0, 0, 100, 100)
  MoveCamera(#Camera, 400, 400, 100, #PB_Absolute | #PB_Local)
  CameraLookAt(#Camera, 0, 1, 0)
  
  ;Create Cube
  CreateCube(#Mesh, 1)
  
  ;Create an Static Cube Mesh, called High Poly
  For X = 0 To 640 Step 2
    For Y = 0 To 640 Step 2
      For Z = 0 To 640 Step 2
        ;Create Entiry for All Cubes
        CreateEntity(#Entity, MeshID(#Mesh), #PB_Material_None, X, Y, Z)
      Next
    Next
  Next
  
  ;Rotate Entiry
  RotateEntity(#Entity, 1, 1, 1, #PB_Local)
  
  
  
  
  
  Repeat
    
    ;Setup 3D
    RenderWorld()
    FlipBuffers()
    ClearScreen(0)
    
  ForEver
  
  
  
  
  ;Check if player will be quit it
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
    
EndProcedure

;Call 3D
Setup3DWorld()
Now if i run my script, this program crashing.... So can anyone correct my codes pleace,
Thanks for help, Jamie.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: [3D Programming] Cube 3D Preformance Test Failed, Crache

Post by DK_PETER »

Holy Moly! :D
The sheer number of cubes you're trying to create and render are way too many.
Here's a more realistic example. It creates 1331 cubes, which is quite a lot on
low end machines. On my pc the example below runs smoothly at a steady framerate of 120.

Edit:
ClearScreen() isn't working in 3D
I recommend using a windowed screen for much more stability and more options.
Best of luck in you 3D endeavour. :wink:

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

NewList cube.i()

OpenWindow(0, 0, 0, 800, 600, "Cubes", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 70)
CreateLight(0, $FFFFFF, 0, 0, 0)

;create a base mesh, texture, material and the entity
CreateCube(0, 0.5)
CreateTexture(0, 50, 50, "color")
StartDrawing(TextureOutput(0))
DrawingMode(#PB_2DDrawing_Gradient)
FrontColor($FFBB00) :BackColor($00FF1B)
LinearGradient(0, 0, 50, 50)
Box(0, 0, 50, 50)
StopDrawing()
CreateMaterial(0, TextureID(0))
CreateEntity(0, MeshID(0), MaterialID(0))
nod = CreateNode(#PB_Any, 0, 0, 0)
For x = -10 To 10 Step 2      ;Change any of the step values to less and you'll see a dramatic drop in rendering and framerate
  For y = -10 To 10 Step 2    
    For z = -10 To 10 Step 2
      AddElement(cube())
      cube() = CopyEntity(0, #PB_Any)
      MoveEntity(cube(), x, y, z, #PB_Absolute) ;copy the base entity
      AttachNodeObject(nod, EntityID(cube()))   ;attach the entity to the node
    Next z
  Next y
Next x
Debug "The number of objects being rendered is: " + Str(ListSize(cube()))
Repeat
  Repeat
    ev = WindowEvent()
  Until ev = 0
  RotateNode(nod, 0.2, -0.4, 0.5, #PB_Relative)
  RenderWorld()
  FlipBuffers()
  SetWindowTitle(0, "Average framerate : " + Str(Engine3DStatus(#PB_Engine3D_AverageFPS)))
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
JamieVanCadsand
User
User
Posts: 34
Joined: Sun Jun 24, 2018 12:28 pm
Location: Holland

Re: [3D Programming] Cube 3D Preformance Test Failed, Crache

Post by JamieVanCadsand »

Thanks for help, i get this changes in this following code:

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

NewList cube.i()

OpenScreen(800, 600, 32, "Cubes", #PB_Window_ScreenCentered | #PB_Screen_NoSynchronization)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 70)
CreateLight(0, $FFFFFF, 0, 0, 0)

;create a base mesh, texture, material and the entity
CreateCube(0, 0.5)
CreateTexture(0, 50, 50, "color")
StartDrawing(TextureOutput(0))
DrawingMode(#PB_2DDrawing_Gradient)
FrontColor($FFBB00) :BackColor($00FF1B)
LinearGradient(0, 0, 50, 50)
Box(0, 0, 50, 50)
StopDrawing()
CreateMaterial(0, TextureID(0))
CreateEntity(0, MeshID(0), MaterialID(0))
nod = CreateNode(#PB_Any, 0, 0, 0)
For x = -20 To 20 Step 2      ;Change any of the step values to less and you'll see a dramatic drop in rendering and framerate
  For y = -20 To 20 Step 2    
    For z = -20 To 20 Step 2
      AddElement(cube())
      cube() = CopyEntity(0, #PB_Any)
      MoveEntity(cube(), x, y, z, #PB_Absolute) ;copy the base entity
      AttachNodeObject(nod, EntityID(cube()))   ;attach the entity to the node
    Next z
  Next y
Next x
Debug "The number of objects being rendered is: " + Str(ListSize(cube()))
Repeat
  RotateNode(nod, 0.2, -0.4, 0.5, #PB_Relative)
  RenderWorld()
  FlipBuffers()
  ClearScreen(0)
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
ForEver
Post Reply