3D engine Horde3D for FreeBASIC Jan 16, 2017

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

3D engine Horde3D for FreeBASIC Jan 16, 2017

Post by D.J.Peters »

Horde3D for FreeBASIC.

download: Horde3D.zip

homepage: http://www.horde3d.org

manual: http://www.horde3d.org/docs/manual.html

wiki: http://www.horde3d.org/wiki/

forum: http://www.horde3d.org/forums/

Joshy
Image
file: animation.bas

Code: Select all

#include once "fbgfx.bi"
#include once "Horde3D.bi"

function InitHorde3D(w as integer=640,h as integer=480) as boolean
  dim as integer bits
  screeninfo ,,bits
  ' create OpenGL context
  screenres w,h,bits,,fb.GFX_OPENGL
  flip
  ' init Horde3D
  return h3dInit()
end function

if InitHorde3D()=false then
  screen 0
  print "error: init Horde3D !"
  beep:sleep:end
end if

' get current screen size
dim as integer w,h
screeninfo w,h

' Set options
h3dSetOption(H3DOptions_LoadTextures,   1)
h3dSetOption(H3DOptions_TexCompression, 0)
h3dSetOption(H3DOptions_FastAnimation,  0)
h3dSetOption(H3DOptions_MaxAnisotropy,  4)
h3dSetOption(H3DOptions_ShadowMapSize, 1024)

' Add resources

' Pipeline
'var deferredPipeRes = h3dAddResource(H3DResTypes_Pipeline,"pipelines/deferred.pipeline.xml")
var forwardPipeRes = h3dAddResource(H3DResTypes_Pipeline,"pipelines/forward.pipeline.xml")

' Environment
var envRes = h3dAddResource(H3DResTypes_SceneGraph,"models/sphere/sphere.scene.xml")

' Knight
var knightRes      = h3dAddResource(H3DResTypes_SceneGraph,"models/knight/knight.scene.xml")
var knightAnim1Res = h3dAddResource(H3DResTypes_Animation, "animations/knight_order.anim")
var knightAnim2Res = h3dAddResource(H3DResTypes_Animation, "animations/knight_attack.anim")

' Particle system
var particleSysRes = h3dAddResource(H3DResTypes_SceneGraph, "particles/particleSys1/particleSys1.scene.xml")

' Load resources
var contentDir = exepath() + "/Content"
h3dutLoadResourcesFromDisk(strptr(contentDir))

' Add scene nodes

' Add camera
var cam = h3dAddCameraNode(H3DRootNode, "Camera", forwardPipeRes)
'var cam = h3dAddCameraNode(H3DRootNode, "Camera", deferredPipeRes)
' Setup viewport and render target sizes
h3dSetNodeParamI( cam, H3DCamera_ViewportXI, 0 )
h3dSetNodeParamI( cam, H3DCamera_ViewportYI, 0 )
h3dSetNodeParamI( cam, H3DCamera_ViewportWidthI, w )
h3dSetNodeParamI( cam, H3DCamera_ViewportHeightI, h)

' Set camera parameters (pos, rotation, scale)
h3dSetNodeTransform(cam, 0,5,20, 0,0,0, 1,1,1)

' Set camera parameters (fov,  ratio, near, far)
h3dSetupCameraView( cam, 45.0, w / h, 0.1, 1000.0 )
h3dResizePipelineBuffers( forwardPipeRes, w, h )
'h3dResizePipelineBuffers( deferredPipeRes, w, h )
' Add environment
var env = h3dAddNodes(H3DRootNode, envRes)
h3dSetNodeTransform(env, 0, -400, 0, 0, 0, 0, 400, 400, 400)

' Add knight
var knight = h3dAddNodes(H3DRootNode, knightRes)
'                           pos,   rotation,  scale
h3dSetNodeTransform(knight, 0,0,0, 0,180,0,  .1,.1,.1)
h3dSetupModelAnimStage(knight, 0, knightAnim1Res, 0, "", False)
h3dSetupModelAnimStage(knight, 1, knightAnim2Res, 0, "", False)

'' Attach particle system to hand joint
h3dFindNodes(knight, "Bip01_R_Hand", H3DNodeTypes_Joint)
var hand = h3dGetNodeFindResult(0)
var particleSys = h3dAddNodes(hand, particleSysRes)
'                                 pos,  rotation, scale
h3dSetNodeTransform(particleSys, 0,40,0,  0,0,0,  1,1,1)

#if 1
' Add light source
var light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP")
'                          pos,    rotation, scale
h3dSetNodeTransform(light, 0,1,5, 0,0,0, 1,1,1)
h3dSetNodeParamF(light, H3DLight_RadiusF, 0, 30)
h3dSetNodeParamF(light, H3DLight_FovF, 0, 90)
h3dSetNodeParamI(light, H3DLight_ShadowMapCountI, 1)
h3dSetNodeParamF(light, H3DLight_ShadowMapBiasF, 0, 0.01)
h3dSetNodeParamF(light, H3DLight_ColorF3, 0, 1) ' red
h3dSetNodeParamF(light, H3DLight_ColorF3, 1, 1) ' green
h3dSetNodeParamF(light, H3DLight_ColorF3, 2, 1) ' blue
#endif

#if 0
' Add light source
var light2 = h3dAddLightNode(H3DRootNode, "Light2", 0, "LIGHTING", "SHADOWMAP")
'                          pos,    rotation, scale
h3dSetNodeTransform(light2, 5,10,5, -45,0,0, 1,1,1)
h3dSetNodeParamF(light2, H3DLight_RadiusF, 0, 30)
h3dSetNodeParamF(light2, H3DLight_FovF, 0, 90)
h3dSetNodeParamI(light2, H3DLight_ShadowMapCountI, 1)
h3dSetNodeParamF(light2, H3DLight_ShadowMapBiasF, 0, 0.01)
h3dSetNodeParamF(light2, H3DLight_ColorF3, 0, 0.2) ' red
h3dSetNodeParamF(light2, H3DLight_ColorF3, 1, 0.2) ' green
h3dSetNodeParamF(light2, H3DLight_ColorF3, 2, 0.8) ' blue
#endif


const as single FPS = 60
dim as single t

h3dutDumpMessages()

' h3dSetOption(H3DOptions_DebugViewMode,1)
' h3dSetOption(H3DOptions_WireframeMode,1)

while inkey()=""
  ' Increase animation time
  t = t + 16 * (1 / FPS)

  ' Do animation blending
  h3dSetModelAnimParams(knight, 0, t, 1) ' order
  h3dSetModelAnimParams(knight, 1, t, 0) ' attack
  h3dUpdateModel(knight,1)
  ' Animate particle systems (several emitters in a group node)
  var cnt = h3dFindNodes(particleSys, "", H3DNodeTypes_Emitter)
  for I as long = 0 to cnt - 1
    h3dUpdateEmitter(h3dGetNodeFindResult(I), 1 / FPS)
  next

  ' Render scene
  h3dRender( cam )
  ' Finish rendering of frame
  h3dFinalizeFrame()
  ' swap buffers
  flip
wend

' free all resources
h3dRelease()
Last edited by D.J.Peters on Oct 12, 2022 17:50, edited 12 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC (Win/Lin 32/64 bit)

Post by D.J.Peters »

Horde3D.bi is complete now and I added the Doc folder.

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

I build a new version of the 3D engine and added a missing Terrain node.

Dynamic libs for Windows x86 and X86_64 are included.

Currently I build the lib for Linux X86 and X86_64 also.

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

I build Horde3D as single lib (no more extra lib HordeUtil)
and added the util and terrain stuff to Horde3D.bi.
I added the Terrain API to the html docu also.
Libs for Windows and Linux included now.
Horde3D-32.dll
Horde3D-64.dll
libHorde3D-32.so
libHorde3D-64.so

Joshy
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by chung »

thanks for horde3D

it works with gui_chung opengl window

but i didnt manage to run alfakilotankgame with my gui_chung nor glfw , only with screenres, (crashes while trying to create the 1rst shader program)?

Code: Select all

#include once "fbgfx.bi"
#include once "Horde3D.bi"
#Include Once "gui_chung.bi"

#Undef Flip
#Define Flip guirefreshopenGL

function InitHorde3D(w as integer=640,h as integer=480) as boolean
  dim as integer bits
  screeninfo ,,bits
  ' create OpenGL context
  'ScreenRes w,h,bits,,fb.GFX_OPENGL
  graphicbox("win.graph",10,10,w,h,"opengl")
  openwindow("win","test opengl",100,50,w+20,h+50)
  guistartOpenGL("win.graph")
  Flip
  ' init Horde3D
  return h3dInit()
end function

' get current screen size
dim as integer w,h
screeninfo w,h
w=640:h=480

If InitHorde3D(w,h)=false then
  screen 0
  print "error: init Horde3D !"
  beep:sleep:end
end if

' Set options
h3dSetOption(H3DOptions_LoadTextures,   1)
h3dSetOption(H3DOptions_TexCompression, 0)
h3dSetOption(H3DOptions_FastAnimation,  0)
h3dSetOption(H3DOptions_MaxAnisotropy,  4)
h3dSetOption(H3DOptions_ShadowMapSize, 512)

' Add resources

' Pipeline
var forwardPipeRes = h3dAddResource(H3DResTypes_Pipeline,"pipelines/forward.pipeline.xml")

' Environment
var envRes = h3dAddResource(H3DResTypes_SceneGraph,"models/sphere/sphere.scene.xml")

' Knight
var knightRes      = h3dAddResource(H3DResTypes_SceneGraph,"models/knight/knight.scene.xml")
var knightAnim1Res = h3dAddResource(H3DResTypes_Animation, "animations/knight_order.anim")
var knightAnim2Res = h3dAddResource(H3DResTypes_Animation, "animations/knight_attack.anim")

' Particle system
var particleSysRes = h3dAddResource(H3DResTypes_SceneGraph, "particles/particleSys1/particleSys1.scene.xml")

' Load resources
var contentDir = exepath() + "/Content"
h3dutLoadResourcesFromDisk(strptr(contentDir))

' Add scene nodes

' Add camera
var cam = h3dAddCameraNode(H3DRootNode, "Camera", forwardPipeRes)

' Setup viewport and render target sizes
h3dSetNodeParamI( cam, H3DCamera_ViewportXI, 0 )
h3dSetNodeParamI( cam, H3DCamera_ViewportYI, 0 )
h3dSetNodeParamI( cam, H3DCamera_ViewportWidthI, w )
h3dSetNodeParamI( cam, H3DCamera_ViewportHeightI, h)

' Set camera parameters (pos, rotation, scale)
h3dSetNodeTransform(cam, 0,5,20, 0,0,0, 1,1,1)

' Set camera parameters (fov,  ratio, near, far)
h3dSetupCameraView( cam, 45.0, w / h, 0.1, 1000.0 )
h3dResizePipelineBuffers( forwardPipeRes, w, h )

' Add environment
var env = h3dAddNodes(H3DRootNode, envRes)
h3dSetNodeTransform(env, 0, -400, 0, 0, 0, 0, 400, 400, 400)

' Add knight
var knight = h3dAddNodes(H3DRootNode, knightRes)
'                           pos,   rotation,  scale
h3dSetNodeTransform(knight, 0,0,0, 0,180,0,  .1,.1,.1)
h3dSetupModelAnimStage(knight, 0, knightAnim1Res, 0, "", False)
h3dSetupModelAnimStage(knight, 1, knightAnim2Res, 0, "", False)

'' Attach particle system to hand joint
h3dFindNodes(knight, "Bip01_R_Hand", H3DNodeTypes_Joint)
var hand = h3dGetNodeFindResult(0)
var particleSys = h3dAddNodes(hand, particleSysRes)
'                                 pos,  rotation, scale
h3dSetNodeTransform(particleSys, 0,40,0,  0,0,0,  1,1,1)

' Add light source
var light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP")
'                          pos,    rotation, scale
h3dSetNodeTransform(light, 5,15,5, -60,0,0, 1,1,1)
h3dSetNodeParamF(light, H3DLight_RadiusF, 0, 30)
h3dSetNodeParamF(light, H3DLight_FovF, 0, 90)
h3dSetNodeParamI(light, H3DLight_ShadowMapCountI, 1)
h3dSetNodeParamF(light, H3DLight_ShadowMapBiasF, 0, 0.01)
h3dSetNodeParamF(light, H3DLight_ColorF3, 0, 1.0) ' red
h3dSetNodeParamF(light, H3DLight_ColorF3, 1, 0.8) ' green
h3dSetNodeParamF(light, H3DLight_ColorF3, 2, 0.7) ' blue


const as single FPS = 60
dim as single t

h3dutDumpMessages()

' h3dSetOption(H3DOptions_DebugViewMode,1)
' h3dSetOption(H3DOptions_WireframeMode,1)

while inkey()="" And guitestkey(vk_escape)=0
  guiscan	
  ' Increase animation time
  t = t + 16 * (1 / FPS)

  ' Do animation blending
  h3dSetModelAnimParams(knight, 0, t, 1) ' order
  h3dSetModelAnimParams(knight, 1, t, 0) ' attack
  h3dUpdateModel(knight,1)
  ' Animate particle systems (several emitters in a group node)
  var cnt = h3dFindNodes(particleSys, "", H3DNodeTypes_Emitter)
  for I as long = 0 to cnt - 1
    h3dUpdateEmitter(h3dGetNodeFindResult(I), 1 / FPS)
  next

  ' Render scene
  h3dRender( cam )
  ' Finish rendering of frame
  h3dFinalizeFrame()
  ' swap buffers
  Flip
wend

' free all resources
h3dRelease()
guicloseOpenGL()
guiclose
guinotice("bye")
guiquit
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

chung wrote: ... only with screenres ...
If it works with the OpenGL context from Screenres hat means something is wrong with your windows only stuff.

May be you create a none shareable OpenGL rendercontext inside of your DLL ?

If you create it with Screenres the OpenGL render context are shareable with oher libraries.

I tested Horde3D on Windows and Linux without any problems.

Joshy
Last edited by D.J.Peters on Dec 02, 2015 1:43, edited 2 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

Chung do you tryed h3dutInitOpenGL(hDC) normaly you don't need it ?

Horde3D works with with any created OpenGL compatible* redercontext: FBGFX, FLTK, GTK+, SDL, QT 4/5, GLUT, FreeGLUT ...
(*) It used shaders so it must be OpenGL version >= 2.x, 3.x, 4.x

Joshy

Code: Select all

#ifdef __FB_WIN32__
' --- OpenGL-related functions ---
' Initializes OpenGL.
' This utility function initializes an OpenGL rendering context in a specified window component.
' Currently this function is only available on Windows platforms.
' Parameters: hDC handle to device context for which OpenGL context shall be created
' Returns:    true in case of success, otherwise false
declare function h3dutInitOpenGL(byval hDC as any ptr) as Boolean

' Releases OpenGL.
' This utility function destroys the previously created OpenGL rendering context.
' Currently this function is only available on Windows platforms.
declare sub      h3dutReleaseOpenGL()

' Displays the rendered image on the screen.
' This utility function displays the image rendered to the previously initialized OpenGL context 
' on the screen by copying it from the backbuffer to the frontbuffer.
' Currently this function is only available on Windows platforms.
declare sub      h3dutSwapBuffers()
#endif
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

Added links to Horde3D maual, wiki and forum see first post.

Joshy
chung
Posts: 648
Joined: Jan 16, 2010 20:52
Location: France
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by chung »

no, it does work well without changes with horde3D

it is alfakilotankgame.bas that doesnt work , i tryied alfakilotankgame with glfw too , it crashes idem
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

New version available.

added:
creategeometry.bas
geoformat.bas

Joshy
Image

Code: Select all

#include once "fbgfx.bi"
#include once "Horde3D.bi"

#ifndef NULL
  #define NULL cptr(any ptr,0)
#endif

type vec3f
  as single x,y,z
end type

type vec3s
  as short x,y,z
end type

type vec2f
  as single x,y
end type

function CreateCubeGeometry(byval resName as zstring ptr,byval scale as single=1) as TH3DRes
  dim as long nVertices  = 24
  dim as long nTriangles = 12
  dim as long nTriangleIndices = nTriangles * 3
  dim as vec3f PosData(...) => { _
  (-0.5*scale, 0.5*scale, 0.5*scale), _ ' front
  (-0.5*scale,-0.5*scale, 0.5*scale), _
  ( 0.5*scale,-0.5*scale, 0.5*scale), _
  ( 0.5*scale, 0.5*scale, 0.5*scale), _
  _
  ( 0.5*scale, 0.5*scale, 0.5*scale), _ ' right
  ( 0.5*scale,-0.5*scale, 0.5*scale), _
  ( 0.5*scale,-0.5*scale,-0.5*scale), _
  ( 0.5*scale, 0.5*scale,-0.5*scale), _ 
  _
  ( 0.5*scale, 0.5*scale,-0.5*scale), _ ' back
  ( 0.5*scale,-0.5*scale,-0.5*scale), _
  (-0.5*scale,-0.5*scale,-0.5*scale), _
  (-0.5*scale, 0.5*scale,-0.5*scale), _
  _
  (-0.5*scale, 0.5*scale,-0.5*scale), _ ' left
  (-0.5*scale,-0.5*scale,-0.5*scale), _
  (-0.5*scale,-0.5*scale, 0.5*scale), _
  (-0.5*scale, 0.5*scale, 0.5*scale), _
  _
  (-0.5*scale, 0.5*scale,-0.5*scale), _ ' top
  (-0.5*scale, 0.5*scale, 0.5*scale), _
  ( 0.5*scale, 0.5*scale, 0.5*scale), _
  ( 0.5*scale, 0.5*scale,-0.5*scale), _
  _
  (-0.5*scale,-0.5*scale, 0.5*scale), _ ' bottom
  (-0.5*scale,-0.5*scale,-0.5*scale), _
  ( 0.5*scale,-0.5*scale,-0.5*scale), _
  ( 0.5*scale,-0.5*scale, 0.5*scale)} 

  dim as ulong indexData(...) => { _
   0, 1, 2,  2, 3, 0, _ ' front
   4, 5, 6,  6, 7, 4, _ ' right
   8, 9,10, 10,11, 8, _ ' back
  12,13,14, 14,15,12, _ ' left
  16,17,18, 18,19,16, _ ' top
  20,21,22, 22,23,20}   ' bottom

  dim as vec3s normalData(...) => { _
  (0,0, 32767), (0,0, 32767), (0,0, 32767), (0,0, 32767), _ ' front
  ( 32767,0,0), ( 32767,0,0), ( 32767,0,0), ( 32767,0,0), _ ' right
  (0,0,-32767), (0,0,-32767), (0,0,-32767), (0,0,-32767), _ ' back
  (-32767,0,0), (-32767,0,0), (-32767,0,0), (-32767,0,0), _ ' left
  (0, 32767,0), (0, 32767,0), (0, 32767,0), (0, 32767,0), _ ' top
  (0,-32767,0), (0,-32767,0), (0,-32767,0), (0,-32767,0)}   ' bottom

  dim as vec2f text0Data(...) => { _
  (0,1),(0,0),(1,0),(1,1), _ ' front
  (0,1),(0,0),(1,0),(1,1), _ ' right
  (0,1),(0,0),(1,0),(1,1), _ ' back
  (0,1),(0,0),(1,0),(1,1), _ ' left
  (0,1),(0,0),(1,0),(1,1), _ ' top
  (0,1),(0,0),(1,0),(1,1) }  ' bottom

  return h3dutCreateGeometryRes(resName         , _ ' resource name
                                nVertices       , _ ' num of vertices
                                nTriangleIndices, _ ' num of triangle indicies
                                @PosData(0).x   , _ ' vertex position (single ptr)
                                @indexData(0)   , _ ' indicies (ulong ptr)
                                @normalData(0).x, _ ' vertex normale   -32767 to +32767 (short ptr) 
                                NULL            , _ ' vertex tangent   -32767 to +32767 (short ptr)
                                NULL            , _ ' vertex bitangent -32767 to +32767 (short ptr)
                                @text0Data(0).x , _ ' vertex texture coords set 0 (single ptr) 
                                NULL)               ' vertex texture coords set 1 (single ptr) 
end function

function InitHorde3D(w as integer=640,h as integer=480) as boolean
  dim as integer bits
  screeninfo ,,bits
  ' create OpenGL context
  screenres w,h,bits,,fb.GFX_OPENGL
  flip
  ' init Horde3D
  return h3dInit()
end function

' get current screen size
dim as integer w,h
screeninfo w,h
w*=0.75
h*=0.75

w=640
h=480

if InitHorde3D(w,h)=false then
  screen 0
  print "error: init Horde3D !"
  beep:sleep:end
end if


' Set options
'h3dSetOption(H3DOptions_LoadTextures,   1)
'h3dSetOption(H3DOptions_TexCompression, 0)
'h3dSetOption(H3DOptions_FastAnimation,  0)
'h3dSetOption(H3DOptions_MaxAnisotropy,  16)
h3dSetOption(H3DOptions_ShadowMapSize, 2048)

' Add resources
var renderPipeline  = h3dAddResource(H3DResTypes_Pipeline  ,"pipelines/forward.pipeline.xml")
var platformScene   = h3dAddResource(H3DResTypes_SceneGraph,"models/platform/platform.scene.xml")
var cubeMaterial    = h3dAddResource(H3DResTypes_Material  ,"models/cube/cube.material.xml")

' Load resources
var contentDir = exepath() + "/Content"
h3dutLoadResourcesFromDisk(strptr(contentDir))

' optional dump log messages
' h3dutDumpMessages() ' usefull if loading of any resources are fails

var platformNode = h3dAddNodes(H3DRootNode, platformScene)
h3dSetNodeTransform(platformNode, 0,0,0, 0,0,0, 1,1,1)


const MAX_CUBES = 110
dim as TH3DNode cubes(MAX_CUBES-1)
for i as integer =0 to MAX_CUBES-1
  dim as string ID = "cubeGeometry" & i
  var cubeGeometry = CreateCubeGeometry(strptr(id),0.5)
  ID = "cubeModel" & i
  cubes(i) = h3dAddModelNode(H3DRootNode,strptr(id),cubeGeometry)
  ID = "cubeMesh" & i
  h3dAddMeshNode(cubes(i),strptr(id),cubeMaterial,0,36,0,3)
next

var cam = h3dAddCameraNode(H3DRootNode, "Camera", RenderPipeline)
' Setup viewport and render target sizes
h3dSetNodeParamI(cam, H3DCamera_ViewportXI     , 0)
h3dSetNodeParamI(cam, H3DCamera_ViewportYI     , 0)
h3dSetNodeParamI(cam, H3DCamera_ViewportWidthI , w)
h3dSetNodeParamI(cam, H3DCamera_ViewportHeightI, h)
h3dSetNodeTransform(cam, 0,5,10, -30,0,0, 1,1,1)
' Set camera parameters (fov,  ratio, near, far)
h3dSetupCameraView( cam, 45.0, w / h, 0.1, 1000.0 )
h3dResizePipelineBuffers( RenderPipeline, w, h )



' Add light source
var light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP")
'                        position,  rotation, scale
h3dSetNodeTransform(light, 0,15,0, 90*3,0,0, 1,1,1)
h3dSetNodeParamF(light, H3DLight_RadiusF, 0, 30)
h3dSetNodeParamF(light, H3DLight_FovF   , 0, 60)
h3dSetNodeParamI(light, H3DLight_ShadowMapCountI, 1)
h3dSetNodeParamF(light, H3DLight_ShadowMapBiasF, 0, 0.01)
h3dSetNodeParamF(light, H3DLight_ColorF3, 0, 0.8) ' red
h3dSetNodeParamF(light, H3DLight_ColorF3, 1, 0.8) ' green
h3dSetNodeParamF(light, H3DLight_ColorF3, 2, 0.0) ' blue

' h3dSetOption(H3DOptions_DebugViewMode,1)
' h3dSetOption(H3DOptions_WireframeMode,1)

' set cube position
for i as integer =0 to MAX_CUBES-1
  var z =  5 - (i \ 11)
  var x = -5 + (i mod 11)
  h3dSetNodeTransform(cubes(i),x*.9,.5,z*.9, 0,0,0, 1,1,1)
next

dim as integer frames,xRot,yRot,zRot
while inkey()=""
  ' rotate the cube
  for i as integer =0 to MAX_CUBES-1
    var z =  5 - (i \ 11)
    var x = -5 + (i mod 11)
    var d = sqr(x*x+z*z)
    if d < 5 then
      h3dSetNodeTransform(cubes(i),x*.9,2-d*.3,z*.9, xRot+d*10,yRot+d*20,zRot+d*30, 1,1,1)
    end if
  next
  ' Render scene
  h3dRender( cam )
  ' Finish rendering of frame
  h3dFinalizeFrame()
  ' swap buffers
  flip
  h3dutDumpMessages()
  frames+=1
  xRot=(xRot+1) mod 360
  if frames mod 2=0 then yRot=(yRot+1) mod 360
  if frames mod 3=0 then zRot=(zRot+1) mod 360
wend

' free all resources
h3dRelease()
Last edited by D.J.Peters on Oct 12, 2022 17:50, edited 2 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

First test of Stats, Overlays and Text.

Joshy
click to enlarge:
Image]
file: overlay.bas

Code: Select all

#include once "fbgfx.bi"
#include once "Horde3D.bi"

function InitHorde3D() as boolean
  dim as integer w,h,bits
  screeninfo w,h,bits
  w*=.75
  h*=.75
  ' create OpenGL context
  screenres w,h,bits,,fb.GFX_OPENGL
  flip
  ' init Horde3D
  return h3dInit()
end function

if InitHorde3D()=false then
  screen 0
  print "error: init Horde3D !"
  beep:sleep:end
end if

' get current screen size
dim as integer w,h
screeninfo w,h



' Add resources

' Pipeline
var forwardPipeRes = h3dAddResource(H3DResTypes_Pipeline,"pipelines/forward.pipeline.xml")
var fontMatRes  = h3dAddResource( H3DResTypes_Material, "overlays/font.material.xml")
var panelMatRes = h3dAddResource( H3DResTypes_Material, "overlays/panel.material.xml")
var logoMatRes  = h3dAddResource( H3DResTypes_Material, "overlays/logo.material.xml")

' Load resources
var contentDir = exepath() + "/Content"
h3dutLoadResourcesFromDisk(strptr(contentDir))

' Add scene nodes

' Add camera
var cam = h3dAddCameraNode(H3DRootNode, "Camera", forwardPipeRes)

' Setup viewport and render target sizes
h3dSetNodeParamI( cam, H3DCamera_ViewportWidthI, w )
h3dSetNodeParamI( cam, H3DCamera_ViewportHeightI, h)

' Set camera parameters (pos, rotation, scale)
h3dSetNodeTransform(cam, 0,5,20, 0,0,0, 1,1,1)

' Set camera parameters (fov,  ratio, near, far)
h3dSetupCameraView( cam, 45.0, w / h, 0.1, 1000.0 )
h3dResizePipelineBuffers( forwardPipeRes, w, h )


dim as single coords(...)=>{0.75, 0.8, 0, 1,  _
                            0.75, 1,   0, 0,  _
                            1   , 1,   1, 0,  _
                            1   , 0.8, 1, 1}

while inkey()=""
  h3dutShowFrameStats(fontMatRes,panelMatRes,2)
  h3dShowOverlays(@coords(0), 4, 1,1,1,1, logoMatRes, 0)
  h3dutShowText( "text", 0, .9, 0.1, 1, 1, 1, fontMatRes)
  h3dRender( cam )
  h3dFinalizeFrame()
  h3dClearOverlays()
  ' swap buffers
  flip
wend

' free all resources
h3dRelease()
Last edited by D.J.Peters on Oct 12, 2022 17:50, edited 2 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC

Post by D.J.Peters »

I know no one here used this modern graphic engine however I added some C++ code:
h3dutLookAt() h3dutSetDumpFile() h3dutSetDumpTitle() and a fresh build of my version of Tokamak physics lib.

Joshy
Image

file: physictest01.bas

Code: Select all

#include once "fbgfx.bi"
#include once "horde3d.bi"
#include once "tokamak-c.bi"

type AnimatedBody as neAnimatedBody ptr
type RigidBody    as neRigidBody ptr

' a static massless body with collision geometry
function CreateAnimatedBodyBox(byval sim     as neSimulator ptr, _
                               byval fWidth  as single=1, _
                               byval fHeight as single=1, _
                               byval fDepth  as single=1) as neAnimatedBody ptr
  var ab  = SimulatorCreateAnimatedBody(sim)
  var geo = AnimatedBodyAddGeometry(ab)
  if fWidth <0.01 then fWidth =0.01
  if fHeight<0.01 then fHeight=0.01
  if fDepth <0.01 then fDepth =0.01 
  GeometrySetBoxSize(geo, fWidth,fHeight,fDepth)
  AnimatedBodyUpdateBoundingInfo(ab)
  return ab
end function

' a dynamic body with mass and collision geometry
function CreateRigidBodyBox(byval sim     as neSimulator ptr, _
                            byval fWidth  as single=1, _
                            byval fHeight as single=1, _
                            byval fDepth  as single=1, _
                            byval fMass   as single=1) as neRigidBody ptr
  var rb  = SimulatorCreateRigidBody(sim)
  var geo = RigidBodyAddGeometry(rb)
  if fWidth <0.01 then fWidth =0.01
  if fHeight<0.01 then fHeight=0.01
  if fDepth <0.01 then fDepth =0.01
  if fMass  <1    then fMass  =1
  GeometrySetBoxSize(geo, fWidth,fHeight,fDepth)
  RigidBodySetInertiaTensor(rb,neBoxInertiaTensor(fWidth,fHeight,fDepth,fMass))
  RigidBodySetMass(rb,fMass)
  RigidBodyUpdateBoundingInfo(rb)
  return rb
end function


function InitHorde3D(byval w as integer=640,byval h as integer=480) as boolean
  dim as integer bits
  screeninfo ,,bits
  ' create window with OpenGL context
  screenres w,h,bits,,fb.GFX_OPENGL
  if screenptr()=0 then
    screen 0
    print "error: init OpenGL context !"
    beep : sleep : end 1
  end if
  flip
  ' init Horde3D
  var ret = h3dInit()
  if ret=false then h3dutDumpMessages()
  return ret
end function

dim as integer iWidth=640,iHeight=480
'screeninfo iWidth,iHeight
'iWidth*=0.75 : iHeight*=0.75
if InitHorde3D(iWidth, iHeight)=false then
  screen 0
  print "error: h3dInit() !"
  beep : sleep : end 1
end if

var sim = CreateSimulator()
if sim=NULL then
  h3dRelease()
  screen 0
  print "error: CreateSimulator() !"
  beep : sleep : end 1
end if

' optinal set dump filename and title
dim as string dumpFile  = command(0) & ".html"
dim as string dumpTitle = "tokamak 1.0.5 game physics test with: " & *h3dGetVersionString
h3dutSetDumpFile (strptr(dumpFile))
h3dutSetDumpTitle(strptr(dumpTitle))

h3dutDumpMessages()

' Add resources
var renderPipeline = h3dAddPipeline  ("pipelines/forward.pipeline.xml")
var skyBoxScene    = h3dAddSceneGraph("models/skybox/skybox.scene.xml")
var platformScene  = h3dAddSceneGraph("models/platform/platform.scene.xml")
var cubeScene      = h3dAddSceneGraph("models/cube/cube.scene.xml")

' Load resources from content folder
var contentDir = exepath() + "/Content"
h3dutLoadResourcesFromDisk(strptr(contentDir))

' optional dump log messages
h3dutDumpMessages() ' usefull if loading of any resources are fails

var skyboxNode = h3dAddNodes(H3DRootNode, skyboxScene)
h3dSetNodeTransform(skyboxNode, 0,0,0, 0,0,0, 200,200,200)
h3dSetNodeFlags    (skyboxNode, H3DNodeFlags_NoCastShadow, true )

var platformNode = h3dAddNodes(H3DRootNode, platformScene)
var platformBody = CreateAnimatedBodyBox(sim,150,2,150)
AnimatedBodySetPosition(platformBody,0,-1,0)

const MAX_CUBES = DEFAULT_RIGIDBODIES_COUNT
const SQR_CUBES = sqr(MAX_CUBES)
dim as TH3DNode  cubeNode(MAX_CUBES-1)
dim as RigidBody cubeBody(MAX_CUBES-1)


for i as integer = 0 to MAX_CUBES-1
  cubeNode(i) = h3dAddNodes(H3DRootNode, cubeScene)
  cubeBody(i) = CreateRigidBodyBox(sim)
  var col = i  \  SQR_CUBES
  var row = i mod SQR_CUBES
  RigidBodySetPosition(cubeBody(i),-SQR_CUBES\2 + col*1.2 + (i and 1)*0.5,.5+row,0)
next

var cam = h3dAddCameraNode(H3DRootNode, "Camera", RenderPipeline)
h3dSetNodeTransform(cam, 0,5,30, -10,0,0, 1,1,1)

' Setup position and size of the viewport
h3dSetNodeParamI(cam, H3DCamera_ViewportXI     , 0)
h3dSetNodeParamI(cam, H3DCamera_ViewportYI     , 0)
h3dSetNodeParamI(cam, H3DCamera_ViewportWidthI , iWidth)
h3dSetNodeParamI(cam, H3DCamera_ViewportHeightI, iHeight)
h3dSetNodeParamI(cam, H3DCamera_OccCullingI,1)

' Set camera parameters (field of view, asspect ratio, near plane, far plane)
h3dSetupCameraView( cam, 60.0, iWidth / iHeight, 0.1, 1000.0 )

' Setup size of the render target
h3dResizePipelineBuffers(RenderPipeline, iWidth, iHeight)

' Add a light
var light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP")
h3dSetNodeTransform(light, 5,25,15, -90,0,0, 1,1,1)
h3dSetNodeParamF(light, H3DLight_RadiusF        , 0, 50)
h3dSetNodeParamF(light, H3DLight_FovF           , 0, 90)
h3dSetNodeParamI(light, H3DLight_ShadowMapCountI, 1)
h3dSetNodeParamF(light, H3DLight_ShadowMapBiasF ,0, 0.01)
h3dSetNodeParamF(light, H3DLight_ColorF3,        0, 0.8) ' red
h3dSetNodeParamF(light, H3DLight_ColorF3,        1, 0.4) ' green
h3dSetNodeParamF(light, H3DLight_ColorF3,        2, 0.2) ' blue

h3dutDumpMessages()

' shows the bounding boxes
'h3dSetOption(H3DOptions_DebugViewMode,1)

' usefull if something are wrong with trriangles
'h3dSetOption(H3DOptions_WireframeMode,1)


dim as single xPos,yPos,zPos
dim as single xRot,yRot,zRot
dim as single matrix(15)
dim as single ptr transform = @matrix(0)

const CAM_TARGET = 10

while inkey()=""
  SimulatorAdvance(sim)
  RigidBodyGetOpenGLMatrix(cubeBody(CAM_TARGET),transform)
  h3dutLookAt(cam,0,5,30, transform[12], transform[13], transform[14], 0,1,0)
  for i as integer = 0 to MAX_CUBES-1
    RigidBodyGetOpenGLMatrix(cubeBody(i),transform)
    h3dSetNodeTransMat      (cubeNode(i),transform)
  next

  ' Render scene
  h3dRender( cam )
  ' Finish rendering of frame
  h3dFinalizeFrame()
  ' swap buffers
  flip
wend

' free all resources
h3dRelease()
DestroySimulator(sim)
Last edited by D.J.Peters on Oct 12, 2022 17:51, edited 2 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: 3D engine Horde3D for FreeBASIC Jan 16, 2017

Post by D.J.Peters »

Because of malware on alice-dsl.net domain I moved all content to my new shiny3d.de server.

Joshy
kryton9
Posts: 3
Joined: Nov 05, 2019 13:22

Re: 3D engine Horde3D for FreeBASIC Jan 16, 2017

Post by kryton9 »

I just downloaded your zip file and everything worked just fine. Thanks for all the work!
I feel like a kid in a candy store with libOpenB3D and now Horde3D.

As a note, hope this helps anyone else in the future.
I am running in Linux Mint 64 bit. I found out that when you place .so files in
/usr/local/lib
and you still get errors of it not finding the .so file when you run the program
you have to run this command in the terminal first: sudo ldconfig

ldconfig creates the necessary links and cache to the most recent shared libraries
Post Reply