Ogre and smooth scrolling

Just starting out? Need help? Post your questions and find answers here.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Ogre and smooth scrolling

Post by Ollivier »

Hello!

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
;}
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Runs fine on my computer! :)

- Pentium D 3.0GHz
- NVIDIA GeForce 6700 XL
- Windows XP SP3
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Thank you Fluid byte.

It's strange cause, on my computer it's fine too:

- 1 GHz (old)
- VIA Chrome9 AC3 IGP (old)
- XP HE (old)

But, Djes has this very strange message :
Image
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

Runs fine on my computer! Smile

- AMD Athlon 64 3500+ 2.2GHz
- NVIDIA GeForce 6600
- Windows XP SP3
________________
Goos E
New User
New User
Posts: 6
Joined: Sun Mar 15, 2009 2:55 pm
Location: Netherlands

Post by Goos E »

Runs fine on my computer too.

Win XP SP3
AMD processor
NVidea Mobility Radion X700 xl
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Thank you Demivec and Good E.

I suppose it's perhaps the LoadTexture() statement which fails in any way. Its loading path is managed by Add3DArchive() and I don't reach to have a standard path.

Ollivier
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

Works also fine with GeForce Fx5500 and Intel P4... and ... cool fx!!
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Thank you Dige!

The problem with this method is the fact it's not for all the configurations. When it's fine, it's often better than using sprites, but when there is problem, it's a big and unmanagable problem...

Ollivier
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

It runs fine here except when i move to right or left at full speed the stars aren't drawn at the opposite side. Problably because you are using the Desktop resolution and i have a widescreen tft at 1920*1200 here.
irc://irc.freenode.org/#purebasic
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Ollivier wrote:Thank you Fluid byte.

It's strange cause, on my computer it's fine too:

- 1 GHz (old)
- VIA Chrome9 AC3 IGP (old)
- XP HE (old)

But, Djes has this very strange message :
Image
I have the same problem :?
Strange no :lol:

Perhaps i have not load or checked something :roll:
You know me :D
ImageThe happiness is a road...
Not a destination
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Works fine here too. Nice effect, I like it. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

2 PB

Thank you! I try to have the best compatibility.

2 Kcc and Deeem2031

I copy and explain the real problem I met to keep compatibility on all the configurations, here.
Post Reply