Souci avec le système d'ombrage.
Publié : lun. 08/juin/2026 14:32
Si vous utilisez les dernières versions (>= 6.20) de PureBasic, vous aurez des soucis avec le système d'ombrage et certainement vous avez eu la boite de dialogue vous signifiant que l'exécutable de débogage se ferme de façon inattendue.
Ajoutez ceci dans votre code.
Un petit exemple.
Normalement vous verrez un cube avec son ombre
Ajoutez ceci dans votre code.
Code : Tout sélectionner
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Main", #PB_3DArchive_FileSystem)
Parse3DScripts()
Code : Tout sélectionner
EnableExplicit
; Evenement window
Global Event, Quit.b
; Sprite Help
Global Bottom, FontInfo = LoadFont(#PB_Any, "Arial", 12)
; Initialisation de l'environnement 3D
If InitEngine3D(#PB_Engine3D_DebugLog) = 0 Or InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Information", "Souci d'initialisation environnement 3D")
EndIf
OpenWindow(0, 0, 0, 0, 0, "Test ombrage", #PB_Window_Maximize | #PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0, #PB_Screen_NoSynchronization)
; Si PureBasic >= 6.20
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Main", #PB_3DArchive_FileSystem)
Parse3DScripts()
; Clavier international
KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
; Ombrage
WorldShadows(#PB_Shadow_Modulative, 0, RGB(180,180,180), 2048)
; Camera
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, RGB(119, 136, 153))
MoveCamera(0, 2, 2, 5, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
; Light
CreateLight(0, RGB(255, 255, 255), -10, 20, 5)
; Création d'un sol
CreatePlane(0, 10, 10, 1, 1, 1, 1)
CreateMaterial(0, 0, RGB(154, 205, 50))
CreateEntity(0, MeshID(0), MaterialID(0))
; Et d'un cube
CreateCube(1, 1)
CreateMaterial(1, 0, RGB(184, 134, 11))
CreateEntity(#PB_Any, MeshID(1), MaterialID(1), 0, 0.5, 0)
;- Création du sprite Help
Bottom = CreateSprite(#PB_Any, ScreenWidth(), 150, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(Bottom))
DrawingFont(FontID(FontInfo))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0, 0, ScreenWidth(), SpriteHeight(Bottom), RGBA(0, 0, 0, 140))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, ". : : Help : : .")
DrawText(10, 40, "Touche Escape pour quitter.")
StopDrawing()
EndIf
; Boucle evenementielle
Repeat
; Traiter les évenement de la file d'attente
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = #True
EndSelect
Until Event = 0
; Evenements 2D/3D
ExamineKeyboard()
RenderWorld()
; Sprite help
DisplayTransparentSprite(Bottom, 0, ScreenHeight()-SpriteHeight(Bottom))
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = #True