This code runs without problem with any configurations. But it crashs with others configurations.
I added conditions to prevent from crash, with messages to display a small bug report.
Could you test and answer if the run is ok, else could you post the bug report and your config?
Thank you!
Code: Select all
;PB 4.30
MessageRequester("Info", "Arrow keys to accelerate and turn left or right...")
;10/01/09 Substitution de l'instruction TextureOutput (Comtois)
;20/03/09 Test défilement 2D (Ollivier)
;23/03/09 Sécurité de dessin (Dr Dri)
;23/03/09 Chronométrie pour Linux (Cpl.Bator)
;25/03/09 Architecture propre pour débutants (djes)
;___________________________________________________________
;{ Informations initiales
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;___________________________________________________________
;{ Constantes
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
#R2D = 180.0 / #PI ; R2D = Conversion Radians/Degrés
Enumeration
#Texture
#TextureSol
EndEnumeration
Enumeration
#Matiere
#MatiereSol
EndEnumeration
Enumeration
#Entity
#EntitySol
EndEnumeration
;}
;___________________________________________________________
;{ Déclaration des procédures
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Declare.S TempPng(n.I)
Declare.S InitSmoothScrolling()
;}
;___________________________________________________________
;{ Structures
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Structure V3D ; Vecteur 3D
X.F
Y.F
Z.F
EndStructure
Structure V2D ; Vecteur 2D
U.F
V.F
EndStructure
Structure Sommet
P.V3D ; Position
N.V3D ; Normale
C.L ; Couleur
T.V2D ; Texture
EndStructure
Structure Triangle
A.W
B.W
C.W
EndStructure
;}
;___________________________________________________________
;{ Variables globales
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Global PleinEcran.I = 1 ; 1 = FullScreen, 0 = Fenêtré
Global EcranLargeur.I
Global EcranHauteur.I
Global EcranBitsParPixel.I
Global Dim Sommet.Sommet(0)
Global ZI.I
Global XI.I
Global Dim Triangle.Triangle(0)
Global FigCarre.I ; N° de la structure fil de fer carré
Global Camera.I ; N° de la caméra (par défaut : 0)
Global RepertoireCaractere.S = "\"
Global Rapport.S = InitSmoothScrolling()
Global ScrollX.F
Global ScrollY.F
Global AngleTeta.F
Global Coef.F
Global AngleV.F
Global Angle.f, Vitesse.f
If Rapport <> "!Init"
MessageRequester("Erreur", "Impossible d'initialiser le programme !")
End
EndIf
;}
;}
;___________________________________________________________
;{ Crée les 2 éléments (Images,textures,matières et entités)
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Semblant de vaisseau
If CreateImage(#Texture, 64, 64)
If StartDrawing(ImageOutput(#Texture))
Box(0, 0, ImageWidth(#Texture), ImageHeight(#Texture), $FFFFFF)
DrawingMode(#PB_2DDrawing_Outlined) ; Pour tracer le contour
Box(0, 0, ImageWidth(#Texture), ImageHeight(#Texture), 0)
StopDrawing()
If SaveImage(#Texture, TempPng(1), #PB_ImagePlugin_PNG)
FreeImage(#Texture)
If LoadTexture(#Texture, TempPng(1) )
If CreateMaterial(#Matiere, TextureID(#Texture))
; Crée le semblant de vaisseau
If CreateEntity(#Entity, MeshID(FigCarre), MaterialID(#Matiere))
; Agrandit et positionne le semblant de vaisseau
ScaleEntity(#Entity, 10, 10, 10) ; Agrandit l'entité
EntityLocate(#Entity, 500, 100, 500)
Rapport + "!E1" ; /!\
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
; Texture du fond étoilé de l'écran
If CreateImage(#TextureSol, 512, 512)
If StartDrawing(ImageOutput(#TextureSol)) ; On sécurise
Box(0, 0, ImageWidth(#TextureSol), ImageHeight(#TextureSol), $0)
For I = 0 To 500
R = Random(127) + 128
X = Random(511)
Y = Random(511)
Plot(X, Y, RGB(R, R, R) )
For D = 1 To 5
C = RGB(R / 1 << D, R / 1 << D, R / 1 << D)
Line((X - D << 1) & 511, (Y) & 511, -2, 1, C)
Line((X + D << 1) & 511, (Y) & 511, 2, 1, C)
Line((X) & 511, (Y - D << 1) & 511, 1, -2, C)
Line((X) & 511, (Y + D << 1) & 511, 1, 2, C)
For DX = -1 To 1 Step 2
For DY = -1 To 1 Step 2
Plot((X + DX * D) & 511, (Y + DY * D) & 511, C)
Next DY
Next DX
Next D
Next I
StopDrawing()
If SaveImage(#TextureSol, TempPng(2), #PB_ImagePlugin_PNG)
If LoadTexture(#TextureSol, TempPng(2) )
If CreateMaterial(#MatiereSol, TextureID(#TextureSol) )
; On rajoute 3 autres couches pour le parallaxe
For I = 1 To 3
AddMaterialLayer(#MatiereSol, TextureID(#TextureSol), #PB_Material_Replace)
Next I
; Crée le fond étoilé
If CreateEntity(#EntitySol, MeshID(FigCarre), MaterialID(#MatiereSol) )
; Agrandit et positionne le fond étoilé
ScaleEntity(#EntitySol, 1000, 2, 1000)
EntityLocate(#EntitySol, 500, -50, 500)
Rapport + "!E2" ; /!\
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
If Rapport <> "!Init!E1!E2"
CloseScreen()
Delay(1)
MessageRequester("Erreur à la création", "Rapport : " + Rapport)
End
EndIf
;}
;___________________________________________________________
;{ Boucle principale
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Angle = #PI / 2.0
StartTime = ElapsedMilliseconds() + 16
Repeat
Delay(1) ; On prévient XP qu'on est cool (XP)
RealTime.I = ElapsedMilliseconds()
If RealTime => StartTime ; On bride (Linux)
StartTime + 16
If PleinEcran
Delay(1) ; Sous µsoft,
Delay(1) ; XP annule ou non ces instructions
Delay(1) ; Cela dépend notamment de ce qui se passe
Delay(1) ; en temps réel en arrière-plan
Delay(1) ; Comme c'est à titre préventif,
Delay(1) ; il n'y a pas d'impact sur la fluidité.
Delay(1) ; Sous Linux, ceci est une blague...
Else
WindowEvent()
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
Vitesse + 0.0001
EndIf
Vitesse * 0.99
If KeyboardPushed(#PB_Key_Left)
AngleV + 0.005
ElseIf KeyboardPushed(#PB_Key_Right)
AngleV - 0.005
EndIf
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
EndIf
Angle + AngleV
AngleV * 0.9
ScrollX + Cos(Angle) * Vitesse
ScrollY + Sin(Angle) * Vitesse
RotateEntity(#Entity, 0.0, Angle * #R2D, 0.0, PB_Absolute)
CameraLocate(Camera, 500 - Cos(-Angle - #PI / 2) * Vitesse * 16000, 500, 500 - Sin(-Angle - #PI / 2) * Vitesse * 16000)
For I = 0 To 3
Coef = 1.0 / (1 + I)
ScrollMaterial(#MatiereSol, ScrollX / Coef, ScrollY / Coef, #PB_Material_Fixed, I)
Next I
RenderWorld()
FlipBuffers()
EndIf
ForEver
CloseScreen()
Delay(1)
End
;}
;___________________________________________________________
;___________________________________________________________
;{ Procédures
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Procedure.S TempPng(n.I)
;________________________________________________________
; Retourne un nom de fichier PNG temporaire numéroté
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected Result.S
Result = "Temp" + Str(n) + ".PNG"
ProcedureReturn Result
EndProcedure
Procedure.S InitSmoothScrolling()
;________________________________________________________
; Intègre toute la partie initialisation 3D
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected Result.S
;___________________________________________________________
;{ Initialisations générales
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
If InitEngine3D() ; Initialise Ogre
If InitSprite() ; Initialise DirectX
If InitKeyboard() ; Initialise le clavier
UsePNGImageEncoder() ; Prise en charge du format image PNG
Add3DArchive(RepertoireCaractere, #PB_3DArchive_FileSystem)
;}
;___________________________________________________________
;{ Préparation de la zone de travail graphique
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
If ExamineDesktops()
EcranLargeur = DesktopWidth(0)
EcranHauteur = DesktopHeight(0)
EcranBitsParPixel = DesktopDepth(0)
If PleinEcran
OpenScreen(EcranLargeur, EcranHauteur, EcranBitsParPixel, "Smooth scrolling")
Else
OpenWindow(0, 0, 0, EcranLargeur, EcranHauteur, "Smooth scrolling", $80000000)
OpenWindowedScreen(WindowID(0), 0, 0, EcranLargeur, EcranHauteur, 0, 0, 0)
EndIf
;}
;___________________________________________________________
;{ Création d'une structure fil de fer de base (plan carré)
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Global Dim Sommet.Sommet(3) ; 4 sommets
For ZI = 0 To 1
For XI = 0 To 1
Index = 2 * ZI + XI
With Sommet(Index)
\P\X = XI - 0.5
\P\Y = 0.0
\P\Z = ZI - 0.5
\N\X = 0.0
\N\Y = 1.0
\N\Z = 0.0
\C = RGB(0, 0, 0)
\T\U = ZI
\T\V = XI
EndWith
Next XI
Next ZI
Global Dim Triangle.Triangle(1) ; 2 triangles
With Triangle(0)
\A = 0
\B = 2
\C = 3
EndWith
With Triangle(1)
\A = 3
\B = 1
\C = 0
EndWith
FigCarre = CreateMesh(#PB_Any, 2)
If FigCarre
Index = #PB_Mesh_Vertex
Index | #PB_Mesh_Normal
Index | #PB_Mesh_Color
Index | #PB_Mesh_UVCoordinate
SetMeshData(FigCarre, Index, @Sommet(0), 4)
SetMeshData(FigCarre, #PB_Mesh_Face, @Triangle(0), 2)
;}
;___________________________________________________________
;{ Initialisation de la caméra
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Création de la caméra
If CreateCamera(Camera, 0, 0, 100, 100)
; Préparation de la caméra
CameraLocate(Camera, 500, 500, 500)
RotateCamera(Camera, 270, 270, 0)
Result = "!Init"
EndIf
;}
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
EndIf
EndIf
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
;}
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯