Smooth scroller

You can post your code snippets here for others to use and learn from
Post Reply
User avatar
lazi
Posts: 363
Joined: Thu Feb 24, 2011 11:08 pm

Smooth scroller

Post by lazi » Tue Jan 01, 2019 9:43 pm

Non smooth text scrolling on Amiga was always an eye hurting visual effect.
Recently popped up a new upload (gfx/show/Intro-Kreation-001_OS4.lha) on Aminet made with Hollywood which presents text scrolling without perfectly smooth realization.

So I decided to share my little scroller object what uses GLGalore to achieve really smooth scrolling effect.

Feel free to use it anywhere, anyhow.

Code: Select all

@APPAUTHOR "Zoltan Lazar"
@APPTITLE "Demoscroller object"
@APPDESCRIPTION "Flickering free text scroller object"
@APPVERSION "$VER: scroller 1.0 (08-Jan-18)"
@DISPLAY {mode="fullscreen",width=640, height=480, color=#WHITE}
@REQUIRE "glgalore.hwp"
BeginDoubleBuffer(True)

demo_scroller={}
Function demo_scroller:setup()
	self.fontinfo=0
	self.text="Amiga Rulez Forever - Greetings goes to: Andreas Falkenhahn a.k.a. softwerfailure for Hollywood - Norbert Roecher a.k.a. Bit Arts for the timeless mod Wasteland - Trevor Dickinson for keeping alive and rolling forward Amiga - WhdLoad should be transferred back to the past which can alone change the future to an alternative present where more Amiga is kicking... and now start it again....                              "
	self.text=UpperStr(self.text)
	self.width=40
	self.window=0
	self.length=640
	self.pos=0
 
	self.ascii2path = Function()
							  SetFillStyle(#FILLGRADIENT,#LINEAR,#RED,#YELLOW)
							  SetFormStyle(#EDGE,#WHITE,2)
							  SetFormStyle(#ANTIALIAS)
							  SetFormStyle(#SHADOW,#GRAY,3,#SHDWSOUTHEAST)

							  SetFont(#MONOSPACE,50)
							  
							  Local f={}
							  Local tbr
							  ; 21 - 7E
							  For Local i=$21 To $7E
								  StartPath(i)
								  MoveTo(i,0,0)
								  AddTextToPath(i,Chr(i))
								  ClosePath(i)
								  ss=TextExtent(Chr(i))
								  InsertItem(f,TextExtent(Chr(i)),i)


								  tbr=CreateBrush(Nil,40,80,#WHITE)
								  SelectBrush(tbr)
								  DrawPath(i,#CENTER,ss.height)
								  EndSelect
								  CopyBrush(tbr,i,{hardware=True})
								  FreeBrush(tbr)
							  Next
							  Return(f)
						EndFunction

	self.fontinfo = self.ascii2path()

	self.sintable = {}

	For Local i=0 To 179 self.sintable[i]=Sin(Rad(i))+.5 Next

	self.draw = Function ()
					Local chars, charpos, c, x, y
					chars=Min(self.pos\self.width+1,self.length\self.width+1)
					charpos=self.pos\self.width

					For Local i=charpos-chars To charpos

					If i>=0
						c=Asc(MidStr(self.text,i,1))
						y=300
						x=self.length-self.pos+i*self.width

						If c<>32 Then DisplayBrush(c,x,y)

					EndIf

					Next
					self.pos=Wrap(self.pos+2,0,self.width*(StrLen(self.text)-1))


				EndFunction
EndFunction
demo_scroller:setup()



Repeat
		DisableLineHook()
		Cls(#WHITE)
			demo_scroller.draw()
		Flip
		EnableLineHook()
		CheckEvent
Forever

                                                               
Image

User avatar
airsoftsoftwair
Posts: 3185
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Smooth scroller

Post by airsoftsoftwair » Wed Jan 02, 2019 6:38 pm

Yes, this is possible thanks to MiniGL and TinyGL :)

User avatar
fingus
Posts: 151
Joined: Fri Sep 16, 2011 9:53 am

Re: Smooth scroller

Post by fingus » Thu Sep 12, 2019 10:21 am

You can realise a smooth scroller in rebelsdl too and you don´t need the disablelinehook:

Code: Select all

@REQUIRE "rebelsdl", {link = True}

; demo by fingus/scienide

scrolltext = 
"This is your Scrolltext powered by Hollywood and Rebelsdl! Dont forget to set the Vsync to true but beware: " ..
"Some users use NOT the standard 60Hz Vertically Frequency for their Monitor. They may have Gaming Monitors w" ..
"hich allow Vertically Frequencies above 60Hz (E.g. 100Hz, 120Hz..etc). So In that Case your Scrolltext will " ..
"be much faster! Maybe Then its better To use a timer To be sure the scrollspeed is the same on every Monitor" ..
"! But there´s an alternative: Instead of timers you can use a different Scrollspeed! In this Demo we use 1 p" ..
"ixel Scrolling per Frame (Step scrollspeed). You can surly use 0.2 Or 0.5 For slower scrolling!... .. . . . " ..
".    .   Thanks To Andreas Falkenhahn For this wonderful Hollywood-Product! O V E R   A N D   O U T ! . . . "

scrollspeed = 1 ; scroll 1 pixel per frame. Higher Value = faster. Higher values as 1 leads to stuttering.

; create scroller fadein/fadeout
CreateBrush(2, 640, 50, #BLACK)   

SelectAlphaChannel(2)            

For k = 255 To 0 Step -1
   SetAlphaIntensity(k)          
   Line(255 - k, 0, 255 - k, 49) 
Next
For k = 0 To 255 Step 1
   SetAlphaIntensity(k)         
   Line(255 + 0 + k, 0, 255 + 0 + k, 49) 
Next

EndSelect                      

ScaleBrush(2, 800, 50, True)

; create scrolltext rendering
CreateBrush(1, 7000, 50, #BLACK)
	
SelectBrush(1)
	Cls
	Print(scrolltext)
EndSelect

ScaleBrush(1, 7000, 200, False)

; do the action
BeginDoubleBuffer()
Repeat
	
	For z = 0 To 2
	
		x = 640
	
		For i = 0 To 7000 Step scrollspeed
			Cls
			DisplayBrush(1, x-i, 300)
			DisplayBrush(2, 0, 300)
			Flip(True)
		Next
	Next
Forever

User avatar
lazi
Posts: 363
Joined: Thu Feb 24, 2011 11:08 pm

Re: Smooth scroller

Post by lazi » Fri Sep 13, 2019 12:14 am

Thanks, but rebelsdl was not vailable for OS4 when I checked last time. :)

Anyway DisableLinehook() does not harm especially for every long run iteration.
Bye

Post Reply