miniB3D: monkey 3d engine - part6

Monkey Programming Forums/User Modules/miniB3D: monkey 3d engine - part6

AdamRedwoods(Posted 2013) [#1]

minib3d+monkey
Latest update v0.39

Download:
https://github.com/adamredwoods/minib3d-monkey

Win8 target:
https://github.com/sascha-schmidt217/minib3d-monkey

**THREAD CONTINUES HERE: http://monkeycoder.co.nz/Community/posts.php?topic=5703

Thread continued from:
http://monkeycoder.co.nz/Community/posts.php?topic=4396




notes:
- current branch: v0.39 requires Monkey V68+
- tested on glfw, android, macos, ios, xna, webgl, flash

Works:
- normals
- textures, mipmaps
- vertex buffers
- sprites
- batch sprites
- context handling for mobile devices
- pick
- collisions
- binary load for b3d files (base64)
- animation, bone & vertex
- Load OBJ
- animated textures
- XNA, Win8 target (courtesy of Rone)
- HTML5 (webGL)
- Shaders
- normal mapping (opengl2.0)
- MDD/PC2 animation loaders
- Ouya target

To Do:
- collada
- Flash
- bones to quat/matrix internals
- glow shaders, shadows
- physics
- terrain






AdamRedwoods(Posted 2013) [#2]
****************************************
minib3d v0.35

- Added: CameraScissor(x,y,w,h) -- allows clipping region for cameras
- Added: SetMojoEmulation() -- Allows mojo 2D commands in OnRender
notes:
-xna Cls() function clears whole screen (may need better way?)
- mojo readpixel/writepixel won't work (but minib3d read/write pixels for tpixmap works ok)
- not all blend modes work
- see bunnies demo for use (must preload images as tpixmap for html5)

- bug fixes: objloader, fog, entityorder depth, more


Xaron(Posted 2013) [#3]
Greeeeat stuff! :) Thanks Adam!


Rone(Posted 2013) [#4]
nice
did not know that this works
format_code('
Extern
Class MojoEmulationDevice Extends GraphicsDevice
')


EdzUp(Posted 2013) [#5]
Now with the fix I get this
format_code('
BUILD SUCCESSFUL
Total time: 1 minute 1 second
Starting: Intent { cmp=com.monkey/.MonkeyGame }
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
I/[Monkey](20969): **OPENGL VERSION:1.1
I/[Monkey](20969): ..max textures:11
I/[Monkey](20969): Monkey Runtime Error : length=0; index=0
I/[Monkey](20969): /Volumes/8GIG/Linux/MonkeyPro69/modules/minib3d/tmodelobj.monkey<138>
I/[Monkey](20969): /Volumes/8GIG/Linux/MonkeyPro69/modules/minib3d/tmodelobj.monkey<68>
I/[Monkey](20969): /Volumes/8GIG/Linux/MonkeyPro69/modules/minib3d/tmesh.monkey<238>
I/[Monkey](20969): /Volumes/8GIG/Linux/MonkeyPro69/modules/minib3d/tmesh.monkey<209>
I/[Monkey](20969): /Volumes/8GIG/Linux/MonkeyPro69/modules/minib3d/functions.monkey<921>
I/[Monkey](20969): /Volumes/8GIG/A.I/AI.monkey<53>
I/[Monkey](20969): /Volumes/8GIG/A.I/AI.monkey<76>
I/[Monkey](20969): /Volumes/8GIG/Linux/MonkeyPro69/modules/mojo/app.monkey<60>
E/AndroidRuntime(20969): FATAL EXCEPTION: main
E/AndroidRuntime(20969): java.lang.StringIndexOutOfBoundsException: length=0; index=0
E/AndroidRuntime(20969): at com.monkey.c_TModelObj.m_ParseObj(MonkeyGame.java:12745)
E/AndroidRuntime(20969): at com.monkey.c_TModelObj.m_LoadMesh(MonkeyGame.java:13012)
E/AndroidRuntime(20969): at com.monkey.c_TMesh.m_LoadAnimMesh(MonkeyGame.java:9154)
E/AndroidRuntime(20969): at com.monkey.c_TMesh.m_LoadMesh(MonkeyGame.java:9427)
E/AndroidRuntime(20969): at com.monkey.bb_functions2.g_LoadMesh(MonkeyGame.java:17635)
E/AndroidRuntime(20969): at com.monkey.c_AIApp.p_Init(MonkeyGame.java:2775)
E/AndroidRuntime(20969): at com.monkey.c_AIApp.p_OnUpdate(MonkeyGame.java:2802)
E/AndroidRuntime(20969): at com.monkey.c_GameDelegate.UpdateGame(MonkeyGame.java:2953)
E/AndroidRuntime(20969): at com.monkey.BBGame.UpdateGame(MonkeyGame.java:559)
E/AndroidRuntime(20969): at com.monkey.BBAndroidGame.UpdateGame(MonkeyGame.java:1205)
E/AndroidRuntime(20969): at com.monkey.BBAndroidGame$GameTimer.run(MonkeyGame.java:791)
E/AndroidRuntime(20969): at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime(20969): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(20969): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(20969): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(20969): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(20969): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(20969): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(20969): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(20969): at dalvik.system.NativeStart.main(Native Method)
E/InputDispatcher( 479): channel '41861690 com.monkey/com.monkey.MonkeyGame (server)' ~ Channel is unrecoverably broken and will be disposed!
')

I cant tell if we are getting closer or what :D


bruZard(Posted 2013) [#6]
great work ... i love MojoEmulation!!!


slenkar(Posted 2013) [#7]
Im trying it in linux, I get some opengl errors


../main.cpp:3892:47: error: â&#128;&#152;glDeleteBuffersâ&#128;&#153; was not declared in this scope

for every opengl command


Landon(Posted 2013) [#8]



AdamRedwoods(Posted 2013) [#9]
Now with the fix I get this


fixed. updated tmodelobj.monkey on GitHub.

Im trying it in linux, I get some opengl errors

Sorry, i don't have linux installed anywhere here (on my todo list), but sounds like its not importing the gl ext headers. i look in Monkey/modules/opengl/native/gles11.glfw.cpp and sure enough it only hooks the standard calls for win32. at the top of that file, i'd try:
format_code('#ifdef __linux__
#include <GL/glext.h>
#endif')
but that's all i can offer for now.


slenkar(Posted 2013) [#10]
didnt work unfortunately, but thanks for tryin


StoneFaceEXE(Posted 2013) [#11]
When I try to CreatePlane() it tells me that I can't create it on a TMesh variable, it requires an INT variable for some unknown to me reason )
I guess it's a bug I've been whitnessing for 3-5 patches ^_^


StoneFaceEXE(Posted 2013) [#12]
I guess PreLoad() function is not available if your app is not extending MiniB3Dapp - no integration with 3rd party frameworks? (


AdamRedwoods(Posted 2013) [#13]
I guess PreLoad() function is not available if your app is not extending MiniB3Dapp - no integration with 3rd party frameworks?

TPixmap.PreLoad(file)
I think the FirePaint3D example does not extend minib3dapp.

RE: CreatePlane()
i don't think CreatePlane works, do you mean CreateGrid(x,y)?
i should remove CreatePlane, because even if i implemented it the vertex lighting on it will look like junk. Use CreateGrid and scale it.


bruZard(Posted 2013) [#14]
TPixmap.PreLoad() doesn't work for images (MojoEmulation) outside the main class


Image not found




AdamRedwoods(Posted 2013) [#15]
The way TPixmap.PreLoadPixmap() works is that it needs to be called continuously. I've thought about using an Async event instead, but haven't thought there'd be a need.

This is the example if you do NOT extend MiniB3DApp.

skeleton example:
format_code('

Function Main()
New Game
End

Class Game Extends App

Field init_gl:Bool = False

Method OnCreate()

SetRender()
SetUpdateRate 30

End

Method Init()

If init_gl Or Not TPixmap.PreLoadPixmap(["Zombie.jpg","mojo_font.png"]) Then Return
init_gl = True

Print "main: init done"
End

Method OnUpdate()

If Not init_gl Then Return
Print "Main Update Routine"
End

Method OnRender()
Init()
If Not init_gl Then Return
Print "RenderWorld and Mojo"
End

End
')

Why do it this way?
I tried to create a solution to allow flexibility to those who want to take it a step further and TPixmap.PreLoadPixmap() a font or splash screen and then start another TPixmap.PreLoadPixmap() for more image and texture files.

If you extend MiniB3DApp
if you use "Import minib3d.app", you only use PreLoad() in Method OnCreate(). Splash screens currently don't really work with this, I've still been working on a solution.

This is all a work in progress.


bruZard(Posted 2013) [#16]
the problem is: i can't load all assets on application init ... i must load assets at runtime.


EdzUp(Posted 2013) [#17]
Can't you create the variables for the assets then load them at runtime, this works for images I haven't tried it for textures.


bruZard(Posted 2013) [#18]
I use states and every state use his own data which will load when the state is initiated

format_code('
Strict

Import minib3d
Import mojo

Class Test Extends App
Method OnCreate:Int()
SetUpdateRate(30)
SetRender()

Self.e = New Ext()
Self.state = 1

Return 0
End

Method OnUpdate:Int()
Select Self.state
Case 1
Self.e.Update()
End
Return 0
End

Method OnRender:Int()
Select Self.state
Case 1
Self.e.Render()
End
Return 0
End

Field state:Int
Field e:Ext
End

Class Ext
Method New()
Self.ready = False
End

Method Init:Int()
If Self.ready Or Not TPixmap.PreLoadPixmap(["image.jpg"]) Then Return 0
Self.ready = True
Self.myImg = LoadImage("image.jpg")
Return 0
End

Method Update:Int()
If Not Self.ready Return 0
Return 0
End

Method Render:Int()
Self.Init()
If Not Self.ready Return 0

SetMojoEmulation()
DrawImage(Self.myImg, 0, 0)

Return 0
End

Field ready:Bool
Field myImg:Image
End

Function Main:Int()
New Test()
Return 0
End
')

this will not work


EdzUp(Posted 2013) [#19]
Firstly move the PreLoadPixmap into the Oncreate function then you should thoretically be able to load the textures when required and release them when they arent. The PreLoadPixmap command loads it all in so things like HTML5 can see it IIRC, by calling it when your state is created its not going to find it as it wasnt loaded at startup.


bruZard(Posted 2013) [#20]
Thats terrible ... you say i have to preload 50MB gfx in OnCreate() ? I think that cannot be the way.


IceVAN(Posted 2013) [#21]
Hi Adam

Good work!

EntityOrder now work ok, but... need a little fix

In entity order function :

This replace all FX flags!
format_code('
if order<>0
EntityFX 64
end
')

fixed code ;)
format_code('
if order<>0
brush.fx = brush.fx|64
end
')


Bye!


bruZard(Posted 2013) [#22]
Ok ... it works :-D ... you just need an RenderWorld() in OnRender() ... *phew*

1. Mainfile
format_codebox('
Strict

Import minib3d
Import mojo
Import includes.intro

Const STATE_INTRO:Int = 1


Class BNB Extends App
Public
Method OnCreate:Int()
SetRender()
SetUpdateRate(30)

Self.state = STATE_INTRO
Self.intro = New Intro()

Return 0
End

Method OnUpdate:Int()
Select Self.state
Case STATE_INTRO
Self.intro.Update()
End
Return 0
End

Method OnRender:Int()
Select Self.state
Case STATE_INTRO
Self.intro.Render()
End

RenderWorld()

Return 0
End

Private
Field intro:Intro
Field state:Int
End

Function Main:Int()
New BNB()
Return 0
End
')

2. the state
format_codebox('
Strict

Import minib3d
Import mojo

Class Intro
Public
Method New()
Self.ready = False
End

Method Init:Int()
If Self.ready Or Not TPixmap.PreLoadPixmap(["gfx/sedm.jpg"]) Return 0
Self.ready = True
Self.sedm = LoadImage("gfx/sedm.jpg")

Return 0
End

Method Update:Int()
If Not Self.ready
Self.Init()
Return 0
EndIf

Self.ratio = Float(DeviceWidth()) / 1080.0

Return 0
End

Method Render:Int()
If Not Self.ready Return 0
SetMojoEmulation()

DrawImage(Self.sedm, 0, 0, 0.0, Self.ratio, Self.ratio)

Return 0
End

Private
Field sedm:Image
Field ratio:Float
Field ready:Bool
End
')

Live:
http://www.sedm.de/test


IceVAN(Posted 2013) [#23]
Strange error in html5?!

If I run my program from monkey. all is well.
but if I open the. html gives this error ...

format_code('
WebGL 1.0 (OpenGL ES 2.0 Chromium)
**WEBGL 1

..FullShader success
Monkey Runtime Error : Error: SecurityError: DOM Exception 18
C:/MonkeyPro70/modules/minib3d/opengl/opengles20.monkey<1333>
C:/MonkeyPro70/modules/minib3d/trender.monkey<490>
C:/MonkeyPro70/modules/minib3d/opengl/opengles20.monkey<1366>
C:/MonkeyPro70/modules/minib3d/trender.monkey<234>
C:/MonkeyPro70/modules/minib3d/functions.monkey<1136>
C:/MonkeyPro70/modules/minib3d/app.monkey<91>
C:/MonkeyPro70/modules/mojo/app.monkey<71>
')

Uncaught Error: SecurityError: DOM Exception 18 <-- in Chrome Console


bruZard(Posted 2013) [#24]
@IceVan: it's normal ... read this: http://stackoverflow.com/questions/2704929/uncaught-error-security-err-dom-exception-18-when-i-try-to-set-a-cookie


IceVAN(Posted 2013) [#25]
@bruZard: ummm... Outch! I'm obfuscated XDD.
Thanks!


AdamRedwoods(Posted 2013) [#26]
Uncaught Error: SecurityError: DOM Exception 18 <-- in Chrome Console

yes, that's why Monkey includes MServer.


AdamRedwoods(Posted 2013) [#27]
In entity order function :

This replace all FX flags!

thanks for finding that, i seem to always be doing that.


bruZard(Posted 2013) [#28]
Next issue: my mesh works fine with Blitz3D, but i get an "glerror 1282" in miniB3D

http://www.sedm.de/test/mesh.zip


bruZard(Posted 2013) [#29]
ok ... i was too euphoric ... all action in one class works, but loading at runtime doesn't. Loading images at runtime for DrawImage() works ... but only for HTML5, on Android i get an "out of memory". It's really frustrating ...


AdamRedwoods(Posted 2013) [#30]
Next issue: my mesh works fine with Blitz3D, but i get an "glerror 1282" in miniB3D

if i change testtex from a jpg to png, preload it, it works.


Rex Rhino(Posted 2013) [#31]
Tried the latest version with Bunnies demo - The image transparency isn't working on XNA.


AdamRedwoods(Posted 2013) [#32]
Tried the latest version with Bunnies demo - The image transparency isn't working on XNA.

So true! Fixed xna files on GitHub. Thanks!


EdzUp(Posted 2013) [#33]
how do we use mojo with minib3d I put the DrawImage after the renderworld but nothing happened, is there a certain way of doing things?

EDIT: it now works perfectly with android :) looks brilliant on me Nexus 7 :) I still cant get mojo to work with it though any help on that score would be appreciated :)


bruZard(Posted 2013) [#34]
AntiAlias() doesn't work.


AdamRedwoods(Posted 2013) [#35]
Q: how do we use mojo with minib3d?
format_code('Method OnRender()
SetMojoEmulation()
DrawImage(my_image, x, y)
RenderWorld()
ENd')

Q: AntiAlias() doesn't work.

no, not at this time since opengles1.1 does not allow it.


Rex Rhino(Posted 2013) [#36]
Hey Adam,

Thanks for fixing that XNA bug! Awesome work!


Rex Rhino(Posted 2013) [#37]
Hey, just wondering if anyone can help with a little problem I am having:

I just incorporated minib3d into my code (it is a big project, too big to post all the source code unfortunately).

I have it rendering the 3D OK, and the drawing commands are working (so I can draw lines, pixels, etc., on top of the 3D).

But images are not being drawn. No error message or anything, they just aren't there. I have tried using the bunny image from the demo (to make sure it wasn't a problem with my images), I have use the following command to preload the image:
format_code('PreLoad("graphics/bunny.png")')

Here is my render loop:
format_code('
SetMojoEmulation()
SetColor 255, 255, 255
g.backgroundSpace.render(g)
SetAlpha 1.0
SetBlend(AlphaBlend)
DrawImage(g.images.Get("bunny"), 100, 100)
DrawText("test",100, 100)
RenderWorld()
')

I have also called "SetRender()" in OnCreate.

Obviously I am missing something, because the bunny demo works perfectly for me now... I am probably forgetting something obvious, but I just can figure it out.

Does anyone have any suggestions or insight on what might be the problem?


AdamRedwoods(Posted 2013) [#38]
test to make sure your resource manager is getting the image, by using Width()
format_code('
Print g.images.Get("bunny").Width()
')
If width is 0 then the resource mapping isn't finding it.

Plus, it could be a problem with the extra folder, if your resource manager needs it Get("graphics/bunny") versus just Get("bunny").


EdzUp(Posted 2013) [#39]
@Adam: Thanks for that will give it a go :)


blabz(Posted 2013) [#40]
I'm rendering to a HTML5 canvas, and resizing the canvas, how can I make minib3d render to the size of the new canvas?

Or how can I set the graphic width and height of minib3d?


blabz(Posted 2013) [#41]
Nvm, Got it!


Landon(Posted 2013) [#42]
Checked out this latest update.

you sir are a boss!


Midimaster(Posted 2013) [#43]
I downloaded the zip file of midb3d and tested the examples on HTML5 target.

When executing "minib3d_collision_test.monkey", this error message appeared:

Image Not Found: monkey://data/mojo_font.png
Font file not found.


When executing "pick_collision_test.monkey", this error message appeared:


Image Not Found: monkey://data/mojo_font.png
Font file not found.
Monkey Runtime Error : TypeError: dbg_array(...)[dbg_index] is null
C:/MonkeyPro69/modules/minib3d/ttext.monkey<280>
C:/MonkeyPro69/modules/minib3d/examples/pick_collision_test.monkey<67>
C:/MonkeyPro69/modules/minib3d/examples/pick_collision_test.monkey<98>
C:/MonkeyPro69/modules/mojo/app.monkey<60>



AdamRedwoods(Posted 2013) [#44]
When executing "pick_collision_test.monkey", this error message appeared

Yeah, i haven't updated that with the font preloader yet...


Rex Rhino(Posted 2013) [#45]

test to make sure your resource manager is getting the image, by using Width()
Print g.images.Get("bunny").Width()

If width is 0 then the resource mapping isn't finding it.

Plus, it could be a problem with the extra folder, if your resource manager needs it Get("graphics/bunny") versus just Get("bunny").



The width being returned is definitely correct... The image has been properly loaded and referenced. It just isn't being drawn to the screen.

Also, the default font for DrawText is not working... That font image is loaded automatically correct?

So something is going on that it will draw shapes like lines, circles, etc., but not bitmaps.

UPDATED INFO:

Aha! If you call any drawing commands BEFORE you call SetRender(), drawing commands no longer work (even after you call SetRender()).

I had a preloader with splash screen that was drawing to the screen before the 3D section, which then messed up subsequent drawing functionality.


Rex Rhino(Posted 2013) [#46]
Sorry to be bombarding the forum with all these questions...

Now that I have 2D and 3D working together wonderingly, I experimented with taking out the PreLoad() on my images, and everything still seemed to work just fine.

What exactly is PreLoad() needed for? I thought it was needed for all 2D graphics, but apparently I am wrong.


Rex Rhino(Posted 2013) [#47]
OK, I think I discovered a bug.

Before using just just 2D, my translate statement was this:

format_code('
Translate(0, ScreenOffset)
')

In order to get it working like before, I have to change it to this:

format_code('
Translate(0, -ScreenOffset)
')

I think there is a bug in your code that reverse the y axis for translate.


AdamRedwoods(Posted 2013) [#48]
What exactly is PreLoad() needed for?

HTML5 target only. If I can get Flash11 target working, you would need it for that.

The other reason you may want to preload, is if you are loading a lot of assets. PreLoad() loads TPixmaps into memory. LoadTexture() and LoadImage() load into video memory.


I think there is a bug in your code that reverse the y axis for translate.

probably, i'll double-check. thanks for finding this.


bruZard(Posted 2013) [#49]
How can i free a sprite (or something) from video mem? After FreeEntity() my sprite is still visible....


AdamRedwoods(Posted 2013) [#50]
How can i free a sprite (or something) from video mem? After FreeEntity() my sprite is still visible....

Does the entity disappear? it should.
To remove the sprite from video memory, you'll need to FreeTexture(). This is because if you free one sprite that is using an image from an atlas, you don't want to free the texture if other sprites are still using it.


bruZard(Posted 2013) [#51]
The sprite doesn't disappear after FreeEntity().
how can i get the texture of the sprite to free them?


AdamRedwoods(Posted 2013) [#52]
how can i get the texture of the sprite to free them?

texture = mysprite.GetSurface(1).Texture()

the above only works with surfaces that have one texture


bruZard(Posted 2013) [#53]
doesn't work

format_code('
Local tex:TTexture = Self.bg.GetSurface(1).Texture()
If tex <> Null FreeTexture(tex)
')

"tex" is Null


bruZard(Posted 2013) [#54]
my fail .... without a following RenderWorld() you think FreeEntity() doesn't work ;)


AdamRedwoods(Posted 2013) [#55]
doesn't work

I'l be darned, i forgot to add in a GetTexture() for TMesh....

for now just use
texture = mysprite.brush.GetTexture()

and note that field "brush" is not guaranteed to all meshes, so for now, keep it with sprites. i'll add a GetTexture(tex_num:Int=0) command for TMesh to solve this.


bruZard(Posted 2013) [#56]
ok, thank you!


StoneFaceEXE(Posted 2013) [#57]
I'm not sure but it seems images made via GrabImage do not render.


Midimaster(Posted 2013) [#58]
Is this a bug or a new feature?

The behavior of childrens in Blitz3D and Monkey MiniB3D is different. When I try to fire a shot from camera in Blitz3D the child "shot" has always the same direction like the camera:

Fire a shot with <1> then turn the camera to ~45° with <2> and fire another shot.



format_code('Graphics3D 800,600
light=CreateLight(1)

cam=CreateCamera()
MoveEntity cam,0,0,-5
Repeat
If KeyHit(2)
shot=CreateSphere(8,cam)
fire=1
EndIf
If KeyHit(3)
TurnEntity cam,0,1,0
EndIf
If fire=1
MoveEntity shot,0,0,1
EndIf
RenderWorld()
DebugLog EntityYaw(cam)
Flip 0
Until KeyHit(1)
')

The same in Monkey produces strange effects. The shot's start direction depends on the camera Yaw position:

Fire a shot with <1> then turn the camera to ~45° with <2> to the right side and fire another shot.


format_codebox('Strict
Import mojo
Import minib3d


Class Game Extends App

Field Camera:TCamera
Field Light:TLight
Field Shot:TMesh
Field Started:Bool, Fire%=0

Method OnCreate%()
SetUpdateRate 30
Return 0
End


Method OnUpdate%()
If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
If Not Started Then Return 0

If TouchX()<100
Camera.TurnEntity 0,1,0
Elseif TouchX()>500
Camera.TurnEntity 0,-1,0
Endif


If TouchHit(0) And Fire=0
Fire=Millisecs()+2000
Shot=CreateSphere(8,Camera)
Endif
If Fire >Millisecs()
Shot.MoveEntity 0,0,2
Elseif Fire>0
Shot.HideEntity()
Fire=0
Endif
Print Camera.EntityYaw()
Return 0
End


Method Init:Void()
If Started Then Return
Started = True
SetRender()
Camera = CreateCamera()
Camera.CameraClsColor(180,210,220)


Light=CreateLight(1)
Light.TurnEntity 35,-40,0
Light.LightColor 222,222,111
Light.AmbientLight 111,99,111
End


Method OnRender%()
Init()
RenderWorld()
Return 0
End
End




Function Main%()
New Game
Return 0
End
')


AdamRedwoods(Posted 2013) [#59]
The same in Monkey produces strange effects. The shot's start direction depends on the camera Yaw position:


oh my oh my. ok, that's a bad bug, thanks for finding this, will update asap. BTW, MoveEntity can be replaced with just this, and it'll work:

EDIT:
Scratch that...
The bug was that i was compounding the matrix back into the children.


AdamRedwoods(Posted 2013) [#60]
ok, fixed the MoveEntity bug on GitHub.

Sorry about that bug, TranslateEntity() may be borked, too, i'll look into when I get 10 minutes free... which is never...


Midimaster(Posted 2013) [#61]
At the moment I start wrinting a beginner tutorial for monkey minib3d. Did you notice it? If I detect more bugs during this process I will report to you, ok?

By the way... this is also "closed" to a bug:
My Tutorial Chapter 1:

...and extract it to your Monkey Module folder...
C:\MonkeyPro69\modules\
After this the minib3d folder will have the wrong name:
C:\MonkeyPro69\modules\minib3d-monkey-master\
Rename it to "minib3d"...
C:\MonkeyPro69\modules\minib3d\

Is there any reason for using this folder name?



And this behavior was also strange:

The "0" in ScaleEntity() causes the grid's color not to be displayed green but black. But I'm not sure, whether this is a feature. With a "0.1" it workes perfect.
format_code(' Floor=CreateGrid(15,15)
Floor.ScaleEntity 10,0,10
Floor.EntityColor 11,99,11
')


AdamRedwoods(Posted 2013) [#62]
Is there any reason for using this folder name?

that's GitHub. If i make a miniB3D-Haxe in the future, i'd want to separate it.

The "0" in ScaleEntity() causes the grid's color not to be displayed green but black.

weird, it should disappear. i'll check it out but if a height is 0.0 it does make sense to get weird.

Did you notice it?

yes! keep going. i don't have time. first, i want to make a demo game, but i want to get collada animation going first.


AdamRedwoods(Posted 2013) [#63]
images made via GrabImage do not render.

i played with this and couldn't find a problem... any examples?


Midimaster(Posted 2013) [#64]
"0" problem:
It did not disappear, but was filled with black color.
I can live with a feature, that an object with height=0 disappears. But I think in Blitz3D the plane had a height of 0.

I see: You have not much time. So, if you want you can check the code of my tutorial demos and add the samples in your package as yours.

You should also search for some guys willing to write the documentation for you for free. 10 friend and everybody write one command a week... they will finish in a year. Perhaps Mark has an automatism for his documentation?


StoneFaceEXE(Posted 2013) [#65]
Sorry, I guess I forgot to delete build folder or something ( It works, which is awesome ^_^


Rex Rhino(Posted 2013) [#66]
Is EntityColor working in the latest version?

UPDATE:

I see that EntityColor is working for CreateCube(), but not CreateSphere()... I think that would be a bug in EntityColor or CreateSphere, but I have no idea which.


AdamRedwoods(Posted 2013) [#67]
CreateCube(), but not CreateSphere()

are you sure? they are treated identically, so i don't see why they'd be different. check the entityblend() values, i have recently changed that in xna.


Rex Rhino(Posted 2013) [#68]

are you sure? they are treated identically, so i don't see why they'd be different. check the entityblend() values, i have recently changed that in xna.



You are right! There was a bug in my code that was create duplicate versions of a sphere, one with EntityColor applied, and one without EntityColor applied.

Sorry about that... Next time I will create a code demo if I think I found a bug!


blabz(Posted 2013) [#69]
Does SetMojoEmulation() render mojo's 2d graphic commands in OpenGL?

Would I be able to use FBO's on Mojo's 2d graphics?


AdamRedwoods(Posted 2013) [#70]
Would I be able to use FBO's on Mojo's 2d graphics?

I have not tested it, but mojo emulation goes through the same renderer as everything else, the only difference is the camera. So in theory, yes. and if you get a working example before i do, please share.


Midimaster(Posted 2013) [#71]
some questions related to my last chapter of the tutorial:

What is this type good for?
format_code('Const COLLISION_METHOD_AABB:Int=4')


What is this type? Do I have to define more in this case?
format_code('Const COLLISION_METHOD_POLYGON:Int=2')


Why are there again collision type definitions in the Collision() command? parameter method_nr%? What are they good for?
format_code('Function Collisions:Void(src_no:Int, dest_no:Int, method_no:Int, response_no:Int=0)')


Why does the bowl stopps to soon in my sample?



Why does the bowl slide and finally continue, when i use this:
format_code('Collisions MovingObjects,MovingObjects, COLLISION_METHOD_BOX, COLLISION_RESPONSE_STOP
')


AdamRedwoods(Posted 2013) [#72]
What is this type good for?

collision AABB is not implemented yet. i was trying to find a very cheap, fast collision. sphere collision is pretty fast.

What is this type? Do I have to define more in this case?

collision polygon is a source sphere to destination polygon collision. it also handles polygon picks (see pick example).

Why are there again collision type definitions in the Collision() command? parameter method_nr%? What are they good for?


src_no = the source collision type (type = group number in this case)
dst_no = the destination collision type (type = group number in this case)
method_no = COLLISION_METHOD_XXXXX (XXXXX = SPHERE, BOX, POLYGON)

so Collisions() command "turns on" that collision for that src/dst group.
this enables you to create different groups, so you do not waste time testing against EVERYTHING. collisions are very expensive computationally.

Example:
format_code('
Collisions(Player%, floor%, POLYGON, SLIDE) ''expensive, but need accuracy
Collisions(Player, wall, BOX, SLIDEXZ) ''medium, need angles for walls
Collisions(Player, zombie, SPHERE, SLIDEXZ) ''cheap, only need to check sphere area, can be multiple spheres
')


Why does the bowl stopps to soon in my sample?

the default EntityBox() setting is too big. probably a bug.
you can do this to define the exact width, height, depth:
Bowl.CollisionSetup MovingObjects,COLLISION_METHOD_BOX, 1.0, 1.0, 1.0
or
Bowl.CollisionSetup MovingObjects,COLLISION_METHOD_BOX, Bowl.EntityScaleX(), Bowl.EntityScaleY(), Bowl.EntityScaleZ()

you can see the collision shapes in your sample here:
format_codebox('
Strict
Import mojo
Import minib3d


Class Game Extends App

Field Camera:TCamera
Field Light:TLight
Field Cube:TMesh, Bowl:TMesh
Field colmesh:TMesh, colmesh2:TMesh
Field Started:Bool

Method OnCreate%()
SetUpdateRate 30
Return 0
End


Method OnUpdate%()
If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
If Not Started Then Return 0
Cube.TurnEntity 0,1,0
Bowl.MoveEntity 0,-0.1,0
Print Bowl.CountCollisions()
UpdateWorld()
Return 0
End


Method Init:Void()
If Started Then Return
Started = True
SetRender()
Camera = CreateCamera()
Camera.CameraClsColor(0,0,80)
Camera.PositionEntity(0,-0.3,0)

Local MovingObjects%=1

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

Bowl= CreateSphere()
Bowl.PositionEntity 0,5,8
Bowl.EntityColor 255,0,0
Bowl.CollisionSetup MovingObjects,COLLISION_METHOD_BOX

colmesh = CreateSphere()
colmesh.EntityAlpha(0.2)
colmesh.EntityParent(Cube, False)
colmesh.ScaleEntity(Cube.collision.radius_x,Cube.collision.radius_x,Cube.collision.radius_x)

colmesh2 = CreateSphere()
colmesh2.EntityAlpha(0.2)
colmesh2.EntityParent(Bowl, False)
colmesh2.ScaleEntity(Bowl.collision.radius_x,Bowl.collision.radius_x,Bowl.collision.radius_x)

Collisions MovingObjects,MovingObjects, COLLISION_METHOD_SPHERE, COLLISION_RESPONSE_STOP

Light=CreateLight(1)
Light.MoveEntity -10,10,10
Light.TurnEntity 35,-40,0
End


Method OnRender%()
Init()
RenderWorld()
Return 0
End
End




Function Main%()
New Game
Return 0
End
')

Why does the bowl slide and finally continue, when i use this:

bug.

Please note that recently there were a few bugs found that I am working on.


IceVAN(Posted 2013) [#73]
Hi Adam,

¿v0.35 works on Android?

minib3d_mojo_bunnies compile but app crash and close

format_codebox('
BUILD SUCCESSFUL
Total time: 17 seconds
Starting: Intent { cmp=com.monkey/.MonkeyGame }
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
E/dalvikvm( 3666): Could not find class 'com.monkey.c_myApp', referenced from method com.monkey.bb_.bbMain
E/AndroidRuntime( 3666): FATAL EXCEPTION: main
E/AndroidRuntime( 3666): java.lang.NoClassDefFoundError: com.monkey.c_MiniB3DApp
E/AndroidRuntime( 3666): at com.monkey.bb_.bbInit(MonkeyGame.java:12678)
E/AndroidRuntime( 3666): at com.monkey.MonkeyGame.onCreate(MonkeyGame.java:1378)
E/AndroidRuntime( 3666): at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime( 3666): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime( 3666): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime( 3666): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime( 3666): at android.app.ActivityThread.access$600(ActivityThread.jE/DictionaryBackupAgent( 2741): Couldn't read from the cursor
ava:141)
E/AndroidRuntime( 3666): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime( 3666): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3666): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3666): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 3666): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3666): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 3666): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 3666): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 3666): at dalvik.system.NativeStart.main(Native Method)
')


Midimaster(Posted 2013) [#74]
Hope you still keep on smiling about my posts... I told you I will find a bunch of bugs during this tutorial...

....Why are there again collision type definitions in the Collision() command? parameter method_nr%? What are they good for?...
Your answer did not answer my question. I understand the need of this function call. But what I did not understand is: Why is there again a definiton of collision radius types?.

If the Bowl is already defined as collision type "Sphere" and the Cube is already defined as collision type "Box". What would bring to define now a collision type in the Collision() command? I'm only talking about the third parameter in this command!

What wouldbe the effect, when this is given...
format_code('Bowl.CollisionSetup 1, COLLISION_METHOD_SPHERE
Cube.CollisionSetup 1, COLLISION_METHOD_BOX')

and now I use here...
format_code('Collisions MovingObjects,MovingObjects, COLLISION_METHOD_SPHERE, COLLISION_RESPONSE_STOP')
or
format_code('Collisions MovingObjects,MovingObjects, COLLISION_METHOD_BOX, COLLISION_RESPONSE_STOP')
or
format_code('Collisions MovingObjects,MovingObjects, COLLISION_METHOD_POLYGON, COLLISION_RESPONSE_STOP')


Your possibility of visualizing the shapes of the collision rooms would be a very helpful tool during development, when this is added to the engine as a feature. The game author could see, whether the collision shape really fits to the actors shape. As long as the game author has to define those shapes by himself he propably could make mistakes and never can 100% sure, that the shape corresponds with the current collision room.


If I now play around with the visible shapes I can see, that the collision radius defined by the default values of the command CollisionSetup() is also to big at the bowl. My bowl is created as CreateSphere() without any scaling. So this should create a Sphere with radius=1 or diameter=2. Shouldn't the CollisionSetup() by default set the collision radius to the same value? But the painted shape of the collision room seems to be double size...


AdamRedwoods(Posted 2013) [#75]
¿v0.35 works on Android?
minib3d_mojo_bunnies compile but app crash and close

that error says it cannot find class myApp.
yup, tested v0.35 out on a nexus4.
If the Bowl is already defined as collision type "Sphere" and the Cube is already defined as collision type "Box". What would bring to define now a collision type in the Collision() command?

oh, ok, thats a good point. you're probably right, one of those is not really needed, but in the CollisionSetup() function it calculates the collision primitive size ahead of time. I guess the third parameter in Collisions() should be optional... i'll have to think about it.

CollisionSetup() also is important if you use a CreatePivot() for a trigger point or something that uses a sphere or box collision, there is no way collisions can tell the size. It is also needed for CameraPick(), since we do not define the collision method.

I told you I will find a bunch of bugs during this tutorial...

good!


IceVAN(Posted 2013) [#76]

that error says it cannot find class myApp.
yup, tested v0.35 out on a nexus4.



I change this

format_code('Class myApp Extends Minib3dApp')

for this one

format_code('Class myApp Extends MiniB3DApp')

and works! But I don't understand, Class myApp Extends Minib3dApp works fine before and works ok on html5 and glfw ??!??!

Several hours to find the error. I believed I was going crazy XD


AdamRedwoods(Posted 2013) [#77]
Several hours to find the error. I believed I was going crazy

sorry about that, that change was me to be more consistent in my labeling.

But i dug into this problem and it's more to do with Android JDK not extracting the classes correctly for the Class Loader because they are named the same and in the same file.

And its a shame that
format_code('Alias Minib3dApp = minib3d.app.MiniB3DApp')
does not work when the class is in the same file. That's a monkey problem.

Anyways, I've changed it so the correct labeling uses caps "MiniB3DApp". My apologies.


Midimaster(Posted 2013) [#78]
I'm working on the next chapter of the tutorial about textures. But I need your help to clarify:

1.
In your first samples you called SetRender() once in the OnRender()-Init(). In the firepaint demo you called it in OnCreate() and it seem important that it is now there, because otherwise the TPixmap.PreLoadPixmap([""...]) seems to throw a bug.

Can we say, that SetRender() now can always be called in OnCreate()? Then I would change the old chapters of the tutorial...


2.
I always get this error message. Is it normal?
format_code('WebGL 1.0
**WEBGL 1
(357,14): warning X3206: implicit truncation of vector type
')


3.
What do I exactly see, when using Wireframe True? When I use this on a CreateGrid(2,1) it looks like there are too many triangles? 4 small ones as I expected but also 2 big ones? If I CreateGrid(3,3) now it looks really confusing...


AdamRedwoods(Posted 2013) [#79]
1. SetRender() must be set first. Do it before any minib3d commands. OnCreate() is best.

2. it is normal.

3. wireframe connects everything in the buffer, so it's not entirely accurate. a render shader would improve this.


hopefully collision bugs will be done soon. just a little popping to smooth out.


bruZard(Posted 2013) [#80]
are shaders already to use? particulary normal maps?


Midimaster(Posted 2013) [#81]
I'm preparing the next chapter "Sprites" of minib3d tutorial and I'm not sure, whether I found the next bug:

I have a "tree.png"...


... and I want to use it as a sprite. But it seems, that it's color is influenced by the CameraClsColor. The tree look "blue":

format_code(' Method Init:Void()
If Started Then Return
If Not TPixmap.PreLoadPixmap(["Tree.png"])
Return
Endif
Started = True
Camera = CreateCamera()
Camera.CameraClsColor(0,0,111)
Camera.MoveEntity 0,0,-2

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

Tree = LoadSprite("Tree.png",FXFLAG_FULLBRIGHT)
Tree.PositionEntity 3,0,4
Tree.SpriteViewMode 2

Light=CreateLight(1)
Light.MoveEntity -10,10,10
Light.TurnEntity 35,-40,0
End')


The second question is about those "TBatchSprites". When do I use them and why. And... is there any reason for using "old fashioned" sprites?


AdamRedwoods(Posted 2013) [#82]
are shaders already to use? particulary normal maps?

yes, you can extend TShaderGLSL and create your own, then either SetDefaultShader(shader) or PaintEntity(shader).

normal maps should work (EntityFX 1024) but I haven't really tested it enough.

But it seems, that it's color is influenced by the CameraClsColor. The tree look "blue"

change sprite blend to 0. i think it's "add" blend by default.

The second question is about those "TBatchSprites". When do I use them and why.

Batch SPrites are great when you have a lot of sprites that are the same image. very fast. explosions, fire and such.

you'd use the regular tsprite for larger stuff that doesn't get drawn as much. "god ray" effects, etc.


AdamRedwoods(Posted 2013) [#83]
****************************************
minib3d v0.35.1

- collision bug fixes
- added: New Brush(r,g,b)


So, i've sent some time on fixing collisions. thanks to everyone who sent in examples, i think collisions feel much better now. let me know otherwise.


Midimaster(Posted 2013) [#84]
this seems not to be the solution... now the alpha channel is like "mask"

left side MiniB3D, right side png on blue background:



AdamRedwoods(Posted 2013) [#85]
is that html5? i think i had a premultiplying alpha problem.


Midimaster(Posted 2013) [#86]
yes html5, the tutorial target is always html5. "premultiplying alpha problem"???

"I had a..." or "It had a ..."?



On android it looks ok, when I use:
format_code(' Tree = LoadSprite("tree.png",2)
Tree.EntityBlend 0
')


During this test, I recognized that your TPixmap.PreLoadPixmap(["tree.png"]) in combination with Android (tested on 2.3) has a problem with case sensitive file names. The corrrect file name was "tree.png", but I asked for

format_code('TPixmap.PreLoadPixmap(["Tree.png"])')

and got this error:

format_codebox('
BUILD SUCCESSFUL
Total time: 24 seconds
--------- beginning of /dev/log/main
E/AndroidRuntime( 8852): feature code ==> cannot open file
E/SensorManager( 8860): registerListener :: handle = 0 name= K2DM delay= 20000 Listener= com.monkey.BBMonkeyGame@40524e28
E/SensorManager( 8860): =======>>>Sensor Thread RUNNING <<<========
E/SensorManager( 8860): reg :: handle = 0
E/ ( 8860): Creating OpenGL 1.1 Session
I/[Monkey]( 8860): **OPENGL VERSION:1.1
I/[Monkey]( 8860): ..max textures:31
I/[Monkey]( 8860): Monkey Runtime Error : java.lang.NullPointerException
I/[Monkey]( 8860): C:/MonkeyPro69/modules/opengl/gles11.monkey<706>
I/[Monkey]( 8860): C:/MonkeyPro69/modules/minib3d/opengl/tpixmapgl.monkey<333>
I/[Monkey]( 8860): C:/MonkeyPro69/modules/minib3d/tpixmap.monkey<198>
I/[Monkey]( 8860): C:/MonkeyPro69/modules/minib3d/tpixmap.monkey<46>
I/[Monkey]( 8860): C:/Monkey/Test3D/Sprites.monkey<32>
I/[Monkey]( 8860): C:/Monkey/Test3D/Sprites.monkey<52>
I/[Monkey]( 8860): C:/MonkeyPro69/modules/mojo/app.monkey<67>
E/EGL_SERVER( 8860): pid mem_get_free_space before = 5fffa0
E/EGL_SERVER( 8860): pid mem_get_free_space = 5fffa0
--------- beginning of /dev/log/system
E/AndroidRuntime( 8860): FATAL EXCEPTION: GLThread 11
E/AndroidRuntime( 8860): java.lang.NullPointerException
E/AndroidRuntime( 8860): at com.monkey.BBAndroidGame.LoadBitmap(MonkeyGame.java:1137)
E/AndroidRuntime( 8860): at com.monkey.bb_opengl_gles11.LoadImageData(MonkeyGame.java:2577)
E/AndroidRuntime( 8860): at com.monkey.bb_gles11.g_LoadImageData(MonkeyGame.java:16386)
E/AndroidRuntime( 8860): at com.monkey.c_PreloadManager.p_PreLoadData(MonkeyGame.java:15470)
E/AndroidRuntime( 8860): at com.monkey.c_TPixmapPreloader.p_PreLoad(MonkeyGame.java:13439)
E/AndroidRuntime( 8860): at com.monkey.c_TPixmap.m_PreLoadPixmap(MonkeyGame.java:13313)
E/AndroidRuntime( 8860): at com.monkey.c_Game.p_Init(MonkeyGame.java:2755)
E/AndroidRuntime( 8860): at com.monkey.c_Game.p_OnRender(MonkeyGame.java:2782)
E/AndroidRuntime( 8860): at com.monkey.c_GameDelegate.RenderGame(MonkeyGame.java:2867)
E/AndroidRuntime( 8860): at com.monkey.BBGame.RenderGame(MonkeyGame.java:566)
E/AndroidRuntime( 8860): at com.monkey.BBAndroidGame.onDrawFrame(MonkeyGame.java:1246)
E/AndroidRuntime( 8860): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1388)
E/AndroidRuntime( 8860): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)
E/liblog ( 1472): failed to call dumpstate
E/ ( 1472): Dumpstate > /data/log/dumpstate_app_com_monkey_error
E/Launcher( 8570): setWindowOpaque()
E/AudioPolicyManager( 1345): Speaker Volume = 0.133352 , device = 2, stream = 1, index = 2
E/InputDispatcher( 1472): Received spurious receive callback for unknown input channel. fd=259, events=0x1
E/Launcher( 8570): setWindowOpaque()
E/StatusBarPolicy( 1547): ecio: 41
E/StatusBarPolicy( 1547): iconLevel: 4
E/StatusBarPolicy( 1547): ecio: 41
E/StatusBarPolicy( 1547): iconLevel: 4
E/StatusBarPolicy( 1547): ecio: 41
E/StatusBarPolicy( 1547): iconLevel: 4')

It was not necessary to LoadSprite() the image. Already the TPixmap.PreLoadPixmap[] was sufficent to get the error.


IceVAN(Posted 2013) [#87]
Hi Adam,

I still have problems with normals and flat shading.
You told me that I had to use the function unweldtriangles() but the normals ligthting keep failing. Is as if the light "turning" with the object.

http://www.monkeycoder.co.nz/Community/post.php?topic=4396&post=51460

I have made this function, and it works.

format_code('

Function NormalizeMesh(m:TMesh)

' to fix float precision with small numbers
ScaleMesh(m,10.0,10.0,10.0)

For Local ns:Int = 1 To CountSurfaces(m)
Local s:TSurface = GetSurface(m,ns)
For Local t=1 To CountTriangles(s)

Local v0:Int = TriangleVertex ( s,t,0 )
Local v1:Int = TriangleVertex ( s,t,1 )
Local v2:Int = TriangleVertex ( s,t,2 )

Local xu:Float = VertexX(s,v1) - VertexX(s,v0)
Local yu:Float = VertexY(s,v1) - VertexY(s,v0)
Local zu:Float = VertexZ(s,v1) - VertexZ(s,v0)

Local xv:Float = VertexX(s,v2) - VertexX(s,v0)
Local yv:Float = VertexY(s,v2) - VertexY(s,v0)
Local zv:Float = VertexZ(s,v2) - VertexZ(s,v0)

Local xn:Float = (yu * zv) - (zu * yv)
Local yn:Float = (zu * xv) - (xu * zv)
Local zn:Float = (xu * yv) - (yu * xv)

Local v:Float = 1.0 / Sqrt((xn * xn) + (yn * yn) + (zn * zn))

Local xw:Float = v * xn
Local yw:Float = v * yn
Local zw:Float = v * zn

VertexNormal(s, v0, xw,yw,zw)
VertexNormal(s, v1, xw,yw,zw)
VertexNormal(s, v2, xw,yw,zw)

Next
Next

' back to original size
ScaleMesh(m,0.1,0.1,0.1)
End

')


bruZard(Posted 2013) [#88]
in Blender3D you can use the modifier "Edge Split" for hard edges.


bruZard(Posted 2013) [#89]
have i to do something to update the normals at runtime or does that the engine automatically?


AdamRedwoods(Posted 2013) [#90]
re: case sensitive filenames
yes, is an error too much? i can have it return an empty 1x1 texture.

re: premultiply html5
yes, it's the shader. i can try to get rid of the white fringe, i am just being slow because i'm working on win8 and flash11 simultaneously.

re:normals and flat shading
ok, i'll look into it. does UpdateNormals() not work? i'll have to check.

re: normals at runtime
No, if you LoadMesh() or CreateXXX() it should take care of normals for you... UNLESS your 3d app creates normals and exports them. then either B3D, OBJ, (or Collada) will pick this up and NOT create normals, otherwise create new normals.

See, it's difficult programatically to determine what people want with normals, so it's best to leave it up to you, but you should have the tools easily available. So I can make tools, but nothing should be "automatic".


Midimaster(Posted 2013) [#91]
white fringe:

the white fringe is a general problem on the html5 target. if I create a texture of the tree and add it to a cube, it is the same problem. It is always a 1pix white border where the color changes to transparent. A workaround for the tutorial will now be to offer a "compact" tree with the shortest borderline...

Also it help, when the texture is bigger. A 512x512 texture has nearly no problems.

It sound like you don't have this problem on the other targets? So, there is no need to hurry with update because of me... Always I only want to inform you about bugs I recognized.




filenames:

So we can say, that it is important in MiniB3D to care about the case sensitivity of filenames? OK, then it is not a bug, but a feature.


bruZard(Posted 2013) [#92]
i mean the normal maps, not the polygon normals.

i try to get normal mapping:
format_codebox('
Strict

Import minib3d

Class Test Extends App
Field normals:TTexture
Field diffuse:TTexture
Field obj:TMesh
Field resReady:Bool
Field cam:TCamera
Field light:TLight

Method Init:Int()
If Self.resReady Return 0

If Not TPixmap.PreLoadPixmap(["normals.png", "diffuse.png"]) Return 0

Self.resReady = True
Self.obj = LoadMesh("test.b3d")
Self.cam = CreateCamera()
Self.light = CreateLight(2)
Self.normals = LoadTexture("normals.png")
Self.diffuse = LoadTexture("diffuse.png")

LightRange(Self.light, 20)
EntityFX(obj, 1024)

TextureBlend(Self.normals, 4)
TextureBlend(Self.diffuse, 2)

EntityTexture(Self.obj, Self.normals)
EntityTexture(Self.obj, Self.diffuse, 0, 1)

PositionEntity(cam, 0, 8, -8)
PositionEntity(light, 0, 5, -5)

PointEntity(cam, obj)


Return 0
End

Method OnCreate:Int()
Self.resReady = False

SetUpdateRate(30)
SetRender()
Return 0
End

Method OnUpdate:Int()
If Not Self.resReady
Self.Init()
Return 0
EndIf

If KeyDown(KEY_W) TranslateEntity(light, 0, 0, 0.1)
If KeyDown(KEY_S) TranslateEntity(light, 0, 0, -0.1)

Return 0
End

Method OnRender:Int()
RenderWorld()
Return 0
End
End

Function Main:Int()
New Test()
Return 0
End
')


IceVAN(Posted 2013) [#93]
Hi Adam
re:normals and flat shading
ok, i'll look into it. does UpdateNormals() not work? i'll have to check

Yes UpdateNormals() work but that smooth the mesh also in unweld models.
I made unweld in my 3D software to obtain independet triangles and then independent 3 vertex for each triangle.


Rone(Posted 2013) [#94]

re: premultiply html5
yes, it's the shader. i can try to get rid of the white fringe, i am just being slow because i'm working on win8 and flash11 simultaneously.



I think it's not the shader. I used the same texture blending equation in d3d11...
alpha is automatically pre-multiplied in webgl(like in xna). Therefore, blending needs to be adjusted as follows:

format_code('
' blend modes
Select blend
Case 0,1

#If TARGET<>"html5"
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
#else
glEnable(GL_BLEND)
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA)
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
#End
...
')



I guess glfw and xna are still not quite right. Since alpha fringes should be visible, at least in glfw ... and both look comparatively bad ...


Midimaster(Posted 2013) [#95]
wow! perfect! I changed your workaround in "opengles20.monkey" and it looks perfect. I'm impressed!


AdamRedwoods(Posted 2013) [#96]
http://www.khronos.org/registry/webgl/specs/latest/#WEBGLCONTEXTATTRIBUTES

Yup, thanks for finding that Rone!
So I wonder if we should have a pre-multiplied alpha blend mode? I think XNA is using premultiply.

and both look comparatively bad ...

yes, it seems my resizing algorithm (bilinear) is terrible. if we change this one line to detect an enlarge for any direction, then it improves somewhat.
in opengles11/tpixmapgl.monkey (and xna/xna_pixmap.monkey)
format_code('
If ratiow<1.0 or ratioh<1.0 Then enlarge = 1')

ALL textures are resized to the nearest powers-of-two, unless its already the correct size or uses the texture flag TEXFLAG_PRESERVE_SIZE.


AdamRedwoods(Posted 2013) [#97]
p.s. i think we will see this premultiply problem arise for non-html5 if i use a gbuffer FBO or shadows (transparent sprite casting shadow).


Rone(Posted 2013) [#98]

So I wonder if we should have a pre-multiplied alpha blend mode?


I think that makes sense.
Sprites can enable it automatically

format_code('
If tex.flags&2=0 And tex.flags&4=0
sprite.EntityBlend 3
ElseIf tex_flags&2
sprite.EntityBlend(BLEND_PREMULTIPLIED)
End
')


yes, it seems my resizing algorithm (bilinear) is terrible.


This also explains the blurry textures with mipmaps ... I have not looked at your scaling algorithm, but this here draws less soft and also produces fewer artifacts...

format_codebox('
Method PixelR(rgba:Int)
Return rgba & $000000ff
End

Method PixelG(rgba:Int)
Return (rgba & $0000ff00 ) Shr 8
End

Method PixelB(rgba:Int)
Return (rgba & $00ff0000) Shr 16
End

Method PixelA(rgba:Int)
Return (rgba & $ff000000) Shr 24
End


Method ResizePixmap:TPixmap(neww:Int, newh:Int)

''simple average 4pixel
''softer
Local enlarge:Int=0

If width =0 Or height =0 Or neww=0 Or newh=0 Then Return CreatePixmap(0,0)

Local ratiow:Float = width/Float(neww)
Local ratioh:Float = height/Float(newh)

If ratiow<1.0 Or ratioh<1.0 Then enlarge = 1
Local newpix:TPixmapXNA = TPixmapXNA(CreatePixmap(neww, newh))

Local rgb:Int[5]
For Local iy = 0 Until newh
For Local ix = 0 Until neww

Local fx# = Float(ix) * ratiow
Local fy# = Float(iy) * ratioh

Local x = Int(fx)
Local y = Int(fy)

''ints faster than bytes
rgb[0] = GetPixel(x,y)
rgb[1] = GetPixel(x+1,y)
rgb[2] = GetPixel(x,y+1)
rgb[3] = GetPixel(x+1,y+1)

local dx = int((fx - x) * 16.0)
local dy = Int((fy - y) * 16.0)


Local y1 = PixelR(rgb[0]) + int(dx * (PixelR(rgb[1]) - PixelR(rgb[0]))) / 16;
Local y2 = PixelR(rgb[2]) + int(dx * (PixelR(rgb[3]) - PixelR(rgb[2]))) / 16;
Local r = y1 + Int(dy * (y2 - y1)) / 16;

y1 = PixelG(rgb[0]) + int(dx * (PixelG(rgb[1]) - PixelG(rgb[0]))) / 16;
y2 = PixelG(rgb[2]) + int(dx * (PixelG(rgb[3]) - PixelG(rgb[2]))) / 16;
Local g = y1 + Int(dy * (y2 - y1)) / 16;

y1 = PixelB(rgb[0]) + int(dx * (PixelB(rgb[1]) - PixelB(rgb[0]))) / 16;
y2 = PixelB(rgb[2]) + int(dx * (PixelB(rgb[3]) - PixelB(rgb[2]))) / 16;
Local b = y1 + Int(dy * (y2 - y1)) / 16;

y1 = PixelA(rgb[0]) + int(dx * (PixelA(rgb[1]) - PixelA(rgb[0]))) / 16;
y2 = PixelA(rgb[2]) + int(dx * (PixelA(rgb[3]) - PixelA(rgb[2]))) / 16;
Local a = y1 + Int(dy * (y2 - y1)) / 16;

newpix.SetPixel(ix,iy,r,g,b,a)

Next
Next

Return newpix
End
')

I did not check the borders, but it seems to provide acceptable results.
'PixelX(..)' & '.SetPixel' should be in-lined...apart from that it's pretty optimized(using fixed point math)

Here is also the sharpening filter I used for sharpening smaller mip levels... makes everything much crisper(anisotropic filtering is disabled by default)

format_codebox('
Global mask:Int[] = [-1,-1,-1,
-1,17,-1,
-1,-1,-1]

Function Clip%(val%)
If val > 255 Then
val = 255
Else If val < 0 Then
val = 0
End
Return val
Function

Function UnsharpMask(src:TPixmap, dst:TPixmap)

Local width:= src.width
Local height:= src.height
Local stride:= src.pitch*4

Local srcPixels:= src.pixels

For Local y = 0 Until height

For Local x = 0 Until width

Local src_rgb:= src.GetPixel(x, y)
Local src_red = (src_rgb & $000000ff )
Local src_green = (src_rgb & $0000ff00 ) Shr 8
Local src_blue = (src_rgb & $00ff0000 ) Shr 16
Local src_alpha = (src_rgb & $ff000000 ) Shr 24
Local src_mono = 0.299*src_red + 0.587*src_green + 0.114*src_blue

If x < 2 Or y < 2 Or x >= width -2 Or y >= height -2

dst.SetPixel(x,y, src_red,src_green, src_blue, src_alpha)

Else

Local r = 0, g = 0, b = 0

For Local iy = -1 To 1
For Local ix = -1 To 1
Local rgb:= src.GetPixel(ix+x, iy+y)
Local red = (rgb & $000000ff )
Local green = (rgb & $0000ff00 ) Shr 8
Local blue = (rgb & $00ff0000 ) Shr 16
b += (mask[(iy + 1) * 3 + ix + 1] * blue);
g += (mask[(iy + 1) * 3 + ix + 1] * green);
r += (mask[(iy + 1) * 3 + ix + 1] * red);
End
End

r = Clip(r/9)
g = Clip(g/9)
b = Clip(b/9)

If Abs((0.299*r + 0.587*g + 0.114*b) - src_mono) < 4 Then
dst.SetPixel(x,y, src_red,src_green, src_blue, src_alpha)
else
dst.SetPixel(x,y,r,g,b,src_alpha)
End

End

End
End

Return dst
End
')


AdamRedwoods(Posted 2013) [#99]
Looks good, i think that's a nearest neighbor algorithm. After I weighted my bilinear, it started to look the same.

Here's a bit-math optimized:
format_codebox('Local dx% = Int(Int(fx - x) Shl 16)
Local dy% = Int(Int(fy - y) Shl 16)


Local y1 = (rgb[0]& $000000ff) + Int(dx * ((rgb[1]& $000000ff) - (rgb[0]& $000000ff))) Shr 4;
Local y2 = (rgb[2]& $000000ff) + Int(dx * ((rgb[3]& $000000ff) - (rgb[2]& $000000ff))) Shr 4;
Local r = y1 + Int(dy * (y2 - y1)) Shr 4;

y1 = ((rgb[0] & $0000ff00)Shr 8) + Int(dx * (((rgb[1] & $0000ff00)Shr 8) - (rgb[0] & $0000ff00)Shr 8)) Shr 4;
y2 = ((rgb[2] & $0000ff00)Shr 8) + Int(dx * (((rgb[3] & $0000ff00)Shr 8) - (rgb[2] & $0000ff00)Shr 8)) Shr 4;
Local g = y1 + Int(dy * (y2 - y1)) Shr 4;

y1 = ((rgb[0] & $00ff0000)Shr 16) + Int(dx * (((rgb[1] & $00ff0000)Shr 16) - (rgb[0] & $00ff0000)Shr 16)) Shr 4;
y2 = ((rgb[2] & $00ff0000)Shr 16) + Int(dx * (((rgb[3] & $00ff0000)Shr 16) - (rgb[2] & $00ff0000)Shr 16)) Shr 4;
Local b = y1 + Int(dy * (y2 - y1)) Shr 4;

y1 = ((rgb[0] & $ff000000)Shr 24) + Int(dx * (((rgb[1] & $ff000000)Shr 24) - (rgb[0] & $ff000000)Shr 24)) Shr 4;
y2 = ((rgb[2] & $ff000000)Shr 24) + Int(dx * (((rgb[3] & $ff000000)Shr 24) - (rgb[2] & $ff000000)Shr 24)) Shr 4;
Local a = y1 + Int(dy * (y2 - y1)) Shr 4;

'newpix.SetPixel(ix,iy,r,g,b,a)
newpix.pixels.PokeInt( (ix Shl 2)+iy*(neww Shl 2), r|g Shl 8|b Shl 16|a Shl 24 )')
I'll probably put this in after I test it on Android.


Rone(Posted 2013) [#100]
Cool!
It's also bilinear.

Edit:
format_code('
Local dx% = Int(Int(fx - x) Shl 4)
Local dy% = Int(Int(fy - y) Shl 4)
')
btw:
I think every compiler will do this shifting automatically if necessary. So it's just obfuscating, using a division will make the code clearer


AdamRedwoods(Posted 2013) [#101]
I think every compiler will do this shifting automatically if necessary.

i've always wondered about this and i know its a bad habit of mine, but with android being so slow i get worried about basic math functions on pre-Android 3.0. you're probably right that basic integer math will have no effect. i'll profile it anyways.


Rone(Posted 2013) [#102]
'fx - x' needs to be multiplied with 16.0, instead of dividing
also first multiply, then cast...
format_code('
Local dx = Int((fx - x) * 16.0)
Local dy = Int((fy - y) * 16.0)
')

just for completeness, here is my original Y800 c++ implementation.

format_code('
// this could be unrolled
/*
for (int r = 0; r < 2; r++)
{
for (int c = 0; c < 2; c++)
{
int index = (y + r ) * imgWidth + (x + c );
FilterdData[r * 2 + c] = *(pIn + index);
}
}
*/

int index = (y) * imgWidth + (x);
FilterdData[0] = *(pIn + index);
FilterdData[1] = *(pIn + index+1);
index = (y + 1) * imgWidth + (x);
FilterdData[2] = *(pIn + index);
FilterdData[3] = *(pIn + index+1);


int dx = (int)((fx - x) * 16.0f);
int dy = (int)((fy - y) * 16.0f);

int y1 = FilterdData[0] + (int)(dx * (FilterdData[1] - FilterdData[0])) / 16;
int y2 = FilterdData[2] + (int)(dx * (FilterdData[3] - FilterdData[2])) / 16;

int filteredPixel = y1 + (int)(dy * (y2 - y1)) / 16;

//float dx = (fx - x);
//float dy = (fy - y);

//int y1 = FilterdData[0] + (int)(dx * (FilterdData[1] - FilterdData[0]));
//int y2 = FilterdData[2] + (int)(dx * (FilterdData[3] - FilterdData[2]));

//int filteredPixel = y1 + (int)(dy * (y2 - y1));
')


Mikele(Posted 2013) [#103]
Ouch!
Yesterday I updated Monkey to ver. 0.70e and miniB3D to the latest ver from GitHub and I can't compile firepaint and animation demos (GFLW)

This is a log (some messages are in Polish - sorry for this):
format_codebox('
"E:/Programs/MonkeyPro/bin/transcc_winnt" -target=Glfw_Game -config=Debug -run "E:/Programs/MonkeyPro/modules/minib3d/examples/firepaint3d.monkey"
TRANS monkey compiler V1.47
Parsing...
miniB3D opengl11
Semanting...
Translating...
Building...
Microsoft (R) Build Engine w wersji 4.0.30319.17929
[Microsoft .NET Framework w wersji 4.0.30319.18033]
Copyright (C) Microsoft Corporation. Wszelkie prawa zastrze&#190;one.

Projekty w tym rozwi&#165;zaniu s&#165; tworzone po kolei. Abu umo&#190;liwi† tworzenie r&#162;wnolegˆe, dodaj przeˆ&#165;cznik "/m".
Kompilacja rozpocz&#169;ˆa si&#169; 2013-05-12 09:37:43.
Projekt "E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.sln" w w&#169;&#171;le 1 (domy˜lne elementy docelowe).
ValidateSolutionConfiguration:
Tworzenie konfiguracji rozwi&#165;zania "Debug|Win32".
Projekt "E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.sln" (1) kompiluje "E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj" (2) w w&#169;&#171;le 1 (domy˜lne elementy docelowe).
InitializeBuildStatus:
Modyfikowanie "E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\build\Debug\MonkeyGame.unsuccessfulbuild".
ClCompile:
Wszystkie dane wyj˜ciowe s&#165; aktualne.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /I"../bdwgc/libatomic_ops-1.2/src" /I../bdwgc/include /I../stb /I../openal/include /I../glfw/include /I../glfw/lib /I../glfw/lib/win32 /Zi /nologo /W0 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _WINDOWS /D _MBCS /Gm /EHa /MTd /GS /Gy- /fp:precise /Zc:wchar_t /Zc:forScope /Fo"E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\build\Debug\\" /Fd"E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\build\Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:queue ..\main.cpp /bigobj
main.cpp
..\main.cpp(1644): error C3861: 'time': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(1649): error C3861: 'localtime_s': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22580): error C2084: function 'const char *readTag(FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(1917) : see previous definition of 'readTag'
..\main.cpp(22587): error C2084: function 'int readInt(FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(1924) : see previous definition of 'readInt'
..\main.cpp(22593): error C2084: function 'int readShort(FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(1930) : see previous definition of 'readShort'
..\main.cpp(22599): error C2084: function 'void skipBytes(int,FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(1936) : see previous definition of 'skipBytes'
..\main.cpp(22608): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22609): error C2296: '-' : illegal, left operand has type 'int (__cdecl *)(FILE *)' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22609): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22610): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22611): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22612): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22612): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22613): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22613): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22615): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22615): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22616): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22616): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22617): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22617): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22618): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22618): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22619): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22619): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22621): error C3861: 'skipBytes': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22623): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22623): error C2440: 'initializing' : cannot convert from 'const char *(__cdecl *)(FILE *)' to 'const char *' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22625): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22625): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
There is no context in which this conversion is possible
..\main.cpp(22627): error C3861: 'skipBytes': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
Kompilowanie projektu "E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj" wykonane (domy˜lne elementy docelowe) - NIEPOWODZENIE.
Kompilowanie projektu "E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.sln" wykonane (domy˜lne elementy docelowe) - NIEPOWODZENIE.

Kompilacja NIE POWIODA SI¨.

"E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.sln" (domy˜lny element docelowy) (1)->
"E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj" (domy˜lny element docelowy) (2)->
(element docelowy ClCompile) ->
..\main.cpp(1644): error C3861: 'time': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(1649): error C3861: 'localtime_s': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22580): error C2084: function 'const char *readTag(FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22587): error C2084: function 'int readInt(FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22593): error C2084: function 'int readShort(FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22599): error C2084: function 'void skipBytes(int,FILE *)' already has a body [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22608): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22609): error C2296: '-' : illegal, left operand has type 'int (__cdecl *)(FILE *)' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22609): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22610): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22611): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22612): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22612): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22613): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22613): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22615): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22615): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22616): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22616): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22617): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22617): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22618): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22618): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22619): error C3861: 'readShort': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22619): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22621): error C3861: 'skipBytes': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22623): error C3861: 'readTag': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22623): error C2440: 'initializing' : cannot convert from 'const char *(__cdecl *)(FILE *)' to 'const char *' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22625): error C3861: 'readInt': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22625): error C2440: 'initializing' : cannot convert from 'int (__cdecl *)(FILE *)' to 'int' [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]
..\main.cpp(22627): error C3861: 'skipBytes': identifier not found [E:\Programs\MonkeyPro\modules\minib3d\examples\firepaint3d.build\glfw\vc2010\MonkeyGame.vcxproj]

Ostrze&#190;enia: 0
Liczba bˆ&#169;d&#162;w: 31

Czas, kt&#162;ry upˆyn&#165;ˆ: 00:00:01.41
TRANS FAILED: Error executing 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /p:Configuration=Debug /p:Platform=Win32 MonkeyGame.sln', return code=1
Done.
')

- when I try to compile to HTML target I have a message:

Monkey Runtime Error : TypeError: Cannot call method 'SetDelegate' of undefinedE:/Programs/MonkeyPro/modules/mojo/app.monkey<113>E:/Programs/MonkeyPro/modules/minib3d/examples/animation_test.monkey<11>E:/Programs/MonkeyPro/modules/minib3d/examples/animation_test.monkey<8>



Should I update some tools or set some their properties? I reverted Monkey to v0.69 but still have the same problem. Any suggestion?


AdamRedwoods(Posted 2013) [#104]
did you delete the previous ".build" folder?


Mikele(Posted 2013) [#105]
Ah ok! I've forgot about that. Mea culpa!
Yes. Now it seems to be ok.
Thank you!


slenkar(Posted 2013) [#106]
did a little bit of google research and got it to compile on linux

go into:

Monkey/targets/glfw/template/


make sure the line in the makefile looks like this


LDLIBS=-lGL -lopenal -lX11 -lpthread -lrt

and at the top of main.cpp add this:
#define GL_GLEXT_PROTOTYPES

tested firepaint and it works!


AdamRedwoods(Posted 2013) [#107]
LDLIBS=-lGL -lopenal -lX11 -lpthread -lrt

and at the top of main.cpp add this:
#define GL_GLEXT_PROTOTYPES

great! perhaps we should try to get this in monkey proper.


Midimaster(Posted 2013) [#108]
Z-Order


For the next chapter of the tutorial I'm testing "TBatchSprites" against normal sprites. With this code I recognized that there is a Z-Order problem if I use the BatchSprites:

format_codebox('Strict
Import mojo
Import minib3d

Class TreePos
Global Liste:List<TreePos> = New List<TreePos>
Field X#,Y#



Function AddOne%(X#,Y#)
Local dist#
Local loc:TreePos=New TreePos
For Local All:TreePos =Eachin Liste
dist=(X-All.X)*(X-All.X)+(Y-All.Y)*(Y-All.Y)
If dist<.75 Return False
Next
loc.X=X
loc.Y=Y
Liste.AddLast loc
Return TRUE
End
End

Class Game Extends App

Field Camera:TCamera
Field Light:TLight
Field Cube:TMesh, Floor:TMesh
Field Tree:TSprite
Field Started:Bool, Third#


Method OnCreate%()
SetUpdateRate 15
SetRender()
Third=DeviceWidth()/3
Return 0
End


Method OnUpdate%()
If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
If Not Started Then Return 0
Cube.TurnEntity 0,1,0
MovingCamera

UpdateWorld()
Return 0
End


Method Init:Void()
If Started Then Return
If Not TPixmap.PreLoadPixmap(["tree.png"])
Return
Endif
Started = True
Camera = CreateCamera()
Camera.CameraClsColor 235,235,255
Camera.CameraFogRange 5,50
Camera.CameraFogMode 1
Camera.CameraFogColor 235,235,255
Camera.MoveEntity 0,10,-0


Floor=CreateGrid(15,15)
Floor.ScaleEntity 10,1,10
Floor.PositionEntity -2,0,8
Floor.EntityColor 55,195,55

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

TBatchSprite.LoadBatchTexture("tree.png",2)

'Tree = LoadSprite("tree.png",2)
'Tree.PositionEntity 0,0,-10
'Tree.EntityBlend 1

For Local i%=0 To 600

Local locTree:TEntity = TBatchSprite.CreateSprite( )
locTree.EntityBlend 1
ShowEntity locTree

'Local locTree:TEntity = CopyEntity(Tree)
Local YScale#=Rnd(.3,1.5)
Local x#,y#
Repeat
x=Rnd(30)
y=Rnd(30)
Until TreePos.AddOne(x,y)=True
locTree.PositionEntity x,YScale,y
locTree.ScaleEntity Rnd(0.3,1),YScale,1
locTree.EntityColor Rnd(0,255),Rnd(230,255),Rnd(150,205)
Next

Light=CreateLight(1)
Light.MoveEntity -10,10,10
Light.TurnEntity 35,-40,0
End


Method OnRender%()
Local Zeit%=Millisecs()
Init()
If Not Started Then Return 0
RenderWorld()
Print -Zeit+Millisecs()
Return 0
End


Method MovingCamera:Void()
Local X#=TouchX(), Y#=TouchY()
If X=0 Then X=DeviceWidth()/2
If Y=0 Then Y=DeviceHeight()/2
Third=DeviceWidth()/3
Camera.MoveEntity 0,0,.06
Local f#=Third
If X<Third
f=2*(f-X)/f
Camera.TurnEntity 0,f,0
Elseif X>2*Third
f=2*(2*f-X)/f
Camera.TurnEntity 0,f,0
Endif

Third=DeviceHeight()/3
f=Third
If Y<Third
f=(f-Y)/f
Camera.TurnEntity -f,0,0
Elseif X>2*Third
f=(2*f-Y)/f
Camera.TurnEntity -f,0,0
Endif
End
End



Function Main%()
New Game
Return 0
End')

If you fly a circle closed over the tree tops, you can see that smalls trees far away are drawn at last. The "tree"-texture is the same like in post #81


Second problem:

Your sample firepaint3d" now seems to show black rectangles around the firework circles. I don't know whether is began only now after this bugfix:
format_code(' glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
')



Bug or Feature?

If you call EntityYaw(Camera) and you turn and turn and turn you will get values >360° and also <-360°. Shouldn't the function return values between -180° to +180° like in B3D?


AdamRedwoods(Posted 2013) [#109]
Re: Z-ORDER

i realized that this may be a problem way back. because the GPU draws quads for sprites, it is a challenge to deal with them. two choices:
1. sort the TBatchSprite
-- this is too computationally heavily, IMO.
2. use GL_ALPHA_TEST
-- makes sprites look "chunky" because it is a all-or-nothing check for alpha. this can be "sortof" fixed by using two passes. it will still look chunky.
-- i haven't implemented this in the OpenGLES2 shader yet, so probably should up the priority of this.

Unity explains this z-ordering challenge here:
http://docs.unity3d.com/Documentation/Components/SL-AlphaTest.html


AdamRedwoods(Posted 2013) [#110]
Your sample "firepaint3d" now seems to show black rectangles around the firework circles

yes, this is caused by the new EntityBlend 0, which is default premultiply. use EntityBlend 1 to fix.
I think i need to add "spark.BatchSpriteEntity().EntityBlend(1)"

no, let me think about that.

If you call EntityYaw(Camera) and you turn and turn and turn you will get values >360° and also <-360°. Shouldn't the function return values between -180° to +180° like in B3D?

huh, i never knew. i guess it's a vote. i can adjust the values internally or it can be done manually if it's not really needed.


bram(Posted 2013) [#111]
On my MacBook Pro, running 10.6.8, HTML5+Chrome, I get the following error:
*glerror: 1286
*glDrawElements
When running a Flash export, the screen remains blue, except for the 'firepaint' demo which gives this error: flash11.monkey<60> : Error : Can't create instance of class FlashMiniB3D due to abstract method Method TRender.UpdateVBO:Int(Local surface:TSurface).
Any ideas what it could be?


AdamRedwoods(Posted 2013) [#112]
On my MacBook Pro, running 10.6.8, HTML5+Chrome, I get the following error

is this on a specific example? may not be preloading the texture.

When running a Flash export

Flash isn't entirely there yet, i'm still writing the AGAL shaders.


AdamRedwoods(Posted 2013) [#113]
v0.36
- alpha testing for opengles2.0
- blending bug fixes
- BrushColor(r,g,b,a), New Brush(r,g,b,a); alpha is now optional

todo: add alpha testing for xna


AdamRedwoods(Posted 2013) [#114]
so, the "flying through trees" TBatchSprite should work when the LoadTexture() of the trees is loaded with "flags|4".


AdamRedwoods(Posted 2013) [#115]
****************************************
minib3d v0.36.1
- some bug fixes, alpha testing all targets



Some familiar faces... not on this update, but showing progress:
http://www.twopisoftware.com/monkeycoder/zombies/flash/MonkeyGame.html
(runs on IE w/flash11)


Landon(Posted 2013) [#116]
wewt


AdamRedwoods(Posted 2013) [#117]
****************************************
minib3d v0.37

- unified EffectState: internal change that simplifies the current render state for all targets

this fixes some bugs, but overall should not effect any external code.
...and updated Flash target to an alpha stage, if anyone wants to play with it. only one point light and no multi-textures.


Amon(Posted 2013) [#118]
Thanks! This is becoming very powerful, thanks to you! :)


Xaron(Posted 2013) [#119]
Has anyone tried async loading for meshes and textures yet? And if so, how is it done? I know the loaders for sound and images already...


slenkar(Posted 2013) [#120]
flash target works, awesome!


AdamRedwoods(Posted 2013) [#121]
Has anyone tried async loading for meshes and textures yet? And if so, how is it done?

well, textures would be the same for images, using the TPixmap.PreLoadPixmap routines.

for meshes and text files, you'd have to use base64 (for binary) and use a custom loader. i think i've enabled all loaders to use existing strings/buffers in memory using ParseB3D, ParseObj, ParseMDD.


Midimaster(Posted 2013) [#122]
To learn how to use "MiniB3D for Monkey" I want to continue writing my tutorial: Load a *.b3d file with LoadMesh() and display it.

At first I build a sample code in old Blitz3D and it worked perfect. Now I converted this to monkey, but it does not work.

Do I have to prepare some additional changes?

I recognized, that I have to change the config.monkey to get also the *.b3d file copied to the data folder.

Now I can already see the 3D model, but the surface is black. The textures are there and preloaded...

The model is a landscape made by ALE with 6 textures as '.jpg and a lightmap as *.png

What do I do wrong?


sionco(Posted 2013) [#123]
Hi. I've just started to play with this, and I'm having fun, thanks for your work!

I have a problem and also a question:

1. I have a problem with sprites, when I use the following code in the init method as suggested, and press compile for flash everything works fine.
format_code('
If Not TPixmap.PreLoadPixmap(["target.png"])
Return
End
')
However, when I try and open the MonkeyGame.html or MonkeyGame.swf externally through the file browser or using the web browser the 3D doesn't start, I just get a white screen.

I know there's something definitely wrong with this (or my code), as when I remove the code and try to open the game again externally from monkey, the game runs ok, even though it doesn't load image and displays a black image in it's place as expected.

2. I've tried using miniB3D on Android and everything works, has anyone made any games with Monkey and miniB3D? is it ready?


Ps
@Midimaster,
Love the tutorials, very helpful! I can't wait for more.


AdamRedwoods(Posted 2013) [#124]
Re:
The model is a landscape made by ALE with 6 textures as '.jpg and a lightmap as *.png

i think i allow max 4 textures for the HTML5 shader, although it shouldn't be black. check the output to see if there are "file not found" errors.
you can debug for textures in a surface by:
format_code('
For local i:int=0 to myMesh.CountSurfaces()-1
For local j:int = 0 to 7
local tex:TTexture= myMesh.GetSurface(i).Brush().GetTexture(j)
if (tex) Print tex.file
Next
Next
')


Re:
However, when I try and open the MonkeyGame.html or MonkeyGame.swf externally through the file browser or using the web browser the 3D doesn't start, I just get a white screen.

yes, this is because in flash or html5 you can only allow remote files to be loaded. this is a common security model for the internet.

to get SWF to run locally, you need to add a different flag either in the code or in the html code that calls the <object>:
format_code('<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
')
i forget if this works or you need to add it in the code as well. if so, you can do that by using an Extern in monkey.


Midimaster(Posted 2013) [#125]
ok, I add your code and additional I added a sprite to display one of the textures.

There are no "file not found messages" nor other messages. The texture is pre-loaded, because I can see it on the sprite

But if I use your check code the app crashs:

format_code('Method OnUpdate%()
If KeyHit(KEY_CLOSE) Or KeyHit(KEY_ESCAPE) Then Error ""
If Not Started Then Return 0
Cube.TurnEntity 0,1,0

If KeyHit(KEY_1)
Print "Textures"
For local i:int=0 to Cube.CountSurfaces()-1
Print "Surface " + i
For local j:int = 0 to 7
Print "Texture " + j
Local tex:TTexture= Cube.GetSurface(i).Brush().GetTexture(j)
Print "check " + j
If (tex) Print tex.file
Next
Print "----------"
Next
Endif

UpdateWorld()
Return 0
End')

it crashs on the line

format_code('Local tex:TTexture= Cube.GetSurface(i).Brush().GetTexture(j)')
without any error message.

Here are the last printout lines:
format_code('...
Textures
Surface 0
Texture 0
')

it does not reach the "check" line.


AdamRedwoods(Posted 2013) [#126]
ok, so the surfaces don't have brushes.
use
format_code('
Local tex:TTexture= Cube.Brush().GetTexture(j)
')
instead.
Another trick is to use is this, which shows the file structure of the model load.
format_code('
#MINIB3D_DEBUG_MODEL=1
')
p.s. if you get really stuck you can send me the file awpiette at yahoo.


Midimaster(Posted 2013) [#127]
with... #MINIB3D_DEBUG_MODEL=1 ...I get this result:

format_codebox('WebGL 1.0
**WEBGL 1
..FullShader success
test
test
test
test
test
test
test
test
Startet
TModel
TEXS
-Load Texture:1.jpg
-Load Texture:2.jpg
-Load Texture:3.jpg
-Load Texture:4.jpg
-Load Texture:5.jpg
-Load Texture:6.jpg
-Load Texture:lm.png
BRUS
NODE
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1104
- TRIS
no_tris:1119 no_verts706
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1143
- TRIS
no_tris:2262 no_verts755
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1467
- TRIS
no_tris:4060 no_verts1139
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1801
- TRIS
no_tris:6592 no_verts1549
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:2719
- TRIS
no_tris:11077 no_verts2596
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:4225
- TRIS
no_tris:19269 no_verts4225
..FastBrightShader success
')

with... Local tex:TTexture= Cube.Brush().GetTexture(j) ...I get the error message:

"Identiefier 'Brush' not found"

Here is a ZIP with all files:

https://www.dropbox.com/s/m5pehupdkm2qhob/bug.zip


Xaron(Posted 2013) [#128]
Hey Adam!

I think there is a bug in your mojo emulation regarding DrawImage when I rotate an image.

I've loaded an image using the Flag Image.MidHandle

Using DrawImage( img, x, y, angle, 1, 1 ) does NOT rotate the image around its center now!

Could you please take a look?

Thanks!


AdamRedwoods(Posted 2013) [#129]
Now I can already see the 3D model, but the surface is black. The textures are there and preloaded...

The model is a landscape made by ALE with 6 textures as '.jpg and a lightmap as *.png


@Midimaster
so, i did manage to find one bug, but the reason your B3D model is black, is because the surfaces are using a brush blend of "0" (overwrite) combined with using a vertex color map entityfx "2" (or 34=32+2).
if the vertex colors are 0,0,0 then we will see black.

i dont know why it is visible in glfw opengl1 vs opengl2 other than there may be a difference in my shader.

this can be corrected by assign the surface blend
format_code('
Cube.GetSurface(1).Brush().blend = 2
Cube.GetSurface(2).Brush().blend = 2
Cube.GetSurface(3).Brush().blend = 2
Cube.GetSurface(4).Brush().blend = 2
Cube.GetSurface(5).Brush().blend = 2
Cube.GetSurface(6).Brush().blend = 2
')
i don't know if that is what result you're trying to get. if not, i'll need a screenshot.


I will check Xaron's bug next.


Midimaster(Posted 2013) [#130]
In this moment I downloaded the new minib3d version as ZIP, deleted the build folder and corrected the config.monkey. I use monkey V69. Then I test the code on target Firefox HTML5.

But it does not start anymore!

Here is the debug log:
format_codebox('test
Startet
..loading B3DBinary:monkey://data/terra.b3d
TModel
TEXS
-Load Texture:1.jpg
-Load Texture:2.jpg
-Load Texture:3.jpg
-Load Texture:4.jpg
-Load Texture:5.jpg
-Load Texture:6.jpg
-Load Texture:lm.png
BRUS
brush rgb:1 1 1 blend:0 fx:2 no_texs:2
brush rgb:1 1 1 blend:0 fx:34 no_texs:2
brush rgb:1 1 1 blend:0 fx:34 no_texs:2
brush rgb:1 1 1 blend:0 fx:34 no_texs:2
brush rgb:1 1 1 blend:0 fx:34 no_texs:2
brush rgb:1 1 1 blend:0 fx:34 no_texs:2
NODE
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1104
- TRIS
no_tris:1119 no_verts706
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1143
- TRIS
no_tris:2262 no_verts755
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1467
- TRIS
no_tris:4060 no_verts1139
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:1801
- TRIS
no_tris:6592 no_verts1549
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:2719
- TRIS
no_tris:11077 no_verts2596
- NODE (parent= Scene Root)
- MESH
- VRTS
no_verts:4225
- TRIS
no_tris:19269 no_verts4225
Monkey Runtime Error : ** out of texture memory ** 1281
C:/MonkeyPro69/modules/minib3d/opengl/opengles20.monkey<1169>
C:/MonkeyPro69/modules/minib3d/trender.monkey<498>
C:/MonkeyPro69/modules/minib3d/opengl/opengles20.monkey<1197>
C:/MonkeyPro69/modules/minib3d/trender.monkey<242>
C:/MonkeyPro69/modules/minib3d/functions.monkey<1136>
C:/Monkey/Test3D/testTerrain.monkey<74>
C:/MonkeyPro69/modules/mojo/app.monkey<67>
')

Is this a hmtl5 target problem or a bug?



And how can the surfaces use "overwrite", when all "building" information comes from a b3d file? Can I not trust in the b3d-file on monkey Minib3D? The old Blitz3D builds a correct landscape without any additinal changes in code:

Screenshot of Blitz3D:





Blitz3D-Code:
format_code('Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
CameraClsColor Camera,111,161,181
MoveEntity Camera, 0,15,140

light=CreateLight()
RotateEntity light,90,0,0

Global land=LoadMesh("terra.b3d")
EntityPickMode land,2
PositionEntity land,0,0,MeshDepth(land)*2


While Not KeyDown( 1 )
RenderWorld
Pick= LinePick(EntityX(Camera),EntityY(Camera),EntityZ(Camera),0,-9,0,.1)
PositionEntity Camera ,EntityX(Camera),PickedY()+1,EntityZ(Camera)
Flip 0
Wend
')

The result, what I'm trying to get is a visible 3D model of the landscape. Finally I want to continue the 3D tutorial and test your module in usability. At the end the user should get an overview, what is able to do with the module and what not.

Do you think the model has a problem? You can check it in old Blitz3D...


I hope you are still interested in my bug reports...


Paul - Taiphoz(Posted 2013) [#131]
Does this work out of the box yet ? or do we still need to hack trans, or some other files.

just looking for a quick progress update if possible.


AdamRedwoods(Posted 2013) [#132]
ok, looks like i need to roll up my sleeves.
the screenshot helps!

Does this work out of the box yet ? or do we still need to hack trans, or some other files.

this should work out of the box, no hacks needed.
the examples still work, but it seems some recent changes have caused some incompatibility to complex b3d files. i'm going to try and fix the bugs.


Paul - Taiphoz(Posted 2013) [#133]
SHWEETTTT :)

Downloading and adding to my modules folder right now.


AdamRedwoods(Posted 2013) [#134]
Is this a hmtl5 target problem or a bug?

man, that was a tough bug. debugging went something like this:
https://www.youtube.com/watch?v=7XkBxCEOGjQ

i'll update in a couple hours.


Sammy(Posted 2013) [#135]
Quick question, is 3d mesh instancing in MiniB3D?


AdamRedwoods(Posted 2013) [#136]
Quick question, is 3d mesh instancing in MiniB3D?

You mean using glVertexAttribDivisor? no, that opengl3 which isn't readily available on all platforms. i do, however, limit state switches of repeating mesh draws. Entity.Copy() naturally reuses mesh data.

Using DrawImage( img, x, y, angle, 1, 1 ) does NOT rotate the image around its center now!

i wasn't able to figure this out yet.

midimaster's problem is fixed and up on github.
you will need to flip the surface stack of the B3D model by using Cube.FlipSurfaceOrder(), or by offsetting each layer in the y direction by a small amount. i added that command as a helper.

Edit: I've also changed out the PreLoaderPixmap() to use stacks, so should be more flexible to preload images.


Midimaster(Posted 2013) [#137]
shall this FlipSurfaceOrder() be a temporary workaround? Or is it only necessary on models made by ALE?

Can you tell me more about it. When I write the tutorial I want to know what I have to communicate about that to other users. Or should I tell, that ALE models in general have problems?

What about the max 4 layer limitation? What about this base64? Is it relevant for a tutorial?

How many model source did you already test? Blender?


Xaron(Posted 2013) [#138]
i wasn't able to figure this out yet.


Does that mean you can't reproduce it or just don't know why it happens atm? :)


AdamRedwoods(Posted 2013) [#139]
don't know why it happens atm?

atm.

necessary on models made by ALE

necessary. what is happening is that the layers (i'm guessing) are all in the same position (0,0,0). so the renderer does not know which to render first. so it renders each and the layers overwrite each other, until the last is drawn. so to reverse this, we use FlipSurfaceOrder(). it seems only with ale, but i would have to see other examples if the original B3D layers it's files differently. most 3d programs shouldn't allow this since it causes z-order fighting. we could also offset the y axis by a very small amount and it would work the same.

What about the max 4 layer limitation?

max 4 textures? it's for the current shader. i'm planning on expanding the shader.
What about this base64?

guess its not needed as much. need to see how other browsers/flash deal with it.
How many model source did you already test? Blender?

as many as i can get. i find most b3d exporters to be buggy. this is why i'm working hard on a collada importer. currently works, trying to get animation working.


Midimaster(Posted 2013) [#140]
just to give a short progression report...

the 3D landscape is now visible on HTML5 target. I downloaded MiniB3D V38 and builded the sample code on Monkey V69.

I added this line:

format_code('Cube =LoadMesh("terra.b3d")
Cube.FlipSurfaceOrder()
')

this lines (an old proposal from you) are not longer necessary
format_code(''Cube.GetSurface(1).Brush().blend = 2')

I will continue testing and report the next bug. But perhaps we are very closed to the nect chapter of the tutorial...


Xaron(Posted 2013) [#141]
Adam, is there anything I could help with? I mean that (for me) annoying bug with the rotation of 2d images (which I use quite frequently for HUDs). Is there something to start with? I mean I just see this MojoEmulation stuff but are the original commands used after that?

Looks like the origin is at 0,0 instead of the center of the image, for whatever reasons...


AdamRedwoods(Posted 2013) [#142]
Using DrawImage( img, x, y, angle, 1, 1 ) does NOT rotate the image around its center now!

fixed, updated v0.38.1 (mojographics.monkey)


Xaron(Posted 2013) [#143]
You are my hero! Wohoo! Thanks again for your great work you do here! :)


Xaron(Posted 2013) [#144]
Looks like there is a new problem with the width and height of textures now:

format_code('
Method loadParticleTexture:Void( texFile:String, texFrames:Int )
If( _particleTexture ) FreeTexture( _particleTexture )
_particleTexture = LoadTexture( texFile, 2+16+32 )
If( Not _particleTexture ) Error "COULD NOT LOAD PARTICLE TEXTURE: " + texFile
_textureFrames = texFrames
_textureFrameSize = TextureWidth( _particleTexture ) / _textureFrames
_textureNumFrames = TextureWidth( _particleTexture ) / _textureFrameSize
_uvUnit = 1.0 / Float( _textureNumFrames )
EntityTexture( _mesh[0], _particleTexture )
EntityTexture( _mesh[1], _particleTexture )
End Method
')

The function TextureWidth returns 0 now even though the texture has been loaded correctly...


Midimaster(Posted 2013) [#145]
@AdamRedwoods:

Do you follow also the minib3d tutorial thread? A user tells about problems on his Samsung tablet (GT-N8013) with Android 4.1.1:

When he runs the "Sprite.monkey" code he gets a white floor instead of a green one:

format_code('Floor=CreateGrid(15,15)
Floor.ScaleEntity 10,1,10
Floor.PositionEntity -2,0,8
Floor.EntityColor 55,195,55
')

On HTML5 or my Samsung GT-S53000 Android 2.3 it works perfect.


The second behavior he noticed, is that sprites in a distance of 1.10 to the camera will not be drawn. On HTML5 or on my Android 2.3 I can near them until 1.01

format_code('Button=LoadSprite("text.png",2,Camera)
Button.ScaleEntity 1.01 , 0.1 , 0.01
Button.MoveEntity 0 , -0.7 , 1.01
')


AdamRedwoods(Posted 2013) [#146]
The function TextureWidth returns 0 now even though the texture has been loaded correctly...


i now allow an empty texture to be returned if the file isn't loaded. not sure if this is bad practice or not, but it keeps everything from crashing.
i have a TPixmap.IsLoaded() that I check, perhaps i need to put it into texture and sprites loads as well.

The second behavior he noticed, is that sprites in a distance of 1.10 to the camera will not be drawn.

i'll have to look into this. i use android 4.1.1 and 2.2.1 for testing.


Xaron(Posted 2013) [#147]
Thanks Adam, so what would be best practice then to avoid that? Preload everything like it's necessary for HTML5? I loaded the texture before I did this call...


Raul(Posted 2013) [#148]
@Midimaster:

Same issues with camera and floor texture I found here:
http://www.monkeycoder.co.nz/Community/posts.php?topic=5070


Midimaster(Posted 2013) [#149]
@raul
yes.. I informed Adam about your problem. You are the "user" I'm talking about... in #145


Raul(Posted 2013) [#150]
@Midimaster: oh, i didn't notice that. just wanted to confirm it. Thanks,


EdzUp(Posted 2013) [#151]
Anyone have any idea why this happens on Linux?

I can compile BlitzMax code on the machine just monkey throws a wobbler

Heres the error log:
format_code('
"/media/edzup/8GIG/BRL/MonkeyPro72a/bin/transcc_linux" -target=Glfw_Game -config=Debug -run "/media/edzup/8GIG/BRL/Projects/MeshEdit/MeshEdit.monkey"
TRANS monkey compiler V1.49
Parsing...
miniB3D opengl11
Semanting...
Translating...
Building...
g++ -I../glfw/include -I../glfw/lib -I../glfw/lib/x11 -I../openal/include -I../stb -D_GLFW_HAS_GLXGETPROCADDRESS -D_GLFW_USE_LINUX_JOYSTICKS -pthread -c -o ../main.o ../main.cpp
../main.cpp: In function ‘void _glGenBuffers(int, Array<int>, int)’:
../main.cpp:4094:44: error: ‘glGenBuffers’ was not declared in this scope
../main.cpp: In function ‘void _glDeleteBuffers(int, Array<int>, int)’:
../main.cpp:4098:47: error: ‘glDeleteBuffers’ was not declared in this scope
../main.cpp: In function ‘void _glGetBufferParameteriv(int, int, Array<int>, int)’:
../main.cpp:4238:55: error: ‘glGetBufferParameteriv’ was not declared in this scope
../main.cpp: In function ‘void _glBufferData(int, int, BBDataBuffer*, int)’:
../main.cpp:4242:54: error: ‘glBufferData’ was not declared in this scope
../main.cpp: In function ‘void _glBufferSubData(int, int, int, BBDataBuffer*)’:
../main.cpp:4246:58: error: ‘glBufferSubData’ was not declared in this scope
../main.cpp: In member function ‘virtual int c_OpenglES11::p_UpdateVBO(c_TSurface*)’:
../main.cpp:7978:45: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:7995:46: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8009:46: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8019:44: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp: In member function ‘virtual void c_OpenglES11::p_Render(c_TEntity*, c_TCamera*)’:
../main.cpp:8356:47: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8386:53: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8397:54: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8408:49: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8690:49: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8696:49: error: ‘glBindBuffer’ was not declared in this scope
make: *** [../main.o] Error 1
TRANS FAILED: Error executing 'make CCOPTS="" OUT="Debug/MonkeyGame"', return code=512
Done.
')

and the source:
format_code('
'
' MeshEdit.monkey - Copyright (C)EdzUp
' Programmed by Ed 'EdzUp' Upton
'

Import minib3d
Import mojo

Function Main:Int()
New MainClass

Return( 0 )
End

Global Camera:TCamera
Global MoveForward:Int
Global MoveRotate:Int

Class MainClass Extends App
Global ReloadAll:Bool = False
Global InitGlobal:Int

Method OnResume()
ReloadAll = True
End

Method Init:Int()
If InitGlobal Then Return 1

'preload textures
' If Not TPixmap.PreLoadPixmap(["blue_square.png", "blue_triangle.png", "sky.png", "monkey.png", "tabletJoystick.png", "tabletJoystickStick.png" ])
' Return 0
' Endif

InitGlobal =1

AmbientLight 255, 255, 255
Camera = CreateCamera()
End

Method OnCreate()
SetRender()
SetUpdateRate( 60 )
End

Method OnUpdate()
If Not Init() Then Return 'make sure its all loaded

If ReloadAll
Graphics3DInit()
ReloadAllSurfaces()
ReloadAllTextures()
Print "....reload complete...."
ReloadAll = False
Endif

If KeyDown(KEY_ESCAPE) Then Error ""

MoveForward = 0
MoveRotate = 0

If KeyDown( KEY_LEFT )=1 Then MoveRotate = -1
If KeyDown( KEY_RIGHT )=1 Then MoveRotate =1
If KeyDown( KEY_UP )=1 Then MoveForward = 1
If KeyDown( KEY_DOWN )=1 Then MoveForward = -1

Select MoveForward
Case -1
Camera.MoveEntity( 0, 0, -.3 )
Case 1
Camera.MoveEntity( 0, 0, .3 )
Default
End

Select MoveRotate
Case -1
Camera.TurnEntity( 0, 1, 0 )
Case 1
Camera.TurnEntity( 0, -1, 0 )
Default
End
End

Method OnRender()
If Not Init() Then Return
SetMojoEmulation()
'mojo drawing goes in here
RenderWorld()
End
End
')


AdamRedwoods(Posted 2013) [#152]
slenkar posted this to get it to work on Linux:

format_code('
did a little bit of google research and got it to compile on linux

go into:
Monkey/targets/glfw/template/


make sure the line in the makefile looks like this


LDLIBS=-lGL -lopenal -lX11 -lpthread -lrt

and at the top of main.cpp add this:
#define GL_GLEXT_PROTOTYPES
')

seems like some of that is in the latest monkey, except for the define part. i would put the define part under this part of main.h instead:
format_code('#elif __linux
#define GL_GLEXT_PROTOTYPES
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pthread.h>
#endif
')
i don't have linux so let me know if this works.


sionco(Posted 2013) [#153]
@AdamRedwoods
Thanks, that worked (I had the same problem)

I put
LDLIBS=-lGL -lopenal -lX11 -lpthread -lrt in the makefile
and followed your suggestion of putting #define GL_GLEXT_PROTOTYPES in the main.h file


dawlane(Posted 2013) [#154]
It's been a bit since I messed with monkey and the fix will work, but I get warnings about pointer size being different as I'm on a 64bit OS.

@AdamRedWoods: The main.h file didn't need to be modified passing a such thing can be achieved by the make file.
Adding -DGL_GLEXT_PROTOTYPES to the end of CPPFLAGS=$(CCOPTS) would do just as well. I have to do a few of these thing to get any thing monkey glfw related to build on my system. And I'm sure -lrt isn't needed any more as I'm possitive that it's been added as a filter with libc. You would only add that for backward compatibility with an older OS.

A few more directives of interest which you would find in the glfw/lib/x11/platform.h

-D_GLFW_HAS_GLXGETPROCADDRESS
-D_GLFW_USE_LINUX_JOYSTICKS
-D_GLFW_HAS_XF86VIDMODE
-D_GLFW_HAS_SCHED_YIELD
-D_GLFW_HAS_SYSCONF
-pthread

It would be nice if Mark add an easy way so you can pass such things in monkey code as if things keep getting added to the make file it will get to be too big to manage in the end.


EdzUp(Posted 2013) [#155]
@Adam:will test it when I get back :-)

Having minib3d on there would be a godsend :-)


Xaron(Posted 2013) [#156]
Adam, I still have this problem here: http://monkeycoder.co.nz/Community/post.php?topic=5016&post=60760

I even preloaded the texture but it still don't work...

Edit: Here's a demo example using my particle candy module:
http://www.leidel.net/dl/monkey/pdemo.zip

Compile this to GLFW and it will crash because of that texture thing. Maybe you could be so kind to tell me how I can prevent this? Thanks!


AdamRedwoods(Posted 2013) [#157]
ok thanks for the example, updated github (tpixmap and mojographics).
works now, all targets.
v0.38.2


Xaron(Posted 2013) [#158]
Thanks Adam, works now! :)


Xaron(Posted 2013) [#159]
Ok, how's the state with OpenGL ES 2.0 for Android/iOS? At the moment I get compiler errors.

The problem with OGL 1.1 is that there are tons of problems with the Adreno 225 GPU which is used by the Samsung S3 for instance. I have missing textures there.

The problem is described here:
http://www.shivaengine.com/developer/forum/viewtopic.php?p=60882

Solution is to use OGL 2.0 or to apply this:
"During the IwGL startup, glGetString(GL_VERSION) is called, among other purposes, to check for the CommonLite profile in order to switch to fixed point texture matrix arithmetic. It does it by looking for the "CL" substring in the returned string.

The cause of the problem is that the Motorola Razr M (and probably more Adreno 225 devices) returns "OpenGL ES-CM 1.1 hide_email('V@2.0') AU@ (CL@2726865)&#34;, which contains that "CL" substring but not meaning "CommonLite". Therefore, Marmalade enables fixed point texture matrices when it shouldn't.

By enabling detailed GL trace, you can see that under this scenearios IwGx is calling the fixed-point version of the relevant function (glLoadMatrixx()) instead of the floating-point one (glLoadMatrixf()), which is the one called usually."



AdamRedwoods(Posted 2013) [#160]
wow that's a mean thing for Adreno engineers to do.

anyways, opengles2.0 works, the shaders are a little slow (need to write a complex shader matrix to choose per-pixel lighting on/off).

but it seems Monkey has a bug in the gles20 android module. I'll report it.
http://monkeycoder.co.nz/Community/posts.php?topic=5589


AdamRedwoods(Posted 2013) [#161]
EDIT:
v0.39
ok, i think i have a bit of a texture matrix going to opengles20. still only one light available, but will have to do for now until i can get a better shader matrix in. nice speed improvements for opengles20, though.

so it defaults to vertex lighting, to get per pixel lighting (which is slower) use:
format_code('
SetRender(RENDERFLAG_PERPIXELLIGHTING)
')


Xaron(Posted 2013) [#162]
Edit: Nevermind, that's exactly what you've described. Oh well, have to drink my coffee...

Thanks but no, Android does not compile with gles20:

format_code('
-compile:
[javac] Compiling 4 source files to D:\Leidel\Projekte\SilentDepth\SilentDepth.build\android\bin\classes
[javac] D:\Leidel\Projekte\SilentDepth\SilentDepth.build\android\src\com\codeknitters\silentdepth\MonkeyGame.java:17715: error: cannot find symbol
[javac] if((bb_opengl_gles20.LoadImageData((t_buf),t_path,t_info))!=null){
[javac] ^
[javac] symbol: method LoadImageData(c_DataBuffer,String,int[])
[javac] location: class bb_opengl_gles20
[javac] Note: D:\Leidel\Projekte\SilentDepth\SilentDepth.build\android\src\com\codeknitters\silentdepth\MonkeyGame.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
')


Xaron(Posted 2013) [#163]
Ok, works with Android now, pretty slow but it works. GLFW doesn't show anything.


Xaron(Posted 2013) [#164]
Hey Adam, thanks for the last fixes! I some questions regarding collisions:

1) CollisionSetup

I see I can give some more parameters there like x,y,z and width,height,depth. Is that the same as I set with EntityBox for instance? Do I have to set these values or to rephrase: How does the collision setup method get the size of the object?

2) Collision types

I see I can set a type in CollisionSetup and in the Collisions command itself. What's the difference there? Are Polygon-to-Polygon collisions possible?

3) Response types

What's the difference between COLLISION_RESPONSE_SLIDE and COLLISION_RESPONSE_SLIDEXZ?

Thanks!


AdamRedwoods(Posted 2013) [#165]
1. CollisionSetup will automatically grab the bounding sphere size or bounding box of the object if no values are set. Pick TYPE determines the initial shape. setting these values will manually set the size of the box or sphere, which is centered at the mesh's center which is centered for a sphere, but a box is offset at the corner (ie a cube would be EntityBox(cube, -0.5,-0.5,-0.5,1.0,1.0,1.0)).

2. CollisionSetup, the TYPE parameter is to define the pick mode, not object-to-object collisions. Using Collisions() sets the object-to-object collision type, which includes source-sphere to destination-polygon. there is no polygon-to-polygon as that is very expensive (but theoretically could be done, check both objects as sources). I recommend using multiple source spheres for specific collision points.

3. COLLISION_RESPONSE_SLIDE will slide the source object around the destination object according to the collision normal and source movement. COLLISION_RESPONSE_SLIDEXZ limits this to just the XZ plane (no Y sliding) which is good for walking around and such, but cannot go up ramps or walls.


Xaron(Posted 2013) [#166]
So let's take an example. E.g. we have two ships (meshes) which can collide.

I thought about to just setup it that way:

CollisionSetup( submarineMesh, COL_SUBMARINE, COLLISION_METHOD_BOX, 0, 0, 0, MeshWidth( submarineMesh ), MeshDepth( submarineMesh ), MeshHeight( submarineMesh ) )
CollisionSetup( shipMesh, COL_SHIP, COLLISION_METHOD_BOX, 0, 0, 0, MeshWidth( shipMesh ), MeshDepth( shipMesh ), MeshHeight( shipMesh ) )
Collisions( COL_SUBMARINE, COL_SHIP, COLLISION_METHOD_BOX, COLLISION_RESPONSE_SLIDE )

Even though that somehow works the collision boxes just don't fit (both meshes are centered correctly). So how am I supposed to setup this stuff correctly with two meshes? Collision boxes would be enough for me!


Xaron(Posted 2013) [#167]
Just saw you answered it a bit. I scratch my head about this collision stuff since the good old Blitzbasic days. lol

So using multiple spheres would be another good way, indeed? Could you please share a small example with me? Thanks so much!


Xaron(Posted 2013) [#168]
I think I got it mostly. What I still don't completely understand is the size of a collision box/sphere.

I set these values with EntityBox and EntityRadius, right? So when I set EntityBox( ent, x, y, z, w, h, d ) does that mean using w,h,d of 1,1,1 it's the same size as a cube (CreateCube) with standard scaling (1,1,1)? x,y,z of the EntityBox are the center of that cube?

Thanks again for answering such a possibly stupid question!


AdamRedwoods(Posted 2013) [#169]
ok, i was wrong. you can ONLY use one sphere/box for the collision response (but you can use multiple for collision triggers).

and for EntityBox(ent, x,y,z,w,h,d) the x,y,z is NOT the center but the corner. so a cube of 1,1,1 would be EntityBox(cube, -0.5,-0.5,-0.5, 1.0,1.0,1.0).
Confusing, which is why it messes me up, too!


Sammy(Posted 2013) [#170]
I'm a bit foggy here, is this how the original iMiniB3D operated collisions(non-centred)?


Xaron(Posted 2013) [#171]
Thanks Adam! How about EntityRadius with both parameters? I guess this would fit nearly perfect for ships when I use a "stretched" sphere...


Xaron(Posted 2013) [#172]
Hey Adam, I think I've discovered a bug? Using your minib3d_collision_test.monkey example:

format_codebox('

''Collision example
Import mojo
Import minib3d

Function Main()
New Game
End

Class Game Extends App

Field width:Int=640,height:Int=480,depth:Int=0,mode:Int=2

Field cam:TCamera , cam2:TCamera

Field light:TLight
Field cube:TMesh
Field sphere1:TMesh, sphere2:TMesh, cylinder:TMesh
Field cone:TMesh
Field dot:TMesh, monkey:TMesh, dot3:TMesh
Field testmesh: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 dotx:Float, dotdir:Float=0.5

Field whitebrush:TBrush
Field redbrush:TBrush, greenbrush:TBrush

Field tex1:TTexture

Field init_gl:Bool = False

Method OnCreate()
SetUpdateRate 30
End

Method Init()

If init_gl Then Return
init_gl = True

SetRender()

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

dot = CreateSphere()
dot.ScaleEntity (0.1,0.1,0.1)
dot.EntityColor(255,0,0)
dot.PositionEntity(0.0,1.1,0.0)

monkey = CreateCube()
'monkey = CreateMiniB3DMonkey()

'monkey.EntityColor(200,200,255)
'monkey.ScaleEntity(0.2,0.2,0.2)
monkey.ScaleEntity(0.2,0.2,0.2)
'monkey.PositionEntity(0.5,-0.5,0.0)
monkey.PositionEntity(-0.39,-0.5,-1.2)


dot3 = CreateSphere()
dot3.ScaleEntity (0.1,0.1,0.1)
dot3.EntityColor(0,200,0)

light=CreateLight(1)

'sphere1 = CreateSphere()
sphere1 = CreateCube()
'sphere1 = LoadMesh("zombie_b3d_base64.txt")
'sphere1=CreateMesh()

cylinder = CreateCylinder()
cone = CreateCone()

txt = CreateText2D()
txt.HideEntity()

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

'PositionEntity cube,-2,0,0
PositionEntity sphere1,-1,-0.5,0
'sphere1.RotateEntity(145,145,0)
ScaleEntity sphere1,0.7,0.7,0.7
PositionEntity cylinder,2,0,5
PositionEntity cone,4,0,0
RotateEntity cone,-90,0,0

cylinder.EntityParent(cone, True)


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

redbrush = New TBrush
redbrush.BrushColor(200,20,20)

greenbrush = New TBrush
greenbrush.BrushColor(20,200,20)

sphere1.PaintEntity( whitebrush)
cylinder.PaintEntity(greenbrush)
cylinder.EntityAlpha(0.7)


'' new method CollisionSetup(group_id, collision method, size of sphere or box)

cone.CollisionSetup(1, COLLISION_METHOD_POLYGON, 1.0)
sphere1.CollisionSetup(1, COLLISION_METHOD_BOX, 1.0)
monkey.CollisionSetup(1, COLLISION_METHOD_POLYGON)

cylinder.CollisionSetup(1, COLLISION_METHOD_POLYGON, 2.0) '-1.0,-1.0,-1.0,2.0,2.0,2.0)
cylinder.RotateEntity(0,0,45)

Collisions(1,1,COLLISION_METHOD_POLYGON,COLLISION_RESPONSE_SLIDEXZ)

sphere1.EntityFX(2)
cone.EntityFX(2)

old_ms=Millisecs()


'Wireframe(True)

Print "main: intit done"
End

Method OnUpdate()

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

If Not init_gl Then Return

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

Local lr2:Float = KeyDown(KEY_H)-KeyDown(KEY_F)
Local ud2:Float = KeyDown(KEY_T)-KeyDown(KEY_G)

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,lr2,0,ud2
cam.TurnEntity ud,lr,0



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

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

'Print CollisionTriangle(sphere1,1)
'Print "pt: "+PickedTriangle()

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

dot.PositionEntity(PickedX(),PickedY(),PickedZ())

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


monkey.MoveEntity(camup*0.1,0,camin*0.1)

'dot.PositionEntity(CollisionInfo.testx,CollisionInfo.testy,CollisionInfo.testz)
If monkey.collision.impact Then dot.PositionEntity( monkey.CollisionX(), monkey.CollisionY(), monkey.CollisionZ())

Print "mx: " + EntityX( monkey ) + " my: " + EntityY( monkey ) + " mz: " + EntityZ( monkey )

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


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

UpdateWorld()


End

Method OnRender()
Init()

RenderWorld()

renders=renders+1


End

End
')

In line 60 use a cube instead of the monkey
monkey = CreateCube()

In line 66 set the following position:
monkey.PositionEntity(-0.39,-0.5,-1.2)

Now start it and just press "W". You can see how the cube clearly intersects with the bigger cube behind...


Xaron(Posted 2013) [#173]
Well that looks like an issue with larger objects. When I scale down everything it works fine. But using a size of 1,1,1 isn't that large, isn't it?

Edit: Further investigation shows that collisions don't work at all if you use two cubes of exact the same size.


AdamRedwoods(Posted 2013) [#174]
so it works if you leave the 1.0 off, which then sets it automatically.

i guess the default size of a cube is w=2,h=2,d=2 . does that sound right?
then if the scale is 0.7, then the cube is still larger than 1.0, so it works...

ok problem #2:
if the cubes are the same size it doesn't work. that is true. i'll look into that.


Xaron(Posted 2013) [#175]
Thanks Adam, I've sent you a more detailed example. ;)


EdzUp(Posted 2013) [#176]
on linux its throwing the not declared in this scope stuff again on 73a


Xaron(Posted 2013) [#177]
Is it possible to speed up the mojo emulation stuff. It becomes pretty slow on Android (gles 20) using some (below 10) images on screen.


AdamRedwoods(Posted 2013) [#178]
v0.39.1 - mojographics.monkey
i've added a small speedup. try that, let me know if it breaks anything.

re:linux
i'll need to install linux at some point to test it. if it's the same error, try the prior fix, and if that works add an entry into the bugs forum.


EdzUp(Posted 2013) [#179]
It dont work here with the prior fix which is a pain :/


AdamRedwoods(Posted 2013) [#180]
did you just download it? try again, i forgot to remove something. if it doesn't work, then post the error.


Xaron(Posted 2013) [#181]
Hey Adam, no that did not change anything but as I can see you removed some local unused variables which the compiler does anyway? ;)

What I noticed is that gles11 is about 50% faster than gles20 on Android.


AdamRedwoods(Posted 2013) [#182]
I can see you removed some local unused variables

no, in mojographics, i changed it so it won't remake the buffers every frame.

i don't suppose you can profile it using DDMS?


EdzUp(Posted 2013) [#183]
Will download it and try again :)


Xaron(Posted 2013) [#184]
Thanks Adam, I'll test it with DDMS. Let's see where the bottle necks are!


EdzUp(Posted 2013) [#185]
righty using the latest monkey (experimental 73b) and downloading the latest minib3d build I get:

format_code('
"/media/edzup/8GIG/BRL/MonkeyPro73b/bin/transcc_linux" -target=Glfw_Game -config=Debug "/media/edzup/8GIG/BRL/Projects/A.I/AI.monkey"
TRANS monkey compiler V1.51
Parsing...
miniB3D opengl11
Semanting...
Translating...
Building...
g++ -I../glfw/include -I../glfw/lib -I../glfw/lib/x11 -I../openal/include -I../stb -D_GLFW_HAS_GLXGETPROCADDRESS -D_GLFW_USE_LINUX_JOYSTICKS -pthread -c -o ../main.o ../main.cpp
../main.cpp: In function ‘void _glGenBuffers(int, Array<int>, int)’:
../main.cpp:4127:44: error: ‘glGenBuffers’ was not declared in this scope
../main.cpp: In function ‘void _glDeleteBuffers(int, Array<int>, int)’:
../main.cpp:4131:47: error: ‘glDeleteBuffers’ was not declared in this scope
../main.cpp: In function ‘void _glGetBufferParameteriv(int, int, Array<int>, int)’:
../main.cpp:4271:55: error: ‘glGetBufferParameteriv’ was not declared in this scope
../main.cpp: In function ‘void _glBufferData(int, int, BBDataBuffer*, int)’:
../main.cpp:4275:54: error: ‘glBufferData’ was not declared in this scope
../main.cpp: In function ‘void _glBufferSubData(int, int, int, BBDataBuffer*)’:
../main.cpp:4279:58: error: ‘glBufferSubData’ was not declared in this scope
../main.cpp: In member function ‘virtual int c_OpenglES11::p_UpdateVBO(c_TSurface*)’:
../main.cpp:8894:45: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8911:46: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8925:46: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:8935:44: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp: In member function ‘virtual void c_OpenglES11::p_Render(c_TEntity*, c_TCamera*)’:
../main.cpp:9274:47: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:9304:53: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:9315:54: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:9326:49: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:9608:49: error: ‘glBindBuffer’ was not declared in this scope
../main.cpp:9614:49: error: ‘glBindBuffer’ was not declared in this scope
TRANS FAILED: Error executing 'make CCOPTS="" OUT="Debug/MonkeyGame"', return code=512
make: *** [../main.o] Error 1
Done.
')

Ive done the thing in post 152 to no avail is there anything im missing?

will keep playing and see if there is something else.


AdamRedwoods(Posted 2013) [#186]
those errors are from the opengl EXT during compiling, so i suspect
"#define GL_GLEXT_PROTOTYPES" is missing from the targets/glfw/templates/main.h for the #elif __linux section? if that doesn't work, i wonder if we need a glext header file somewhere else, too.


EdzUp(Posted 2013) [#187]
Well i added the #define like it said to the if block but still get errors ao i think theres a missing header somewhere


Xaron(Posted 2013) [#188]
Part 7? This thread has become long. ;)

Adam, I just tried to create my own shader, which is just a copy of your Fullshader (GLES20).

It looks like:
format_codebox('
Strict

Import opengl.gles20
Import minib3d.opengl.tshaderglsl

Class LightShader Extends TShaderGLSL

Global init_id:Int=0
Global global_uniforms:ShaderUniforms
Global shader:TShaderGLSL[10]

Method New()

MAX_TEXTURES = 4
MAX_LIGHTS = 1

name = "LightShader"

If( init_id = 0 And shader_id = 0 )
shader[0] = New MultiShader(0,1,0)
shader[1] = New MultiShader(1,1,0)
shader[2] = New MultiShader(0,1,1)
shader[3] = New MultiShader(1,1,1)
shader[4] = New MultiShader(0,1,2)
shader[5] = New MultiShader(1,1,2)
shader[6] = New MultiShader(0,1,3)
shader[7] = New MultiShader(1,1,3)
shader[8] = New MultiShader(0,1,4)
shader[9] = New MultiShader(1,1,4)

init_id = shader[0].shader_id
shader_id = shader[0].shader_id

If shader[0].active Then Dprint "..LightShader success"
active = shader[0].active

Else If init_id
shader_id = init_id ''use same shader
u = global_uniforms ''use same uniforms
active = 1
End If
End Method

Function GetShader:TShaderGLSL(ppl:Int=0, num_lights:Int=1, num_texs:Int=0)
Return shader[2*num_texs+ppl]
End
End Class
')

... so really a copy of your Fullshader.

I instantiate it with:
format_code('
TShader.LoadDefaultShader( new LightShader )
')

But I just see nothing then. Using the same command with your FullShader and FastBrightShader works just fine. Do I miss something here?

Cheers!