mojographics issues
Closed this issue · 3 comments
I tested the new mojo integration with junglegui(sample2) on glfw + xna.
Seems that there are some issues with
- transform
- scissor
- image drawing(no or wrong images are rendered)
Here is the sample code:
Import minib3d.app
'Import minib3d.opengl.opengles20
Import mojo
Import reflection
Import junglegui
Import trans
'import folder
#REFLECTION_FILTER+="minib3d_mojo_bunnies*|junglegui*"
Function Main:Int()
New MyGame()
Return 0
End
Global gui:Gui
Class MyGame Extends MiniB3DApp
Field numBunnies:Int = 30
Field gravity:Float = 3
Field bunnies:List<Bunny>
Field maxX:Int = 640
Field minX:Int = 0
Field maxY:Int = 480
Field minY:Int = 0
Field bitmap:Image
Field fpsRate:Int = 30
Field myForm:MyForm
Field mesh:TMesh
Field cam:TCamera
Field light:TLight
Method Create:Int()
SetUpdateRate(fpsRate)
SetRender()
PreLoad("wabbit_alpha.png")
SetUpdateRate(60)
EnableAutoSize()
gui = New Gui 'We create the Gui manager.
myForm = New MyForm
try
myForm.InitForm(gui)
Catch jge:JungleGuiException
Print "Form could not be initialized becouse of an exception:"
Print jge.ToString()
End
Return 0
End
Method Init:Int()
''must add this to use mojo fonts
SetFont(LoadImage("mojo_font.png",96,Image.XPadding))
mesh = CreateMiniB3DMonkey()
'mesh.EntityFX 1
mesh.EntityColor (90,90,90)
mesh.ScaleEntity( 2,2,2)
cam = CreateCamera
cam.PositionEntity(0,0,-10)
light = CreateLight
bitmap = LoadImage("wabbit_alpha.png")
bunnies = New List<Bunny>
Local bunny:Bunny
For Local i:Int = 0 Until numBunnies
bunny = New Bunny
bunny.image = bitmap
bunny.speedX = Rnd() * 10
bunny.speedY = (Rnd() * 10) - 5
bunnies.AddLast(bunny)
Next
End
Method Update:Int()
If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error""
For Local bunny:Bunny = Eachin bunnies
bunny.x += bunny.speedX
bunny.y += bunny.speedY
bunny.speedY += gravity
If bunny.x > maxX
bunny.speedX *= -1
bunny.x = maxX
Else If (bunny.x < minX)
bunny.speedX *= -1
bunny.x = minX
End
If bunny.y > maxY
bunny.speedY *= -0.8
bunny.y = maxY
If Rnd() > 0.5
bunny.speedY -= Rnd() * 12
End
Else If (bunny.y < minY)
bunny.speedY = 0
bunny.y = minY
End
bunny.posX = bunny.x
bunny.posY = bunny.y + bunny.z
Next
If KeyHit(KEY_LEFT)
fpsRate-=5
SetUpdateRate(fpsRate)
End
If KeyHit(KEY_RIGHT)
fpsRate+=5
SetUpdateRate(fpsRate)
End
mesh.TurnEntity(0,2,0)
try
gui.Update()
Catch jge:JungleGuiException
Print "Error updating the Gui component:"
Print jge.ToString()
Error(jge.ToString())
End
Return 0
End
Method Render:Int()
SetMojoEmulation()
Cls(0, 0, 105)
FPSCounter.Update()
'Cls
For Local b:Bunny = Eachin bunnies
DrawImage(b.image, b.posX, b.posY)
'DrawRect(b.posX, b.posY, 10,10)
Next
DrawImage(GetFont(), 100,200)
FPSCounter.Draw(0,0)
SetColor(255,255,255)
DrawText("FPS Rate: "+fpsRate,100, 100)
DrawRect(1,0,1,5)
'RenderWorld()
try
gui.Render()
Catch jge:JungleGuiException
Print "Error rendering the Gui component:"
Print jge.ToString()
Error(jge.ToString())
End
Return 0
End
End
Class Bunny
Field speedX:Float = 0
Field speedY:Float = 0
Field speedZ:Float = 0
Field image:Image
Field x:Float = 0
Field y:Float = 0
Field z:Float = 0
Field posX:Float = 0
Field posY:Float = 0
Field angle:Float = 0
Field speed:Float = 0
End
Class FPSCounter Abstract
Global fpsCount:Int
Global startTime:Int
Global totalFPS:Int
Function Update:Void()
If Millisecs() - startTime >= 1000
totalFPS = fpsCount
fpsCount = 0
startTime = Millisecs()
Else
fpsCount+=1
End
End
Function Draw:Void(x% = 0, y% = 0, ax# = 0, ay# = 0)
DrawText("FPS: " + totalFPS, x, y, ax, ay)
End
End
Class MyForm extends Form
Field listBox1:ListBox
Field comboBox:ComboBox
Field listView1:ListView
Field listView2:ListView
Method OnInit()
Size.SetValues(500, 464)
Position.SetValues(DeviceWidth / 2 - 255, DeviceHeight / 2 - 232 )
'''
''' MyForm
'''
'Events.Add(Self, eMsgKinds.MOVED, "MyForm_Moved")
Self.Event_Moved.Add(Self, "MyForm_Moved")
Local label:= new Label()
label.Position.SetValues( 10,5)
label.Parent = Self
label.Text = "Item Size: "
'''
''' trackbar
'''
local trackbar:= New TrackBar
trackbar.Parent = Self
trackbar.Position.SetValues(10, 25)
trackbar.Event_ValueChanged.Add(Self, "Trackbar1_ValueChanged")
trackbar.Minimum = 48
trackbar.Maximum = 256
trackbar.Tickfrequency = 4
label= new Label()
label.Position.SetValues( 230,5)
label.Parent = Self
label.Text = "Item Spacing: "
'''
''' trackbar
'''
trackbar = New TrackBar
trackbar.Parent = Self
trackbar.Position.SetValues(230, 25)
trackbar.Minimum = 2
trackbar.Maximum = 64
trackbar.Tickfrequency = 2
trackbar.Event_ValueChanged.Add(Self, "Trackbar2_ValueChanged")
'''
''' listView1
'''
Local img1:= LoadImage("icon1.png")
local img2:= LoadImage("icon2.png")
Local map1:= LoadImage("map1.png")
Local map2:= LoadImage("map2.png")
Local map3:= LoadImage("map3.png")
listView1 = New ListView(5, 60, 470, 180, Self)
listView1.Items.AddLast( New DefaultListViewItem( "Bla" ,img1 ))
listView1.Items.AddLast( New DefaultListViewItem( "Bla" , img2 ))
listView1.Items.AddLast( New DefaultListViewItem( "Bla" ,img1 ))
listView1.Items.AddLast( New DefaultListViewItem( "Bla" ,img2 ))
listView1.Items.AddLast( New DefaultListViewItem( "Bla" ,img1 ))
listView1.Items.AddLast( New DefaultListViewItem( "Bla" ,img2 ))
listView1.Items.AddLast( New DefaultListViewItem( "Bla" ,img1 ))
listView1.Items.AddLast( New DefaultListViewItem( "Bla" ,img2 ))
listView2 = New GameListView(5, 250, 470, 180, Self)
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" ,map1 ))
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" , map2 ))
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" ,map3 ))
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" ,map1 ))
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" ,map2 ))
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" ,map3 ))
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" ,img1 ))
listView2.Items.AddLast( New GameListViewItem( "Bla Dedicated Server","Waiting for players","37.59.222.194:1234","A Path Beyond" ,img2 ))
End
Method MyEvent(sender:Object, e:EventArgs)
Print "HelloEvent"
End
Method Trackbar1_ValueChanged(sender:Object, e:EventArgs)
Self.Text = "trackbar1 value changed: " + TrackBar(sender).Value
listView1.SetItemSize(TrackBar(sender).Value,TrackBar(sender).Value )
End
Method Trackbar2_ValueChanged(sender:Object, e:EventArgs)
Self.Text = "trackbar2 value changed: " + TrackBar(sender).Value
listView1.SetItemSpacing(TrackBar(sender).Value,TrackBar(sender).Value)
End
Method MyForm_Moved(sender:Object, e:EventArgs)
Self.Text = "Moved to: " + Self.Position.X + ", " + Self.Position.Y
End
End
'################################################################
Class GameListViewItem extends ListViewItem
Private
Const WIDTH = 440
Const HEIGHT = 72
Field _lblStatus:Label
Field _lblIp:Label
Field _lblMapName:Label
Field _lblText:Label
Field _img:Image
Public
Method New(text$,status$, ip$, mapName$, img:Image)
Local boldFont:= New BitmapFont("boldFont.txt")
Local normalFont:= New BitmapFont("normal.txt")
_lblText = New Label
_lblText.Text = text
_lblText.Font = boldFont
_lblText.Parent = Self
_lblText.Position.SetValues(96,5)
_lblMapName = New Label
_lblMapName.Text = mapName
_lblMapName.Parent = Self
_lblMapName.Font = normalFont
_lblMapName.Position.SetValues(96,25)
_lblStatus = New Label
_lblStatus.Text = status
_lblStatus.Parent = Self
_lblStatus.Font = boldFont
_lblStatus.TextAlign = eTextAlign.LEFT
_lblStatus.Position.SetValues(WIDTH-5-_lblStatus.Font.GetTxtWidth(_lblStatus.Text),5)
_lblIp = New Label
_lblIp.Text = ip
_lblIp.Parent = Self
_lblIp.Font = normalFont
_lblIp.TextAlign = eTextAlign.LEFT
_lblIp.Position.SetValues(WIDTH-5-_lblIp.Font.GetTxtWidth(_lblIp.Text),25)
_img = img
Size.SetValues(WIDTH, HEIGHT )
End
Method Render:Void()
Super.Render()
Local drawpos:= CalculateRenderPosition()
'' Calculate image scaling factor
Local scale# = Min(
float(HEIGHT-8) / float(_img.Width),
float(HEIGHT-8) / float(_img.Height))
'' Draw item image
SetColor 255,255,255
DrawImage(_img,
drawpos.X + HEIGHT / 2 - float(_img.Width * scale) / 2 ,
drawpos.Y + (HEIGHT ) / 2 - float(_img.Height * scale) / 2 ,
0,scale, scale)
End
Method Text:String()
Return _lblText.Text
End
End
Class GameListView extends ListView
Method new(x%,y%, width%, height%, parent:ContainerControl )
Super.New(x,y,width, height, parent )
ItemHeight = GameListViewItem.HEIGHT
ItemWidth = GameListViewItem.WIDTH
SetItemSpacing(5,5)
End
End
if you change this method in mojographics.monkey:
Method SetMatrix( ix#,iy#,jx#,jy#,tx#,ty# )
mat.grid[0][0] = ix
mat.grid[0][1] = iy
mat.grid[1][0] = jx
mat.grid[1][1] = jy
mat.grid[3][0] = tx
mat.grid[3][1] = -ty
End
Does it work? I'm not sure what it is suppose to look like, so a simple example may help.
I can confirm that did the trick :) Anyway, I saw you pushed the change, so you found out!
About mojo emulation, I'm developing a version of the emulation mojo 'adapter' trying to decoupling it from minib3d (because I'm working in a 2d game, so I don't need all the 3d stuff). I made it work, but notice some performance issues. The scenario is, a grosso modo, Flixel + the Mojo adapter (based on your Mojo emulation). I run the bunny mark and the performance of plain Flixel+ its WebGL patch is better than using the adapter. Could you indicate me some guidelines to optimize the adapter / mojo emulation? Thanks for your work and time!
in debug mode Webgl is super slow because I am checking for glerrors, which is slow slow slow. make sure you profile in release mode.
also, the real mojo is memory efficient, mojoemulation is not. and finally, the core of miniB3D is a retained entity system, where the real mojo is draw & dump, so retained mojo would work better-- but that would be a change in API.