Skip to content

ffunatsu/TrussC.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

126 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TrussC.jl

TrussC Julia binding.


C++ bindings are generated by tcxZZJuliaCxxWrap using CxxWrap.jl (and it's precompiled in TrussC_prebuilt_jll)

(Binding base code are mainly ported from tcxLua)

Note

This repository is not registered in public package manager, so you need pkg> add https://github.com/xxx/yyy.git (see How to add this library into your project in detail)

Binding coverage

see tcxZZJuliaCxxWrap#binding-coverage

(and also see test cases.)

Sample code

screenshot

module TrussCExample

using TrussC

# tc = TrussC

function setup()
  setFps(60.0f0)
end

function draw()
  clear(0.12f0, 1.0f0)

  # Rotating box
  pushMatrix();
  noFill();
  translate(getWindowWidth() / 2.0f0, getWindowHeight() / 2.0f0);
  rotate(Float32(getElapsedTimef() * 0.1f0), Float32(getElapsedTimef() * 0.15f0), 0.0f0);
  drawBox(200.0f0);
  popMatrix();
end

function keyPressed(key::Cint)
  c = Char(key)
  println("key: ", c, " (", key ,")")
end

function main()
  @setup(setup)
  @draw(draw)
  @keyPressed(keyPressed)

  runTrusscApp()
end

end # module TrussCExample

see TrussCExample.jl for detail.

Syntax cheat sheet

Julia's procedural style is much different than C++ OOP style. Please check test folder how to use types or functions in detail.

Julia (CxxWrap) C++
x(vec) vec.x
r(red) red.r
x!(vec, new_value) vec.x = new_value
getWidth(fbo) fbo.getWidth()
Color_red() Color.red
Quaternion_identity() Quaternion.identity()
begin_fbo(fbo) fbo.begin()
end_fbo(fbo) fbo.end()

(If you need method chaining, you can use |> operator or Chain.jl and Lazy.jl as you like.)

Shadowing

When you shadowed x, y by your variables, you can use TrussC.x() instead.

using TrussC
tc = TrussC
x = Vec2(1.0f0, 2.0f0) # This shadows TrussC.x
tc.x(x) # 1.0f0

For other common example: tc.draw(image), tc.update(a), tc.string(e) etc...

How to add this library into your project

In your project, run julia --project=@. and:

  • pkg> add https://github.com/funatsufumiya/TrussC_prebuilt_jll.git
  • pkg> add https://github.com/funatsufumiya/TrussC.jl.git

(NOTE: pkg> REPL can be shown by typing ] key on julia REPL, and type Backspace key to back to normal REPL.)

Warning

Windows CxxWrap.jl issue

If not working CxxWrap.jl on Windows, you need to try Building libcxxwrap-julia (Because prebuilt packaged dll for CxxWrap.jl is not compatible with MSVC).
Please see Windows libcxxwrap_julia_jll build of https://github.com/funatsufumiya/CxxWrapTest.jl or https://github.com/JuliaInterop/libcxxwrap-julia in detail.

If it's too hard for you to manually build libcxxwrap_julia_jll/override, You can use my prebuilt override.zip (built for libcxxwrap_julia_jll 0.14.9+0, version at 2026/05/15.)

(or, just use WSL. It's much easier.)

Addons

Not full addons supported, but some addons are supported in other libraries.

  • tcxOsc
  • tcxHap

Warning

They are already included in TrussC.jl, and separated DLLs now makes rendering problem (Issue #3, Issue tcxHap.jl#1)

This would be hard problem to use other addons. We need more investigation and need to find the way to use other DLLs, without recompiling TrussC_precompiled_jll (libJlTrussC) itself.

Known Issues

  • Default values are not treated perfectly now. You may need clear(1.0f0, 1.0f0) instaed of clear(1.0f0).
  • Stataic methods (and some static constants) of types are renamed using _ (underscore).
    • For example Quaternion.identity() was replaced to Quaternion_identity()
    • For example Color.white was replaced to Color_white() (NOTE color constants are wrapped as function! not constant!)
  • begin, end is renamed.
    • For example Fbo#begin(), Fbo#end() were replaced to begin_fbo, end_fbo
  • functions such as x, y, r (they are needed to access such as Vec3#x, Color#r) can be easily replaced by user variables.
    • In this case, use TrussC.x(vec) or tc = TrussC; tc.x(vec) instaed of x(vec).
  • You may need nothing at the end of setup or draw, in order to indicate void function (for limitation of @cfunction bridge.)

Dependencies

Unit tests

$ julia --project=@. -e 'using Pkg; Pkg.test()'

Build notes

see docs/build_notes.md

About

TrussC Julia binding

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages