Test code below is a copy of the example file MeshManual.pb, chopped-down (for example, excludes Screen3DRequester.pb) so that I can teach myself about Materials and Cameras.
In PB4.31, it runs perfectly (I have double-triple checked this!) - in Compiler Options, Library Subsystem, I entered "DirectX9" (a tip I picked-up elsewhere on the forum).
In PB4.40, the code fails. Firstly, the compiler complains that "DirectX9" cannot be found: "The following subsystem cannot be found: DirectX9".
If I remove the Subsystem entry, the code fails at FlipBuffers: "[ERROR] Invalid memory access. (read error at address 0)".
Whether DirectX9 is entered as a Subsystem or not, the original MeshManual.pb works fine, so not a PB bug. What is the difference between PB4.31 and PB4.40 that causes my code failure? I know that FlipBuffers and OpenWindowedScreen have been improved in PB4.40.
Code: Select all
; MeshTest
#WINDOW_Screen3D = 0
#CameraSpeed = 1
#Camera1 = 2
#MeshData = 3
#MeshEnt = 4
#MeshMatl = 5
Global sSourceFolder.s = "D:\PROJECTS\PureBasic\MeshTest\Data\"
Global sWindowTitle.s = "[ESC] Key to Exit"
Procedure Screen3D()
If OpenWindow(0, 0, 0, 800, 650, sWindowTitle, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Result = OpenWindowedScreen(WindowID(#WINDOW_Screen3D), 0, 50, 800, 600, 0, 0, 0)
EndIf
EndProcedure
If InitEngine3D()
UsePNGImageDecoder()
Add3DArchive(sSourceFolder, #PB_3DArchive_FileSystem)
InitSprite()
InitKeyboard()
InitMouse()
Screen3D()
; The data has to be organize in this order: Vertex, Normal, Color, UVCoordinate (per vertex)
; Create a cube, manually.. See the DataSection, for more precisions
CreateMesh(#MeshData, 100)
SetMeshData(#MeshData, #PB_Mesh_Vertex, ?VertData, 8)
SetMeshData(#MeshData, #PB_Mesh_Normal, ?NormData, 8)
SetMeshData(#MeshData, #PB_Mesh_Face, ?FaceData, 12)
CreateMaterial(#MeshMatl, LoadTexture(0, "AlphaChannel.png"))
MaterialAmbientColor(#MeshMatl, RGB($CC,$CC,$CC))
CreateEntity(#MeshEnt, MeshID(#MeshData), MaterialID(#MeshMatl))
CreateCamera(#Camera1, 0, 0, 100, 100)
CameraLocate(#Camera1, 0, 0, 1000)
CameraLookAt(#Camera1, EntityX(#MeshEnt), EntityY(#MeshEnt), EntityZ(#MeshEnt))
AmbientColor($FFFFF0)
Repeat
ClearScreen(RGB(0,0,0))
RotateEntity(#MeshEnt, 1, 1, 1, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "3D Engine did not start",0)
EndIf
CloseScreen()
End
#SQRT13 = 0.57735026
DataSection
VertData:
Data.f -100.0,100.0,-100.0 ; 0 position
Data.f 100.0,100.0,-100.0 ; 1 position
Data.f 100.0,-100.0,-100.0 ; 2 position
Data.f -100.0,-100.0,-100.0 ; 3 position
Data.f -100.0,100.0,100.0 ; 4 position
Data.f 100.0,100.0,100.0 ; 5 position
Data.f 100.0,-100.0,100.0 ; 6 position
Data.f -100.0,-100.0,100.0 ; 7 position
NormData:
Data.f -#SQRT13,#SQRT13,-#SQRT13 ; 0 normal
Data.f #SQRT13,#SQRT13,-#SQRT13 ; 1 normal
Data.f #SQRT13,-#SQRT13,-#SQRT13 ; 2 normal
Data.f -#SQRT13,-#SQRT13,-#SQRT13 ; 3 normal
Data.f -#SQRT13,#SQRT13,#SQRT13 ; 4 normal
Data.f #SQRT13,#SQRT13,#SQRT13 ; 5 normal
Data.f #SQRT13,-#SQRT13,#SQRT13 ; 6 normal
Data.f -#SQRT13,-#SQRT13,#SQRT13 ; 7 normal
FaceData:
Data.w 0,2,3
Data.w 0,1,2
Data.w 1,6,2
Data.w 1,5,6
Data.w 4,6,5
Data.w 4,7,6
Data.w 0,7,4
Data.w 0,3,7
Data.w 0,5,1
Data.w 0,4,5
Data.w 2,7,3
Data.w 2,6,7
EndDataSection
; IDE Options = PureBasic 4.40 (Windows - x86)
; CursorPosition = 13
; FirstLine = 28
; Folding = -
; EnableThread
; EnableXP
; SubSystem = DirectX9
; CurrentDirectory = D:\PROJECTS\PureBasic\
; CompileSourceDirectory