StarWars Scroll Text

Everything related to 3D programming
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

StarWars Scroll Text

Post by StarWarsFan »

Hi PureBasic-fellows,

I am trying out PureBasic and this is my very first post here.

I have concerns with PureBasic not being able to handle older source-codes. It seems so be absolutely not downward-compatible, is it?

I have downloaded this source-code:
http://www.purearea.net/pb/download/pro ... source.zip
That source-code is from 2003, i.e. 12 years old
and I can by no means get this code to compile in the PureBasicV5.


Has anybody already converted this cool code so that I have not got to reinvent the wheel?

Constructive help highly appreciated. Many thanks in advance!
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: StarWars Scroll Text

Post by applePi »

thanks for posting this exercise.
the code works in version 3.72 also in v 3.90 from the purebasic museum in 2002, 2003
i make one step to make it run in PB v5.31 , but can't display the text normally, it is displayed at the upper of the screen. hope the sprites and memory functions experts help.
i haven't used SetMeshData since PB automatically pump the info to the mesh every time we use MeshVertexPosition or MeshVertexTextureCoordinate or MeshFace ... then FinishMesh(#True)
the SetMeshData are suitable with huge data.
the code needs the picture car2.bmp from the above file
needs v5.31, and runs partially
PS: the code are corrected for the mesh construction, but still not works correctly
PS2:note UserBuffer(0) are important: from the pb372 doc: it Changes the default rendering buffer (usually the screen) to the given #Sprite. but whats its replacement in 531?

Code: Select all

;
;
; stars war scroller
; by R.JAMES (VIRTUALYS)
; 
; Virtualys for U

InitEngine3D()
InitSprite()
InitKeyboard()

Structure car
  x.w
  y.w
EndStructure

ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0)-5, 0, 0, 0)

;OpenScreen(640, 480, 16, "")

;CreateSprite(0,512,1,#PB_Sprite_Memory)
CreateSprite(0,512,1)
;LoadSprite(1, "car2.bmp", #PB_Sprite_Memory)
LoadSprite(1, "car2.bmp")

Dim pos.car(130)
u=0
For j=0 To 3
For i=0 To 25
pos(u)\x=i*24
pos(u)\y=j*24
u+1
Next i
Next j

StartDrawing(SpriteOutput(0))
adr.l = DrawingBuffer()
pix = DrawingBufferPitch()
StopDrawing()

CreateTexture(0,  512, 512)
CreateMaterial(0,  TextureID(0))

DisableMaterialLighting(0,  1)
MaterialBlendingMode(0, 1)

Fog(RGB(0,  0, 0), 1, 100, 430)

CreateMesh(1, #PB_Mesh_TriangleList , #PB_Mesh_Static )

; constructing the mesh
MeshVertexPosition(-50,-50,0)
MeshVertexTextureCoordinate(0, 1)

MeshVertexPosition(50,-50,0)
MeshVertexTextureCoordinate(1, 1)

MeshVertexPosition(50,50,0)
MeshVertexTextureCoordinate(1, 0)

MeshVertexPosition(-50,50,0)
MeshVertexTextureCoordinate(0, 0)
  

MeshFace(0, 1, 2)
MeshFace(2, 3, 0)


FinishMesh(#True)
CreateEntity(1,  MeshID(1), MaterialID(0))

CreateCamera(0,  0, 0, 100, 100)
MoveCamera(0,  0, 0, 260)
CameraFOV(0, 30)

ScaleEntity(1,  1, 3, 1)
RotateEntity(1,   0,   -70, 0)
;RotateEntity(1,   0,   0, 90)

StartDrawing(TextureOutput(0))
adr2.l = DrawingBuffer()
StopDrawing()

AmbientColor(RGB(255,  255, 255))

Dim t$(40)
   t$(0)="Episode I"
   t$(1)=" "
   t$(2)="STARWARS SCROLLER"
   t$(3)=" "
   t$(4)=" "
   t$(5)=" "
   t$(6)="Par R.James"
   t$(7)="(VIRTUALYS)"
   t$(8)="Graphix:"
   t$(9)="VIRTUALYS"
  t$(10)=" "
  t$(11)=" "
  t$(12)="Feel this scroll...."
  t$(13)=" "
  t$(14)=" "
  t$(15)="See U soon!"
  t$(16)=" "
  t$(17)="Greets to:"
  t$(18)="Frederic Laboureur"
  t$(19)=" "
  t$(20)="and all the rest..."
  t$(21)=" "
  t$(22)=" "
  t$(23)="vv    vv     ssssss"
  t$(24)="vv    vv   ss      "
  t$(25)=" vv  vv    ss      "
  t$(26)=" vv  vv     ssssss "
  t$(27)=" vv  vv          ss"
  t$(28)="  v  v           ss"
  t$(29)="   vv       ssssss"
  t$(30)=" "
  t$(31)=" "
  t$(32)=" bye! bye!"
  t$(33)=" "
  t$(34)=" "
  t$(35)=" ............"
  t$(36)=" ............"
  t$(37)=" ............"
  t$(38)=" "
  t$(39)=" "
  t$(40)=" "
  
txt=0  

Repeat
  WindowEvent()
  ;FlipBuffers()
  ;ClearScreen(RGB(0, 0, 0))
  ExamineKeyboard()
  
  t + 1
  If t > 2
    t = 1
      StartDrawing(TextureOutput(0))
      CopyMemory(adr2 + pix, adr2, 511 * pix)
      CopyMemory(adr, adr2+511*pix, pix)
      StopDrawing()
  EndIf
  
  g.f + 0.5
  If g > =24
    g = 0
    txt=txt+1
    If txt>40
    txt=0
    EndIf
  EndIf
  
  ;UserBuffer(0)  
  For i=0 To Len(t$(txt))-1
  s=(Asc(Mid(t$(txt),i+1,1))-32)
  ClipSprite(1,pos(s)\x,pos(s)\y,24,24)
  xx=256-(((Len(t$(txt)))*24)/2)
  DisplaySprite(1,xx+i*24,-g)
  Next i
  ;UseBuffer(-1)
  
  ;RotateEntity(1, 0, 1,0,#PB_Relative)
  FlipBuffers() 
  RenderWorld()
  
  
Until KeyboardPushed(#PB_Key_Escape)

End


DataSection

Point:
Data.f -50,-50,0 
Data.f  50,-50,0 
Data.f  50,50,0 
Data.f -50,50,0 

Texturecoord:
Data.f 0.0, 1.0 
Data.f 1.0, 1.0 
Data.f 1.0, 0.0 
Data.f 0.0, 0.0 

Face:
Data.w 0,1,2
Data.w 2,3,0

EndDataSection

for those who want doc about some 3.72 functions here it is:

Code: Select all

This is doc for PB v3.72
SetMeshData()

Syntax

SetMeshData(#Mesh, Type, Data, DataLength) 
Description

Set a specific data to a #Mesh. 'Data' is the memory address of the data to be set in the #Mesh. 'DataLength' is the length its data, depending of its type. This command is mainly used in combination with CreateMesh(). 

'Type' can be one of the following values: 
  #PB_Mesh_Vertices     : 'Data' is an array of vertices, 'DataLength' is the number of elements 
  #PB_Mesh_Triangles    : 'Data' is an array of triangles, each triangle vertex is an index of the vertices array. The array @LineBreak 
                           need to be of 'word' type (.w). 'DataLength' is the number of elements 
  #PB_Mesh_UVCoordinates: 'Data' is an array of UVCoordinates, 'DataLength' is the number of elements 
  #PB_Mesh_Normals      : 'Data' is an array of Normals, 'DataLength' is the number of elements 
  #PB_Mesh_Colors       : 'Data' is an array of Colors, 'DataLength' is the number of elements 

==================================================================================
DrawingBufferPitch()

Syntax

Result = DrawingBufferPitch() 
Description

Returns the real length of one line, in bytes, of the current buffer. This is need when accessing the video memory directly to go from line to line. 

====================================================================================
DrawingBuffer()

Syntax

MemoryAddress = DrawingBuffer() 
Description

Returns the MemoryAddress of the drawing buffer. It can be directory in video memory if the output is a ScreenOutput() or SpriteOutput() and allows very fast pixel manipulation. If the 'MemoryAddress' is 0, then the direct memory access isn't available. This commands is for advanced programmers only. To get more informations about the buffer, the following commands are available: DrawingBufferPixelFormat() and DrawingBufferPitch(). 

====================================================================================
UseBuffer()

Syntax

UseBuffer(#Sprite) 
Description

Changes the default rendering buffer (usually the screen) to the given #Sprite. This means than all following DisplaySprite() like commands will be rendered on the #Sprite. To get back on the main screen buffer, use a -1 #Sprite value. 
=====================================================================================


Last edited by applePi on Sat Mar 14, 2015 6:41 pm, edited 3 times in total.
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: StarWars Scroll Text

Post by Tenaja »

StarWarsFan wrote:I have concerns with PureBasic not being able to handle older source-codes. It seems so be absolutely not downward-compatible, is it?
Fred has made a number of changes that are not backward-compatible. However, every change is clearly documented in the History (in the Help file) with color coding to indicate the type of change. In addition, every change makes the commands more consistent, so they really do improve the language.

When updating old code, look for Changed and Removed in the History file to see the updates that "break" code. There really aren't a huge number, considering all of the updates.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: StarWars Scroll Text

Post by DK_PETER »

@StarWarsFan

A simple example/solution

Code: Select all

;STAR WARS - THE SIMPLE IMITATION


InitEngine3D()
InitSprite()
InitKeyboard()

OpenWindow(0, 0, 0, 1024, 768, "SW",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0 , 0)

LoadFont(0, "Star Jedi Hollow", 46)  ; Download font here: http://www.dafont.com/star-jedi.font

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 3, 10)
CameraRange(0, 0, 500)
CameraFOV(0, 80)

CreateLight(0, $F911D2DA, 0, -10, 0, #PB_Light_Directional)
LightDirection(0, 0, -1, 0)

CreateParticleEmitter(0, 200, 200, 10, #PB_Particle_Point, 0, 0, -500)
CreateTexture(1, 10, 10)
StartDrawing(TextureOutput(1))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($FFFFFF)
FrontColor(0)
CircularGradient(5,5,4)
Circle(5,5,4)
StopDrawing()
CreateMaterial(1, TextureID(1))
MaterialBlendingMode(1, #PB_Material_Add )
ParticleMaterial(0, MaterialID(1))
ParticleEmissionRate(0, 400)
ParticleEmitterDirection( 0, 0, 0, 1)
ParticleTimeToLive(0, 1, 5)
ParticleSize(0, 0.7, 0.7)



CreatePlane(0, 50, 50, 2, 2, 1, 1)
CreateImage(0, 2048, 2048)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(0))

Restore STWA
For y = 1 To 12
  Read.s res.s
  DrawText(1024 - TextWidth(res)/2, 1024 + (y*64), res, $F211FFDA)
Next y
StopDrawing()

CreateTexture(0, 1024, 1024)
StartDrawing(TextureOutput(0))
DrawImage(ImageID(0), 0, 0, 1024, 1024)
StopDrawing()

CreateMaterial(0, TextureID(0))
MaterialBlendingMode(0, #PB_Material_Add)
MaterialFilteringMode(0, #PB_Material_Trilinear)
ScrollMaterial(0, 0, -0.01, #PB_Material_Animated)  ; simply scroll the material
CreateEntity(0,MeshID(0), MaterialID(0), 0, 0, 2)
RotateEntity(0, -30, 180, 0)

Quit.i = 0

Repeat
  
  Repeat
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow
      Quit = 1
    EndIf
  Until ev = 0

  RenderWorld()
  
  FlipBuffers()
  ExamineKeyboard()
  
Until KeyboardReleased(#PB_Key_Escape) Or Quit = 1


DataSection
  STWA:
  Data.s "Star wars scroller"
  Data.s "In a Galaxy far far away"
  Data.s "The empire has created a new"
  Data.s "and terrible weapon, which has"
  Data.s "a single purpose....."
  Data.s "To destroy all ice sculptures"
  Data.s "with a single blow."
  Data.s "------------------------"
  Data.s "Da da da daaaa daaaaaaaaa"
  Data.s "da da da daaaa daaaaaaaaaaa!"
  Data.s "da da da daaaa daaaaaaaaa"
  Data.s "da da da daaaaaaaaaa!"
EndDataSection
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: StarWars Scroll Text

Post by davido »

@DK_PETER,
Very nice example.
Thank you.
:D
DE AA EB
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: StarWars Scroll Text

Post by applePi »

Thanks DK_PETER for the good and straightforward example. just now i have noticed your code contains reference to the new Font from http://www.dafont.com/star-jedi.font , i have saved them to the Font folder gives interesting demo. Hollywood now need not to pay thousands of dollars they just try PureBasic.
i think it is hard for the new software versions to stay compatible with the past 12 years old version, this is like asking a manufacturer to make a modern car but asking him to use the same old steering system.

still the old example nagging me, its author used that lengthy way to draw the plane because there was no CreateCube, CreatePlane, ... , there is still the problem that we can't put the parts of the scrolling texts on the plane. it seems that the old UserBuffer(0) are critical: from doc: it Changes the default rendering buffer (usually the screen) to the given #Sprite.
there should be some trick
best regards
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: StarWars Scroll Text

Post by StarWarsFan »

Many thanks DK_Peter.

I have now tried long and wide, and I still can't get the thing going the way I want it to be.

If I try
to make the first example work, I can only compile it under the outdated PB-version, and only against that outdated engine.dll
A conversion failed because of the very same troubles I ran into just as applePI describes.

If I try
DK_Peter's example, I can't get it to work with the car2.bmp-charset

Argl..

DK_Peter, may I ask you or does it bother you too much? All I want is a solution with that car2.bmp charset.
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: StarWars Scroll Text

Post by DK_PETER »

@StarWarsFan

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

Structure car
  x.w
  y.w
  id.i
EndStructure

Declare.i GetLetter(Letters.s = " ")
Declare Init()

Global Dim pos.car(130)
Global im.i 

Procedure Init()
  im = LoadImage(#PB_Any, "car2.bmp")
  u=0
  For j=0 To 3
    For i=0 To 25
      pos(u)\x=i*24
      pos(u)\y=j*24
      pos(u)\id = GrabImage(im, #PB_Any, i*24, j*24, 24, 24)
      u+1
    Next i
  Next j
EndProcedure

Procedure.i GetImageLetters(Letters.s = " ")
  Protected img.i = CreateImage(#PB_Any, Len(Letters) * 24, 24, 24,  #Black)
  
  StartDrawing(ImageOutput(img))
  For i=0 To Len(Letters)-1
    s = Asc(Mid(Letters,i + 1, 1)) - 32
    DrawImage(ImageID(pos(s)\id), i * 24, 0, 24, 24)
  Next i
  StopDrawing()
  ProcedureReturn img
EndProcedure

OpenWindow(0, 0, 0, 1024, 768, "Scroller", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0, 0)
CreateCamera(0, 0, 0, 100, 100)
CameraFOV(0, 70)

Init()

CreateImage(0, 1024, 1024)
Restore STWA
For y = 1 To 12
  Read.s tx.s
  my_img = GetImageLetters(tx)
  StartDrawing(ImageOutput(0))
  DrawImage(ImageID(my_img), 512 - (ImageWidth(my_img)/2) , 512 + (y * 24))
  StopDrawing()
  FreeImage(my_img)
Next y


CreateTexture(0, 1024, 1024)
StartDrawing(TextureOutput(0))
DrawImage(ImageID(0), 0, 0, 1024, 1024)
StopDrawing()

CreateMaterial(0, TextureID(0))
MaterialBlendingMode(0, #PB_Material_Add)
MaterialFilteringMode(0, #PB_Material_Trilinear)
ScrollMaterial(0, 0, -0.04, #PB_Material_Animated)  ; simply scroll the material

CreatePlane(0, 50, 100, 2, 2, 1, 1)
CreateEntity(0,MeshID(0), MaterialID(0), 2, -20, 8)
RotateEntity(0, -30, 180, 0)


Repeat
  
  Repeat
    ev = WindowEvent()
  Until ev = 0
  
  RenderWorld()
  
  FlipBuffers()
  
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape)


DataSection
  STWA:
  Data.s "Star wars scroller"
  Data.s "In a Galaxy far far away"
  Data.s "The empire has created a new"
  Data.s "and terrible weapon, which has"
  Data.s "a single purpose.."
  Data.s "To destroy all ice sculptures"
  Data.s "in the Hoth system."
  Data.s "------------------------"
  Data.s "The glarf leader joins forces"
  Data.s "with the rebellion leader smurf,"
  Data.s "to start an uprising of sugarcains"
  Data.s "in the pool of supper!"
EndDataSection
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: StarWars Scroll Text

Post by blueb »

I was looking to parse bitmaps and ran into this.

Thanks DK_PETER for your helpful ideas, much appreciated. :D
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply