Another attempt at 3D external using openb3d

Are you developing an External using the LiveCode Externals SDK?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Another attempt at 3D external using openb3d

Post by n.allan » Fri Jun 20, 2014 8:59 am

Hello, Continuing my mad obsession with 3D externals for windows Livecode, I have thrown together another one.

This one uses the OpenB3D library. OpenB3D uses openGL and is primarily intended for use in FreeBASIC. It has a long history too. From what I can gather....

Blitz3D used Direct X 7 and was discontinued, a new cross platform language was created, BlitzMax. BlitzMax users wanted 3D functionality that was cross platform....Enter MiniB3D.

It started out as MiniB3D. MiniB3D gave BlitzMax users Blitz3D functionality. It was also "extended" giving BlitzMax users a more complete 3D replacement for Blitz3D such as terrains etc... It was then ported to IOS, creating iMiniB3D. iMiniB3D was then stripped of it's objective c ties to create OpenB3D.

OpenB3D is still under development. It currently supports win32 and linux and has recently been ported to OSX for use in BlitzMax. so I got to thinking...

I have created an external for livecode that takes the livecode stack and creates an opengl context, the stack then loads the functions explicitly from the openb3d.dll and maps them to livecode functions and commands. They are mapped in such a way that it is fairly true to the original Blitz3D syntax (which I liked)

global camera
put CreateCamera() into camera etc...

The only thing I really did was create the context and openB3D does the rest. It is a remarkable library!

I will upload my wrapper dll and source later if anyone is interested. Maybe someone in the know could add an opengl context in Linux and OSX too, maybe even IOS!

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Another attempt at 3D external using openb3d

Post by n.allan » Sat Jun 21, 2014 3:34 pm

OK, here are some bits and pieces.

The attached zip file has the compiled external extopenb3d.dll, the source for it, the ubiquitous Utah teapot model and a couple of stacks to test.

As well as these files, you will need to go onto sourceforge and download the latest openb3d.dll for win32. (For these tests I used V0.7).

Once you have the openb3d.dll, put it alongside these files OR stick it in your system32 / sysWOW64 folder (depending if you are running a 32 or 64 bit win32.

All commands are available (but not tested) Most are documented on Blitz3D docs website and some are not ( such as stencils, shadows and stuff ). If anyone wants I could rattle up some instructions or whatever.

There are only two major differences to the command set:

1. Graphics3D needs the title of the window passed to it along with the width and height (so that we can grab the handle) This will probably change in the future so I can go fullscreen, open another window or something I shall have to have a think about it.

2. Since "Flip" is a reserved keyword in LC I have used "Swap" instead.

You must call "Graphics3D before calling any other commands.

I'm not going to go in to too much detail at the moment unless anyone else wants info due to the fact that this murky section of the forum is not frequented by a lot of people.
Attachments
extopenb3d.zip
extopenb3d external for Livecode win32
(173.98 KiB) Downloaded 547 times

xAction
Posts: 86
Joined: Sun Oct 03, 2021 4:14 am

Re: Another attempt at 3D external using openb3d

Post by xAction » Sun Oct 24, 2021 2:59 pm

Hmm, .dll in externals folder, in livecode folder, in SySWoW64 folder, set the externals of this stack to path on my hard drive instead of yours still can't find external.

paul@researchware.com
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 135
Joined: Wed Aug 26, 2009 7:42 pm
Location: Randolph, MA USA
Contact:

Re: Another attempt at 3D external using openb3d

Post by paul@researchware.com » Mon Oct 25, 2021 1:19 pm

Is this an old style External or a LC9 widget/library (i.e the DLL is wrapped using LiveCode Builder)?
Paul Dupuis
Researchware, Inc.

xAction
Posts: 86
Joined: Sun Oct 03, 2021 4:14 am

Re: Another attempt at 3D external using openb3d

Post by xAction » Mon Oct 25, 2021 1:40 pm

Posted in 2014, I'm guessing not LC9 Widget Builder thing.
Downloaded 322 times and nobody got it working...

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Another attempt at 3D external using openb3d

Post by n.allan » Tue Oct 26, 2021 3:27 pm

Downloaded 322 times and nobody got it working...
I did loool. Thanks for letting me know.

I got this going again just now (26th Oct 2021) using this recipe.
Originally this was tested on 32 bit windows XP so that's what I have used here in a virtual machine.

Download and install LiveCode V8.0.2 (The last version that worked semi OK on windows XP)
Download the original extopenb3d.zip attachment from above
Download V0.7 of OpenB3D.dll https://osdn.net/frs/g_redir.php?m=jais ... +win32.zip
Dropped the OpenB3D.dll into c:\Windows\System32 folder
dropped the extopenb3d.dll external into C:\Program Files\RunRev\LiveCode Business 8.0.2\Externals folder
in that folder there is a file called "externals.txt". Edit that file and add the line to the bottom "extopenb3d,extopenb3d.dll"

Now when you load the IDE you should have access to the 3D commands.

I extracted the attached zip file to my desktop. There should be 3 files. The livecode stack, 3d model and sphere map.

Double click on the stack to launch it and there should be spinning teapot.

---------------------

I haven't tested this on Windows 10 \ 64 Bit \ LiveCode 9 etc... and don't really intend to because nowadays this should be done using the LiveCode Builder FFI. In theory all we need to do is get/create an OpenGL context from a widget and start issuing the 3D commands. I have tried in the past but LCB stuff is beyond me at the moment.
Attachments
3D_V8.0.2_Oct 2021.zip
(77.17 KiB) Downloaded 206 times

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Another attempt at 3D external using openb3d

Post by n.allan » Tue Oct 26, 2021 4:22 pm

OK so it works in windows 10 64 bit as well.

Installed 8.0.2 on windows 10 64 bit.
dropped openb3d.dll into Windows\SysWoW64 folder
dropped extopenb3d.dll external into C:\Program Files (x86)\RunRev\LiveCode Business 8.0.2\Externals then modified the external.txt file as above

Screenshots for both xp and win 10 below are attached
Attachments
Screenshot 2021-10-26 at 14.53.59 low.jpg
Screenshot 2021-10-26 at 16.14.18.jpeg

xAction
Posts: 86
Joined: Sun Oct 03, 2021 4:14 am

Re: Another attempt at 3D external using openb3d

Post by xAction » Wed Oct 27, 2021 8:52 am

I guess its a dead end for free loaders using last community edition. Maybe there will be another pandemic and I can get a low priced Livecode again.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9249
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Another attempt at 3D external using openb3d

Post by richmond62 » Wed Oct 27, 2021 11:49 am

I guess its a dead end for free loaders using last community edition.
I wonder how accurate "free loaders" is when one considers how the contributions with advice and sample code
has dwindled to a trickle with the removal of the community editions?

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Another attempt at 3D external using openb3d

Post by n.allan » Thu Oct 28, 2021 4:15 pm

Jeezo I just noticed they have removed every community download. What a waste! :shock:

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Another attempt at 3D external using openb3d

Post by Klaus » Thu Oct 28, 2021 4:37 pm

They are still hosting them here: https://community.livecode.com

xAction
Posts: 86
Joined: Sun Oct 03, 2021 4:14 am

Re: Another attempt at 3D external using openb3d

Post by xAction » Thu Oct 28, 2021 9:08 pm

WELL HOT DOG! IT WORKED! Thanks Klaus and n. allan!
So what changed from 8 to 9 that killed this kind of feature ?

Well the new stack works the old ones pop an error dialogue with no info.
Oh wait, i fixed something?
I moved the OpenStack to card script of the old teapot and it worked.
Then I opened the new teapot and it stole the 3D context.
There can only be one!

Cool, moved the stack script of shadow test to the card script. Now it's workin.

Works on Community 8.1.10 Shadow test died on that.
Built app out of 8.0.2 crashes, on start up. 8.1.10 too.
Moved externals into Runtime folder, then a copy in with with the built exe, builds work.

Sooo what was this stuff about creating a GL context in Extensions Builder?

And what was the process behind building this .dll? I downloaded the updated openb3D.dll to test but then I realized there was no external built against it.

Quick Reference:
  • The external commands of the stack ,ie DLL
    CameraClsColor
    BrushAlpha
    BrushColor
    Animate
    AntiAlias
    AmbientLight
    AddMesh
    MeshCullRadius
    TexToBuffer
    BackBufferToTex
    BufferToTex
    Swap
    BrushShininess
    BrushFX
    BrushBlend
    BrushTexture
    CameraViewport
    ClearTextureFilters
    CameraZoom
    ClearWorld
    CameraClsMode
    CameraProject
    CameraProjMode
    ClearCollisions
    CameraFogColor
    CameraFogMode
    Collisions
    ClearSurface
    CameraRange
    CameraFogRange
    EntityAutoFade
    EntityBlend
    EntityBox
    EntityColor
    EntityFX
    EntityAlpha
    EntityShininess
    EntityRadius
    EntityPickMode
    FitMesh
    EntityParent
    FreeBrush
    FreeTexture
    FreeShadow
    EntityOrder
    FlipMesh
    FreeEntity
    EntityType
    EntityTexture
    HideEntity
    PaintEntity
    LightRange
    MoveEntity
    ModifyTerrain
    PaintMesh
    HandleSprite
    LightConeAngles
    LightColor
    PaintSurface
    NameEntity
    Graphics3D
    SetCubeMode
    ResetEntity
    ScaleSprite
    StencilMesh
    PositionMesh
    RotateMesh
    RotateTexture
    ScaleEntity
    PointEntity
    RotateSprite
    RotateEntity
    RenderWorld
    ScaleMesh
    ScaleTexture
    ShowEntity
    StencilAlpha
    StencilMode
    PositionTexture
    SetCubeFace
    SpriteViewMode
    PositionEntity
    StencilClsColor
    SetAnimTime
    VertexNormal
    TurnEntity
    TFormVector
    UpdateWorld
    TranslateEntity
    TextureFilter
    TextureBlend
    TFormPoint
    UpdateNormals
    TFormNormal
    UseStencil
    UpdateTexCoords
    VertexColor
    TextureCoords
    VertexCoords
    ShadeEntity
    SetFloat4
    UseFloat
    SetInteger4
    SetFloat
    UseFloat2
    UseFloat4
    ShadeMesh
    SetFloat2
    SetFloat3
    UseFloat3
    SetInteger
    SetInteger2
    SetInteger3
    ShadeSurface
    UseInteger
    VoxelSpriteMaterial
    Wireframe
    VertexTexCoords
    ShaderTexture
    UseInteger4
    ShaderMaterial
    UseSurface
    UseInteger2
    AddToOctree
    UseMatrix
    UseInteger3

n.allan
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Mon Mar 12, 2007 12:06 pm

Re: Another attempt at 3D external using openb3d

Post by n.allan » Thu Nov 11, 2021 9:19 pm

Sorry for the late reply I normally get notified of a reply on here but it appears not...
WELL HOT DOG! IT WORKED!
I'm glad someone had some success. I can't really offer much help with the building of standalone and including externals etc as I rarely build them. I can only assume if it works in the IDE, there is some way of using them in a standalone.
So what changed from 8 to 9 that killed this kind of feature ?
In version 8 and below, the stacks (in windows os at least) appear to be just another native window so you can grab the handle of that window and manipulate it with the windows API. It was a hack at best.

In version 9 the graphics are drawn using the skia library. I tried it in the early v9 release and you could see the teapot for a millisecond then it was immediately drawn over. I assume this was the skia library rendering the card over my teapot during the "on paint" win32 function.

As a result I gave up and never gave it a second thought. This project might become feasible again when they ditch skia in version 10.
Sooo what was this stuff about creating a GL context in Extensions Builder?
I would hold fire on this until we see what's happening with version 10. If they are dumping skia then it will be wasted time.

In this external, the gl context is hacked/created in c. The livecode windowid() is "massaged" into an HWND type and the context is created from that so that everything is painted/flipped right into your livecode stack.

The idea for LCB would be to ditch the external dll altogether and simply wrap the calls to openb3d.dll using LCB. This can be done today, right now, no problem. The problem is creating the context with skia painting over the stack every microsecond.

We could create a new separate OpenGL window easily but it kind of defeats the purpose of integrating it into LiveCode. I want to create stacks in livecode and paint to them in Livecode.

Lets see what happens with V10.
And what was the process behind building this .dll? I downloaded the updated openb3D.dll to test but then I realized there was no external built against it.
As above, the process of building the external dll may become redundant. we can simply call all the openb3d functions from LCB and it would be rather neat. We could also make calls to OS directly from LCB to create the OpenGL context.

If you are simply interested in the general process of building an external then this is essentially the same tutorial I followed back in the day https://livecode.fandom.com/wiki/Working_with_DLL (The website is a complete mess of ads and is frankly annoying.) Download the ExternalsSDK and have a play on the older versions it was quite cool IMHO. If you don't know c/cpp you can probably still get by with that tutorial.

The code for this external could probably just be pasted into that project cpp file and click build. There are no fancy libraries required. All the #includes are fairly standard

Post Reply

Return to “Building Externals”