How To Fix Missing OpenAL32-dll Problem in Windows 10

Missing OpenAL32.dll problem seem to be common problem with many software.

First how the solution can’t be solved: At least in 64-bit Windows 10 grabbing just OpenAL32.dll and registering it to system with regsvr32 doesn’t work. There are some bad solutions to solve this problem. The best solution is simply grabbing the missing dll from http://www.openal.org/ and install it with the official installer it comes with.

In general, if one is missing some software component, it is best to find the official website of the missing software component and hope for the best.

Image courtesy of digitalart at FreeDigitalPhotos.net

This is how to fix the problem when setting up Monkey X installation, too.

 

Example of Own Font Class in Monkey X part 2

I decided to implement in an alternative way own font class to Monkey X to use with fonts converted with my Font 2 PNG, just to for passing time.

Check the previous post or the homepage of Font 2 PNG for format of the dat-file.

Screenshot of the program:

All you really have to understand is the simple format of the dat-file of a font to understand the source code below — and of course basic understanding of Monkey X.

Import mojo
Import brl.databuffer

Function Main()
	New MyApp
End

Class MyFont
	Field maxHeight:Int
	Field fontDat:DataBuffer
	Field gfxFont:Image
	Field scale:Float
End

Class MyApp Extends App
	
	Field gfxBG:Image
	Global font1:MyFont
	Global font2:MyFont

	Method OnCreate()
		
		' -------
		' Font 1
		' -------
		font1 = New MyFont
		font1.gfxFont = LoadImage("font1.png")
		font1.fontDat = New DataBuffer(95*4*2) ' 95 characters, for each character two 4 byte integers
		font1.scale = 1
		font1.maxHeight = 71
		font1.fontDat = DataBuffer.Load("monkey://data/font1.dat")

		' -------	
		' Font 2
		'--------
		font2 = New MyFont
		font2.gfxFont = LoadImage("font2.png")
		font2.fontDat = New DataBuffer(95*4*2) ' 95 characters, for each character two 4 byte integers
		font2.scale = 1.8
		font2.maxHeight = 43
		font2.fontDat = DataBuffer.Load("monkey://data/font2.dat")
		
		gfxBG = LoadImage("bg.jpg")
		
		SetDeviceWindow(640,480,0)
		
		SetUpdateRate(30)
	End
	
	Method OnRender()
		SetBlend AlphaBlend
		SetAlpha 1
		DrawImage gfxBG,0,0

		drawString(font1, "Testing font 1", 10, 10)
		drawString(font2, "Testing font 2", (640 - stringWidth(font2, "Testing font 2") * font2.scale) / 2, (480 - (font2.maxHeight * font2.scale)) / 2)
	End
	
	Function drawString(font:MyFont, text:String, x:Float, y:Float)
		Local len = text.Length()
		
		Local chrs:Int[]
		chrs = text.ToChars()
		
		For Local i = 0 To len - 1
			'                                 pos. in font.png                          width in pixels in font.png
			DrawImageRect font.gfxFont, x, y, font.fontDat.PeekInt((chrs[i]-32)*4*2), 0, font.fontDat.PeekInt((chrs[i]-32)*4*2 + 4), font.maxHeight,0,font.scale, font.scale,0
			x = x + font.fontDat.PeekInt((chrs[i]-32)*4*2 + 4) * font.scale
		Next

	End
	
	Function stringWidth:Int(font:MyFont,text:String)
		Local len:Int = text.Length()
		Local chrs:Int[]
		Local length:Int = 0
		
		chrs = text.ToChars()
		
		For Local i:Int = 0 To len - 1
			length = length + font.fontDat.PeekInt((chrs[i]-32)*4*2 + 4)
		Next
		
		Return length
	End

End Class

Feel free to use the code above.

 

Example of Own Font Class in Monkey X

I seem to live in the past… Monkey X programming language has evolved into Monkey2, but I’m still sometimes using Monkey X.

I made an example class to use in Monkey X with bitmap fonts converted with my Font 2 PNG. The example uses old Mojo-module, but old examples on scaling bitmap font made with Font 2 PNG will give you an idea of an alternative way to implementing this.

Next, let’s take a look at a screenshot:

Next to the code:

Import mojo
Import brl.stream
Import brl.filestream

Function Main()
	New MyApp
End

Class MyFont
	Field maxHeight:Int
	Field fontDat:Int[][]
	Field gfxFont:Image
	Field scale:Float
End

Class MyApp Extends App
	
	Field gfxBG:Image
	Global font1:MyFont
	Global font2:MyFont

	Method OnCreate()

		Local file:FileStream
		
		' -------
		' Font 1
		' -------
		font1 = New MyFont
		font1.gfxFont = LoadImage("font1.png")
		font1.fontDat = allocateArray(95,2)
		font1.scale = 1
		font1.maxHeight = 71

		file = FileStream.Open("monkey://data/font1.dat","r")
		
		For Local i:Int = 0 To 95 - 1
			font1.fontDat[i][0] = file.ReadInt()
			font1.fontDat[i][1] = file.ReadInt()
		Next				
		
		file.Close()

		' -------	
		' Font 2
		'--------
		font2 = New MyFont
		font2.gfxFont = LoadImage("font2.png")
		font2.fontDat = allocateArray(95,2)
		font2.scale = 1
		font2.maxHeight = 43

		file = FileStream.Open("monkey://data/font2.dat","r")
	
		For Local i:Int = 0 To 95 - 1
			font2.fontDat[i][0] = file.ReadInt()
			font2.fontDat[i][1] = file.ReadInt()
		Next				
		
		file.Close()
		
		gfxBG = LoadImage("bg.jpg")
		
		SetDeviceWindow(640,480,0)
		
		SetUpdateRate(30)
	End
	
	Method OnRender()
		SetBlend AlphaBlend
		SetAlpha 1
		DrawImage gfxBG,0,0

		drawString(font1, "Testing font 1", 10, 10)
		drawString(font2, "Testing font 2", (640 - (stringWidth(font2, "Testing font 2") * font2.scale)) / 2, (480 - (font2.maxHeight * font2.scale)) / 2)
	End
	
	Function drawString(font:MyFont, text:String, x:Float, y:Float)
		Local len = text.Length()
		
		Local chrs:Int[]
		chrs = text.ToChars()
		
		For Local i = 0 To len - 1
			'                               pos. in font.png          width in pixels in font.png
			DrawImageRect font.gfxFont, x, y, font.fontDat[chrs[i]-32][0], 0, font.fontDat[chrs[i]-32][1], font.maxHeight, 0 , font.scale, font.scale,0
			x = x + font.fontDat[chrs[i]-32][1] * font.scale
		Next

	End
	
	Function stringWidth:Int(font:MyFont, text:String)
		Local len:Int = text.Length()
		Local chrs:Int[]
		Local length:Int = 0
		
		chrs = text.ToChars()
		
		For Local i:Int = 0 To len - 1
			length = length + font.fontDat[chrs[i]-32][1]
		Next
		
		Return length
	End
	
	Function allocateArray:Int[][](i:Int, j:Int)
    	Local arr:Int[][] = New Int[i][]
    	
    	For Local index = 0 Until i
    	    arr[index] = New Int[j]
    	Next
    	
    	Return arr		
	End

End Class

Font 2 PNG prints the max height of the font after converting. The value is in practice just the height of the png-file.

As a reminder: Font 2 PNG produces two files, font.png and font.dat for one font. The font.dat-file holds the information for each character with two 4 byte integers, first tells the position in pixels in font, the second the width of the chatacter in pixels.

I hope this example gives you some ideas on how to use different fonts converted with Font 2 PNG.

Feel free to use the code above.

PS. I also made new version of part 1 of my Old School series demonstration in Monkey X. Video below:

From the source code in the video you’ll get an idea, how this font class could be used with Mojo2-module.

That’s it from my “hobby corner” tonight!

Old School IX

This morning I made new Old School demonstration in Monkey X. This is now 9th in the series.

Not much is changed in the code from the previous Old School demonstration. What actually required some work, was the font. As in all my Old School demonstrations, I used my Font 2 PNG program. With Mojo2-module one can use for one picture the following: “pic.png”, “pic_n.png” and “pic_s.png”. The programmer doesn’t need to worry about “_n” and “_s” versions of an image, Mojo2 takes care of them. I’ve written all I know from those extra pictures in the first old school post. I may make a better version of it in code-wise and perhaps add some extra too…

Anyway in this 9th version there are 3 versions of each character that are individual png-files.

See the magic: 🙂

I may share the Monkey X source code for these later Old School demonstrations later.

Rolling and Rotating scrolltext (Old School VIII)

I made today a little Monkey X Pro demonstration: Rolling and rotating scrolltext (Old School VIII). Now it works perfectly. Like in Old School VII, the letters fade in and out at the bottom of the circle of letters. I have used my Font 2 PNG program to grab individual characters of a ttf-font to png-images for the program. Perhaps I will later share the source code of the demonstration…

Enjoy the nostalgia! 🙂

The idea behind the code of the rolling and rotating scrolltext:

  • At every update frame 30 characters (png-images) from the scrolltext are drawn in a form of a circle, each character with 12 degrees step (12 *30 = 360), let angle related to this angle be angle1
  • When drawing the character images, the angle that increases in 12 steps is added to each character in addition to this angle is added other angle variable, let this be angle2, that is decreased (the direction of rolling and rotating) by 1 degrees at every update frame
  • Because of my (probably clumsy but working 🙂 )implementation:
If angle2 Mod 12 = 0 Then
  angle2 = angle2 + 12
  scrollTextOffset = scrollTextOffset + 1
Endif
  • in DrawImage method rotation angle is angle1 + angle2 + constant that adjusts the letters to the right place on the circle

As to he fade out and fade in for the letter images, you may adjust the letters with alpha values as you best you see it is sensible, probably somewhere at the bottom of the circle.

That’s it! Do try to make make your own version with programming language of your choice. I recommend my Font 2 PNG program for the font.

Good luck!

The first time I saw this kind of effect created was some time in the late 80s on Amiga in following demo:

Ah! Those good old Amiga demos. Kind of magic at their time.

Old School VI 2 and VII Videos

I recently made version 2 from my poor Old School VI video. Today I got finished Old School VII video. Both demonstrations are programmed in Monkey X Pro. VII has that nice demo scene style synth music like Old School V. 🙂

In the Old School VII the the new letters fade in to the screen as the scroll text goes on and when the letters have gone the whole circle, they fade out…

Let the nostalgia flow through you!

First Old School VII:

…then Old School VI 2

I hope you enjoy the videos!

Scaling ttf-font in Monkey2

In Monkey2 programming language it is possible to load ttf (and otf & fon) font directly and use the DrawText method of canvas to draw the text. But how to scale the font? In this example I made today it is done in a clumsy way, but may give you some ideas…

The source code:

Namespace myapp

#Import "IMG_0648.JPG"
#Import "transparent.png"

#Import "<std>"
#Import "<mojo>"

Using std..
Using mojo..


Class MyWindow Extends Window
	
	Const RAD:Double = Pi / 180	' 1 degreen in radians
	
	Field gfxBG:Image
	Field gfxTransparent:Image	' Just an transparent image where the text is drawn
	Field fontCanvas:Canvas		' Canvas for transparent image
	Field scaleVar:Float
	Field scale:Float			' Text scale (scales the "gfxTransparent")

	Method New( title:String="Scaling font in Monkey2",width:Int=800,height:Int=600,flags:WindowFlags=Null )
		Super.New( title,width,height,flags )
		
		gfxBG = Image.Load("asset::IMG_0648.JPG")

		' Load a 100 x 48 transparent image
		gfxTransparent = Image.Load("asset::transparent.png")		
		gfxTransparent.Handle = New Vec2f(0, 0)

		' Make a canvas from the transparent image to render the text to...
		fontCanvas = New Canvas(gfxTransparent)
		fontCanvas.Font = Font.Load("asset::SpeedballNo2NF.ttf", 21)
		fontCanvas.Color = Color.Yellow
		fontCanvas.DrawText("Sample Text",(100 - fontCanvas.Font.TextWidth("Sample Text")) / 2, 1)
		fontCanvas.Flush()		

		scale = 1
		scaleVar = 0
	End

	Method OnRender(canvas:Canvas) Override
	
		App.RequestRender()

		canvas.DrawImage(gfxBG, 0, 0)
		
		scaleVar = scaleVar + RAD * 2
		scale = 4 - Sin(scaleVar) * 1.5	' This the scale (if scale = 1, no scaling)
				
		' The text is scaled and centered
		canvas.DrawImage(gfxTransparent, (800 - 100.0 * scale) / 2, (600 - 48.0 * scale) / 2, 0, scale, scale)

		canvas.Flush()
		
	End

End

Function Main()
	New AppInstance
	New MyWindow
	App.Run()
End

Below is the video related to this post:

Feel free to use my code!

Scrolling of Picture Larger Than Visible Area in Monkey2

I finally today made my first Monkey2 app. I think it was someday in September I finally noticed that Monkey X has evolved into hugely more advanced programming language: Monkey2.

As I wrote in previous post I have an unfinished game project in Monkey X Pro. I think think I’ll finish it someday in Monkey2… I have one other little project in my mind to be done in Monkey2.

This is why I decided to try to make my first Monkey2 program today. In my older post I wrote a  short tutorial on scrolling a picture larger than visible area in Monkey X Pro keeping Android target in mind. In this post the same thing is written in Monkey2 to desktop.

The picture is scrolled with mouse, to change the code to touch screen, just change the mouse related code to touch related code.

Source code below:

' Scrolling of pre-loaded picture that is larger than the visible area in Monkey2
'

Namespace myapp

#Import "bg1280x960.png"
#Import "<std>"
#Import "<mojo>"

Using std..
Using mojo..

Class MyWindow Extends Window

	Field gfxBG:Image
	Field scrollX:Float
	Field scrollY:Float
	Field touchX:Float
	Field touchY:Float
	Field touchXD:Float
	Field touchYD:Float
	Field prevTX:Float
	Field prevTY:Float
	Field scroll:Bool
	
	Method New( title:String="Scrolling...",width:Int=800,height:Int=600,flags:WindowFlags=Null )
		Super.New(title,width,height,flags )
		gfxBG = Image.Load("asset::bg1280x960.png")
	End
	
	Method OnRender( canvas:Canvas ) Override
	
		App.RequestRender()

		If scrollX > 0 Then scrollX = 0
		If scrollX < -(1280 - 800) + 1 Then scrollX = -(1280 - 800) + 1
		If scrollY > 0 Then scrollY = 0
		If scrollY < -(960 - 600) + 1 Then scrollY = -(960 - 600) + 1
		
		canvas.DrawImage(gfxBG,scrollX, scrollY)
		
	End
	
	Method OnMouseEvent( event:MouseEvent ) Override
	
		touchX = Mouse.X
		touchY = Mouse.Y
					
		If Mouse.ButtonDown(MouseButton.Left) Then
			
			If scroll = True Then

				' touchXD & touchYD variables prevent the picture
				' to "jump", if scrolling is stopped and user then
				' touches somewhere on the screen				

				touchXD = touchX
				touchYD = touchY
				
			Else
				' if not scrolling, values below are set to zero,
				' because when the scrolling starts again, otherwise
				' scrollX & scrollY could change too much because of
				' values of previous scrolling
								
				touchXD = 0
				touchYD = 0
				prevTX = 0
				prevTY = 0
			
			Endif
			
			scroll = True
				
			scrollX = scrollX - (touchXD - prevTX)
			scrollY = scrollY - (touchYD - prevTY)
			
			prevTX = touchX
			prevTY = touchY

		Else
			scroll = False			
		Endif

	End
		
End

Function Main()

	New AppInstance	
	New MyWindow
	
	App.Run()
End

Video below demos the source (the text in the video is in video only, though):

https://youtu.be/U9DLogNGeoo

Below is a video from the mentioned older blog post written in Monkey X Pro to Android:

Feel free to use my code as you wish.