Ayant pris pour base l'exemple "Entity.pb", fourni par défaut avec le PureBasic, je fais quelques expérimentations en 3D. J'ai rajouté un compteur d'images par seconde ( FPS counter ) au code originel, et il s'avère que le résultat tourne autour de 62 FPS, et cela quel que soit l'argument passé à la fonction SetFrameRate.
Alors ma question est la suivante : l'utilisation des fonctions 3D du PureBasic, et notamment RenderWorld(), rend-t-elle inutile la fonction SetFrameRate ?
Tant que j'y suis, j'avais aussi une question subsidiaire : pourquoi mon code marche-t-il sous la version 4.40 et non pas sous la 4.41 ?
Merci pour le temps que vous prendrez à me répondre !
Code : Tout sélectionner
; "test 3D robot entities army.v0.01.pb"
; marche avec PureBasic 4.40, sa librairie "Engine3D.dll" et le dossier "Data" de ses exemples standards
; ne marche pas avec PureBasic 4.41 suite à une erreur avec le compteur de FPS...
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
Add3DArchive("Data" , #PB_3DArchive_FileSystem)
Add3DArchive("Data/skybox.zip", #PB_3DArchive_Zip)
InitSprite()
InitKeyboard()
InitMouse()
If OpenWindow(0,0,0,800,600,"test 3D robot entities army v1",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
If OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
SetFrameRate(10) ; ne marche apparemment pas !
LoadMesh (0, "robot.mesh")
CreateMaterial(0, LoadTexture(0, "clouds.jpg"))
CreateMaterial(1, LoadTexture(1, "r2skin.jpg"))
For m=0 To 4
For n=0 To 9
CreateEntity((m*10+n), MeshID(0), MaterialID(1), 60*n, 0, 60*m)
Next n
Next m
For n=0 To 49
AnimateEntity(n, "Walk")
Next n
SkyBox("desert07.jpg")
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,0,100)
TimeDelay.l=100 ; FPS counter
MasterTimer.l=GetTickCount_() ; FPS counter
Repeat
ClearScreen(RGB(0, 0, 0))
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_PageUp)
RollZ = 3
Else
RollZ = 0
EndIf
If KeyboardPushed(#PB_Key_Add)
Frame.f+0.005
EndIf
EndIf
If ExamineMouse()
MouseX = -MouseDeltaX()/10
MouseY = -MouseDeltaY()/10
EndIf
RotateCamera(0, MouseY, MouseX, RollZ, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
StartDrawing(WindowOutput(0)) ; FPS counter
FrontColor(RGB(255,0,0)) ; FPS counter
DrawText(10, 10, "FPS="+Str(FrameRate.f) ) ; FPS counter
StopDrawing() ; FPS counter
FlipBuffers()
TimeDelay=GetTickCount_()-MasterTimer ; FPS counter
MasterTimer=GetTickCount_() ; FPS counter
FrameRate.f=1000/TimeDelay ; FPS counter
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End