Code Monkey home page Code Monkey logo

minib3d-monkey's People

Contributors

adamredwoods avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minib3d-monkey's Issues

poor tanimation performance if DONT_USE_VERT_POINTER

Please have a look at tanimation...

Since animation is pretty slow, by doing vertex memory copy in monkey(slow c# databuffer), I added some native functions.This gives a nice performance boost on xna and d3d11:

void UpdateVertexDataBufferPositions(BBDataBuffer* destVertexDataBuffer, BBDataBuffer* floatBuffer, int count)
{
    B3DVertex* dest = (B3DVertex*)destVertexDataBuffer->ReadPointer();
    B3DVector* src = (B3DVector*)floatBuffer->ReadPointer();
    B3DVector* end = src + count;

    do
    {
        *(B3DVector*)dest++ = *src++;
    }
    while(src!=end);
}

...basically the same in c#

from my point of view... in the medium term, it makes sense to use same animation code on all platforms..Actually I don't like this #IF TARGET stuff...

xna/d3d11 shader - Feedback / Your oppinion...

Edit:
damn, I've ruined the repository, hope I fixed it correctly

hi,
just wanted to point out that shader support in xna is finished.
But I had to adjust the xna target in order to import Fx files properly.
It was the easiest way and therefore almost everything is automatic. What do you think?

Added it to
minib3d-monkey / xna / transcc / builders / xna.monkey

If MatchPath( r,TEXT_FILES )
                    Select ext
                    Case "fx"
                         cont.Push "  <ItemGroup>"
                         cont.Push "    <Compile Include=~q"+t+"~q>"
                         cont.Push "      <Name>"+f+"</Name>"
                         cont.Push "      <CopyToOutputDirectory>Always</CopyToOutputDirectory>"
                         cont.Push "              <Importer>EffectImporter</Importer>"
                         cont.Push "              <Processor>EffectProcessor</Processor>"
                         cont.Push "    </Compile>"
                         cont.Push "  </ItemGroup>"

Actually, the shader should now be tested. However, xna and d3d11 looks almost identical, even the monkey code. So I am considering whether it would be useful rather invest time into a translator tool, than to maintain all these redundant code...?

Edit:
just found some nice stuff:
http://blogs.unity3d.com/wp-content/uploads/2011/08/FastMobileShaders_siggraph2011.pdf

2d rendering - correct scissor/viewport

scissor / viewport does not work correctly for 2d rendering.
In opengl, 2d drawing is distorted when using viewport/scissor. xna does not implement a scissor test at all...

opengl fix:

Method UpdateCamera(cam:TCamera)

        ' viewport
        If cam.draw2D
            glViewport(0,0,DeviceWidth, DeviceHeight)
        Else
            glViewport(cam.vx,cam.vy,cam.vwidth,cam.vheight)
        End 

                '' must be turned on again somewhere 
        glEnable(GL_SCISSOR_TEST)


        glScissor(cam.vx,cam.vy,cam.vwidth,cam.vheight)
        glClearColor(cam.cls_r,cam.cls_g,cam.cls_b,1.0)

                ...

xna fix

Method SetStates(ent:TEntity, surf:TSurface, cam:TCamera )
    ...
        If cam.draw2D

            _device.RasterizerState = _rasterizerScissor
            _device.ScissorRectangle(cam.vx,TRender.height-cam.vheight-cam.vy,cam.vwidth,cam.vheight)

        Else
            ''global wireframe rendering
            If TRender.render.wireframe
                _device.RasterizerState = _rasterizerWire
            Else
                ' fx flag 16 - disable backface culling
                If _fx&16 Then 
                    _device.RasterizerState = _rasterizerStates[0] 
                Else 
                    _device.RasterizerState = _rasterizerStates[2]
                End 
            Endif
        End 
                 ...

have not yet looked into d3d ...propably the same.

xna_pixmap.ResizePixmap bug

in line 107 and 108

Local dx% = (Int(fx - x) /16)
Local dy% = (Int(fy - y) /16)

needs to be multiplied with 16 instead divided by 16

gl version is correct...

opengles20; fog error

from IceVan:

If an entity have disable fog fx then all entitys in the world have disable fog fx.

Corrected code:
' fx flag 8 - disable fog
If fx&8
'glDisable(GL_FOG)
If shader.u.fogflag<> -1 Then glUniform1i( shader.u.fogflag, 0 )
Else
If shader.u.fogflag<> -1 Then glUniform1i( shader.u.fogflag, 1 )
Endif

xna issue: blue canvas after window minimization..

After minimizing the application or 'Ctrl+Alt+Del' the canvas stays blue on xna...

Probably some resource reset is necessary if they are not created with MANAGED flag. Have not looked into it, yet.

Edit:
DeviceReset and DeviceResetting events are raised, but not implemented...

Garbage Collection Stutter with collisions?

Im doing some rudimentary testing of the collisions and im getting stuttering appearing but only when collisions are active. (im using ellipsoid-to-polygon collisions)

I have a collision set using a camera to a large floor and whilst moving the camera every other second the screen update stops, then restarts. If I turn off collisons the stutter goes away?

There is no problem with he collisions not working so I was thinking it may be teh GC getting in the way ?

CameraPick return nothing

Hi,

I've tried to compile and old game with new monkey 78h and minib3d for 78g.
Tested all around, it's CameraPick, it don't works anymore.

Enhancement: TTexture.PRESERVE_SIZE flag

Small addition to TTexture: I added a flag to TTexture, that prevents minib3d from automatic scaling. I whould like to see it in the official version, because my mojo implementation requires it, and it would be nice if it works without changes...

Class TTexture
Const PRESERVE_SIZE = 256
...


...
If tex.flags & PRESERVE_SIZE = 0 Then
pixmap=AdjustPixmap(pixmap, tex.resize_smooth)
End
...

Collision issues with ported blitz3d sample

I am trying to port max's blitz3d driver sample, but I am getting stuttering, alignment/translate and collision issues.

Here's the result and the code I have here so far with the assets:

Strict

Import minib3d.opengl.opengles20
Import minib3d.app

Class MyApp Extends MiniB3DApp
		
	Const GRAVITY#=-.1
	Const BODY%=1,WHEEL%=2,SCENE%=3

	Field Camera:TCamera
	Field Light:TLight
	Field Cube:TMesh
	
	Field terr:TMesh
	Field car:TMesh
	
	Field target:TPivot

	Field speed#=0
	Field x_vel#=0,  prev_x#
	Field y_vel#=0,  prev_y#
	Field z_vel#=0,  prev_z#

	Field dx#,dy#,dz#
	
	Field wheels:TMesh[4+1]

	Field cnt%=1
	
	Field x#
	
	Field tex:TTexture
	
	Field zx#,zy#,zz#

	Method Create:Int()
		SetUpdateRate 60
		SetRender()
		PreLoad(["terrain-1.jpg"])		
		Return 0
	End
	
	Method Update:Int()

		If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""

		If KeyDown(KEY_Q) TranslateEntity car, 0, -GRAVITY*1.5, 0	
	
		zx=(EntityX( wheels[1],True )+EntityX( wheels[2],True ))/2
		zx=zx-(EntityX( wheels[3],True )+EntityX( wheels[4],True ))/2
		zy=(EntityY( wheels[1],True )+EntityY( wheels[2],True ))/2
		zy=zy-(EntityY( wheels[3],True )+EntityY( wheels[4],True ))/2
		zz=(EntityZ( wheels[1],True )+EntityZ( wheels[2],True ))/2
		zz=zz-(EntityZ( wheels[3],True )+EntityZ( wheels[4],True ))/2
		AlignToVector car,zx,zy,zz,3

		'align car To wheels
		zx=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2
		zx=zx-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2
		zy=(EntityY( wheels[2],True )+EntityY( wheels[4],True ))/2
		zy=zy-(EntityY( wheels[1],True )+EntityY( wheels[3],True ))/2
		zz=(EntityZ( wheels[2],True )+EntityZ( wheels[4],True ))/2
		zz=zz-(EntityZ( wheels[1],True )+EntityZ( wheels[3],True ))/2
		AlignToVector car,zx,zy,zz,1

		'calculate car velocities	
		Local cx#=EntityX( car )  x_vel=cx-prev_x  prev_x=cx
		Local cy#=EntityY( car )  y_vel=cy-prev_y  prev_y=cy
		Local cz#=EntityZ( car )  z_vel=cz-prev_z  prev_z=cz
		
		'resposition wheels
		cnt=1
			For Local z#=1.5 To -1.5 Step -3
			For Local x#=-1 To 1 Step 2
				'PositionEntity wheels[cnt],0,0,0
				'ResetEntity wheels[cnt]
				PositionEntity wheels[cnt],x,-1,z
				cnt=cnt+1
			Next
		Next		

		'move car
		If KeyDown(KEY_A) TurnEntity car,0,3,0
		If KeyDown(KEY_D) TurnEntity car,0,-3,0

		If EntityCollided( car,SCENE )
			If KeyDown(KEY_W)
				speed=speed+.02 
				If speed>.7 speed=.7
			Else If KeyDown(KEY_S)
				speed=speed-.02
				If speed<-.5 speed=-.5
			Else
				speed=speed*.9
			Endif
			MoveEntity car,0,0,speed
			TranslateEntity car,0,GRAVITY,0
		Else
			TranslateEntity car,x_vel,y_vel+GRAVITY,z_vel
		EndIf
		
		If speed>=0
			dx=EntityX( target,True )-EntityX( Camera )
			dy=EntityY( target,True )-EntityY( Camera )
			dz=EntityZ( target,True )-EntityZ( Camera )
			TranslateEntity Camera,dx*.1,dy*.1,dz*1
		End If
		PointEntity Camera,car
		UpdateWorld()

		Return 0
	End
	
	Method Render:Int()		
		SetMojoEmulation()
		DrawText(speed,10,10)
		Return 0
	End
	
	Method Init:Int()

		Collisions BODY,SCENE,2,3
		Collisions WHEEL,SCENE,2,3

		Cube = CreateCube()
		Cube.PositionEntity -0.5,-2.5,8

		Light=CreateLight()
		Light.TurnEntity 45,45,0
				
		'Create Terrain
		terr = LoadMesh("terrain.b3d")
		ScaleMesh terr,100.0,100,100.0
		'PositionEntity terr,-150,0,50
		tex = LoadTexture("terrain-1.jpg")
		ScaleTexture tex,.1,.1
		EntityTexture terr,tex
		'EntityColor terr,0,125,0		
		EntityType terr,SCENE
		
		'Load Car
		car = LoadMesh("car.b3d")
		ScaleMesh car,1,1,-1
		FlipMesh car
		FitMesh car,-1.5,-1,-3,3,2,6
		PositionEntity car,0,340,0
		EntityShininess car,100
		EntityType car,BODY		

		prev_x=EntityX( car )
		prev_y=EntityY( car )
		prev_z=EntityZ( car )
		
		target = CreatePivot( car )
		PositionEntity target,0,5,-12

		Camera=CreateCamera()
		CameraClsColor Camera,0,128,255
		CameraRange Camera,0.1,20000		
		
		'Wheels		
		For Local z#=1.5 To -1.5 Step -3
			For Local x#=-1 To 1 Step 2
				wheels[cnt]=CreateSphere( 8,car )
				EntityAlpha wheels[cnt],.5
				ScaleEntity wheels[cnt],.5,.5,.5
				EntityRadius wheels[cnt],.5
				PositionEntity wheels[cnt],x,0,z
				EntityType wheels[cnt],WHEEL
				cnt=cnt+1
			Next
		Next
	
		Return 0
	End
End

Function Main:Int()
	New MyApp	
	Return True
End

Per the Blitz3D manual, entityorder needs to disable dpeth testing.

(by icevan)
Another small bug that I have fixed.

EntityOrder () does no effect.

The problem is in Render() Method of opengles11 and opengless20.

I've corrected by adding this code after glDisable(GL_ALPHA_TEST)

If ent.order<>0
glDisable(GL_DEPTH_TEST)
glDepthMask(False)
Else
glEnable(GL_DEPTH_TEST)
glDepthMask(True)
Endif

Error with EntityCollided

When checking EntityCollided() with a type that has not been created crashes.

A quick fix is :-

tentity.monkey

Method EntityCollided:TEntity(type_no)

    ' if self is source entity and type_no is dest entity
    For Local i=1 To CountCollisions()
        If CollisionEntity(i).collision.type=type_no Then Return CollisionEntity(i)
    Next

    ' if self is dest entity and type_no is src entity
    If TCollisionPair.ent_lists[type_no] <> Null Then   ' <<<<<<<<<< check if null
        For Local ent:TEntity = EachIn TCollisionPair.ent_lists[type_no]
            For Local i = 1 To ent.CountCollisions()
                If CollisionEntity(i) = Self Then Return ent
            Next
        Next
    EndIf

    Return Null

End 

TRender.ClearWorld() and TTexture.FreeTexture() contain erroneous code.

TRender.ClearWorld():

/modules/minib3d/trender.monkey<62> : Error : Identifier 'ClearList' not found.
Abnormal program termination. Exit code: -1

/modules/minib3d/trender.monkey<65> : Error : Cannot convert from {NULL} to Int.
Abnormal program termination. Exit code: -1

/modules/minib3d/trender.monkey<66> : Error : Cannot convert from {NULL} to Int.
Abnormal program termination. Exit code: -1

TTexture.FreeTexture():

/modules/minib3d/ttexture.monkey<46> : Error : Identifier 'tex' not found.
Abnormal program termination. Exit code: -1
(Resolved by changing glDeleteTextures(1,tex.gltex[0]) to glDeleteTextures(1,gltex))

/modules/minib3d/ttexture.monkey<49> : Error : Cannot convert from {NULL} to TPixmap[].
Abnormal program termination. Exit code: -1

/modules/minib3d/ttexture.monkey<50> : Error : Cannot convert from {NULL} to Int[].
Abnormal program termination. Exit code: -1

After commenting the erroneous lines out (and fixing the fourth error listed), I'm greeted with a memory access violation at runtime when calling it (only if there are entities declared).

Picking Problem (and collision)

I had a problem with the collisions not working on a floor plan I was testing.

Doing more testing and it seems is the picking that's not correct (as I presume that picking is directly related to collisions)

Heres an example - I load the floor and drop a monkey onto it. It passes straight thru. I added mouse picking and you will see that the picking is quite a way off.

The only thing to note is that the imported model is not centered, apart from that its pretty standard.

https://www.dropbox.com/s/agl3t2x7gs2w3p1/pick.zip

Occasional Error on render

Im getting a constant error in tcamera.monkey, Method EntityInFrustum#(ent:TEntity)

' is sphere in frustum

    Local d#

    If ent.frustum_cache<>0
        Local fc% = ent.frustum_cache    <<<<<<<<<<<<<<<<<
        d = frustum[fc][0] * x + frustum[fc][1] * y + frustum[fc][2] * -z + frustum[fc][3]
        If d <= -radius Then Return 0

    Endif   

ent.frustum_cache is = 6 ... which I think is incorrect as the array is 0..5 ?
If I change it to

Local fc% = ent.frustum_cache-1

I never see the error ? I might be doing something incorrect there as its beyond me but it does seem that the following code in that function sets the cache to 1..6 instead of 0..5 ?

TRender.FreeVBO never get called

I searched the project for .FreeVBO... it seems that TRender.FreeVBO never get called because TSurface.FreeVBO is not implemented/ deprecated ...

Did I miss something, or is there just no way to free surfaces??

EntityParent not working (heres the fix)

In functions.monkey

Function EntityParent(ent:TEntity,parent_ent:TEntity,glob:Int=True)

needs to be

Function EntityParent(ent:TEntity,parent_ent:TEntity,glob:Bool=True)

HTML5 Fix for Lightmapping

at line 202 in opengl/basicshadergsl.monkey replace the FRAGBLEND string with the following

Global FRAGBLEND:String = "/*blendfunc*/"+
    "vec4 BlendFunction(const float blend, const vec4 texture, const vec4 finalcolor, const vec4 vertcolorx) {"+
    "vec4 color = one_zero.yyyy;    "+
    "if (blend ==1.0) {color.xyz = mix(finalcolor.xyz, texture.xyz, texture.w );color.w = vertcolorx.a; return color;"+
    "} else if (blend ==2.0) { color = (vertcolorx * texture * finalcolor);     return color;"+
    "} else if(blend==3.0) {    color = ((color * vertcolorx) + (texture * finalcolor)); return color;"+
    "} else if(blend==4.0) {    color = (vertcolorx * texture); return finalcolor+color;"+
    "} else if(blend==5.0) {    color = (vertcolorx * texture); return finalcolor*color;"+
    "} return (texture);}"

mojographics issues

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)

minib3d_mojo

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

Calling TRender.ClearWorld() results in a crash on GLFW and Android (at least).

I'm unable to test it on iOS/Android, but on both GLFW and Android, the use of ClearWorld() causes a crash on both GLFW and Android.

GLFW: Memory access violation.
Android: Reference to Null

Here's the code; press Z after it starts to experience the crash:

Import mojo


Import minib3d

Function Main()
    New Game
End

Class Game Extends App

    Field cam:TCamera 

    Field light:TLight
    Field sphere1:TMesh

    Field txt:TText

    ' used by fps code
    Field old_ms:Int
    Field renders:Int
    Field fps:Int

    Field a:Float=0, dir:Int=0, oldTouchX:Int, oldTouchY:Int, touchBegin:Int

    Field whitebrush:TBrush


    Field init_gl:Bool = False

    Method OnCreate()
        SetUpdateRate 30
    End

    Method Init()

        If init_gl Then Return
        init_gl = True

        SetRender(New OpenglES11)


        cam = CreateCamera()
        cam.CameraClsColor(0,0,80)


        light=CreateLight(1)

        sphere1 = CreateSphere()

        txt = TText.CreateText(cam)
        'txt.NoSmooth()

        light.PositionEntity 0,3,-3
        cam.PositionEntity 0.5,1,-5

        PositionEntity sphere1,-1,0,0


        whitebrush = New TBrush
        whitebrush.BrushColor(200,200,200)
        sphere1.PaintEntity( whitebrush)

        sphere1.EntityCollision(1, COLLISION_METHOD_POLYGON, 1.0)       
        sphere1.EntityFX(2)
        sphere1.RotateEntity(145,145,0)
        sphere1.ScaleEntity(2.0,2.0,2.0)

        old_ms=Millisecs()

        'Wireframe(True)

        Print "main: intit done"
    End

    Method OnUpdate()   

        ' control camera
        Local lr:Float = KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT)
        Local ud:Float = KeyDown(KEY_DOWN)-KeyDown(KEY_UP)

        Local camin:Float = KeyDown(KEY_W)-KeyDown(KEY_S)
        Local camup:Float = KeyDown(KEY_D)-KeyDown(KEY_A)

        If TouchDown(0) And Not TouchDown(1)
            If Not touchBegin
                oldTouchX = TouchX()
                oldTouchY = TouchY()
                touchBegin = 1
            Endif
            lr = (TouchX() - oldTouchX) * 0.5
            ud = (-TouchY() + oldTouchY) *0.5
            oldTouchX = TouchX()
            oldTouchY = TouchY()
        Elseif TouchDown(1)
            If Not touchBegin
                oldTouchX = TouchX()
                oldTouchY = TouchY()
                touchBegin = 1
            Endif
            camup = (-TouchX() + oldTouchX) * 0.1
            camin = (-TouchY() + oldTouchY) *0.1
            oldTouchX = TouchX()
            oldTouchY = TouchY()
        Else
            touchBegin = 0
        Endif

        MoveEntity cam,camup,0,camin
        sphere1.TurnEntity(ud*2,lr*2,0)
        'cam.TurnEntity ud,lr,0

        cam.PointEntity(sphere1)


        If TouchDown(0)
            Local e:TEntity = cam.CameraPick(TouchX(), TouchY() )

            Local surf:TSurface = PickedSurface()
            Local v0:Int, v1:Int, v2:Int

            If surf
                v0 = surf.TriangleVertex( PickedTriangle(), 0)
                v1 = surf.TriangleVertex( PickedTriangle(), 1)
                v2 = surf.TriangleVertex( PickedTriangle(), 2)

                'Print v0+" "+v1+" "+v2

                surf.VertexColor(v0,255,0,0)
                surf.VertexColor(v1,255,0,0)
                surf.VertexColor(v2,255,0,0)

                'surf.RemoveTri( PickedTriangle)
            Endif

            If Not e Then Print "null pick" Else Print e.classname
        Endif

        txt.SetMode2D() 
        txt.SetText(fps+" fps ~nhow are you", 0,0)


        ' calculate fps
        If Millisecs()-old_ms >= 1000
            old_ms=Millisecs()
            fps=renders
            renders=0
        Endif

        If KeyDown(KEY_ESCAPE)
            ClearWorld()
        End

        UpdateWorld()

    End

    Method OnRender()
        Init()

        RenderWorld()
        renders=renders+1               

    End

End

Known Issue: HTML5 is slow in debug mode

HTML5 is slow in debug mode (Chrome browser) because checking for openGL errors is costly because of the ANGLE overhead. I won't fix this yet, because release mode avoids the glerror check and is fast.

Unsafe compile JAVA for android build

in opengles11.monkey change the function GetGLError to :- (move he retirn 0 outside the if statement)

'----

Function GetGLError:Int()
If Not DEBUG
Local gle:Int = glGetError()
If gle<>GL_NO_ERROR Then Print "**glerror: "+gle; Return 1
Endif
Return 0
End
'----

Small fix in tsprite.monkey

Need a change to tsprite.monkey

from
Function BatchSpriteParent(id:Int = 0, ent:TEntity, glob:int = True)

to

Function BatchSpriteParent(id:Int = 0, ent:TEntity, glob:Bool = True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.