Skip to main content

Python wrapper for BGFX Library

Project description


BGFX Python

Python 3.6+ wrapper for the BGFX library.



Key FeaturesHow To UseBuild CPP bindingsUsing ImGUIExamplesLoggingCreditsLicense

Key Features

  • Uses Pyind11 and Builder to natively wrap the C++ interface. No CTypes or ugly C interfaces.
  • Functions, classes and methods respect the PEP 8 notation.
  • Unless specified, the GIL is released for every invocation and pointers are passed by reference. This will ensure great overall performances.
  • Maintains the original documentation; use help() on a class or function to view it.
  • Compiles shaders on-the-fly, so you don't have to.
  • Ships with ImGui integrated in the BGFX rendering pipeline.

How To Use

Precompiled wheels

Precompiled wheels are available for Windows, Linux and MacOS. To install the latest published release, simply run:

$ pip install bgfx-python

Install from source

To install the latest version, you'll need to clone this repository and its submodules:

$ git clone --depth=1 https://github.com/fbertola/bgfx-python
$ git submodule update --init --recursive

Then, make sure to have make, cmake and ninja installed in your system.

Finally, simply build and install the wheel.

$ pip setup.py install

Installing on MacOS

Building on MacOS X > 10.14 requires you to also install the SDK headers:

xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Installing on Windows

The easiest way is to install Visual Studio 2019 Community Edition. If you have Chocolatey installed, then run:

choco install visualstudio2019community

Before building the package, make sure to activate all the environment variables required by the compiler:

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64

Build CPP bindings

bgfx-python uses Binder and Pybind11 to wrap the original library. A script to generate such binding is provided inside the scripts directory. Make sure that all the paths are corrects then simply launch the various scripts, e.g:

$ python make_bindings_bgfx.py

Building on MacOS X could be a little trickier, since system headers are in the SDK location. Make sure to also include these paths; you can check where the headers are located running this command:

g++ -E -x c++ - -v < /dev/null

Using ImGUI

Two modules are exposed:

  • ImGui, which provides a standard wrapper around all the ImGui funcions and classes.
  • ImGuiExtra, which provides some additional functions to integrate ImGui in the BGFX rendering pipline.

To use it in your application, simply follow this template:

# Setup the application
def init():
    ImGuiExtra.imgui_create()

# Destroy the application
def destroy():
    ImGuiExtra.imgui_destroy()

# Update the application, rendering each fram
def update():
    ImGuiExtra.imgui_begin_frame(
        mouse_x, mouse_y, buttons_states, 0, width, height
    )

    # Other ImGui drawing directives...

    ImGuiExtra.imgui_end_frame()

All ImGui API that provides user input (such as InputText, SliderFloat, etc.) modifies their arguments by reference. However, in Python, such objects as integers, floats and strings are passed always by value. Because of this, bgfx-python provides special wrappers, that allow passing those variables by reference.

For example, to use SliderFloat, you will need first to create a variable that will hold the state:

f = ImGui.Float();

You can access the value in the following way: f.value

To use it with slider_float simply pass it to that function:

ImGui.slider_float("float slider", f, 0.0, 1.0)

Logging

Loguru is used for logging inside bgfx_python. By default the logger is disabled; to enable it, use the following instructions:

from loguru import logger

logger.enable("bgfx")

Examples

You will find some examples in the examples folder, be sure to check them out. For a more advanced example, see the Natrix project.

Credits

This software uses the following open source packages:

License (BSD 2-clause)

BSD 2-Clause License

Copyright (c) 2020, Federico Bertola
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

GitHub @fbertola

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bgfx-python-1.0.2.tar.gz (87.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bgfx_python-1.0.2-cp38-cp38-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.8Windows x86-64

bgfx_python-1.0.2-cp38-cp38-manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.8

bgfx_python-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

bgfx_python-1.0.2-cp37-cp37m-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.7mWindows x86-64

bgfx_python-1.0.2-cp37-cp37m-manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.7m

bgfx_python-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

bgfx_python-1.0.2-cp36-cp36m-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.6mWindows x86-64

bgfx_python-1.0.2-cp36-cp36m-manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.6m

bgfx_python-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

Details for the file bgfx-python-1.0.2.tar.gz.

File metadata

  • Download URL: bgfx-python-1.0.2.tar.gz
  • Upload date:
  • Size: 87.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx-python-1.0.2.tar.gz
Algorithm Hash digest
SHA256 83974071b25b932b34a48ef0dec7c8c99eab898db4b575ddafb9d053d5654e8c
MD5 6753b3aa2b400c823e86df6380a42a4f
BLAKE2b-256 a7af37f1dc4b8af22f5e6118c8bf9adb859c79bd72b5af7651dfeb59ed2599f5

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 79467d9ae7c5afa4a66c9289c764792f0a85fe9dfa0dd211242c81dcb7ca07d2
MD5 f65cecf0d0d77d68277231f93d088852
BLAKE2b-256 823aac0279d590d775557e2f8ad0a1e80cf3629f7b430dec15f6c597cdfefd77

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8bfc8746dff76ac5ee5510cb2d1b9017543a2c247fc88ecbc60b6e5fa178e9a2
MD5 406754f78309dfadd6812d95be3b0770
BLAKE2b-256 505b2df807bb1c85198aa1054c7ebcc2ce4c747683fe071f222de5da6d1252e6

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1ee4e0a0f7902bf898097b39579d0945380a5d82e6349b409e78a06974049092
MD5 128a1b673a1674fce39d8fd898a460f1
BLAKE2b-256 9ea6b3fe4e4fc6cd268ef2d769de94a3c03384b4b6f2bbf25c5822f13802635b

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 fe89ce58a8b391af7fd542413f5df9be3a8fb9c67b87c3be0cd1f02d4b56f377
MD5 a1e94eb19b01b7162fd0808a01bed9b0
BLAKE2b-256 e47789d7004abf21465f9969374a8753316609c25c5bf5a61ae7573ca572a3cb

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0a77f19c1fafe7edfb8c3763236e358414ab9688844724686289307dd5d0795
MD5 ee017266947fa2f6c33a39995aac7370
BLAKE2b-256 56f569fec6790d0ac791ff5afb8b3de16f811012e995cf6596bb134f6414bd58

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8cf08158d3ad862496772f4d4f05c94e624361790985052e17a8e97afb65c9ad
MD5 de105e53d1e93d894d01a072acbbd5d5
BLAKE2b-256 d0bd7bf2e77c6e3e50e78a7f7ffe76957cacf74fdbc405f9c516e57f9903ddc3

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 b2ef17b30d149307d6a913993d545717af329ea792d61f204c2382d8dc2210e1
MD5 a9544d0f0e4aac5aa08aba73258272ef
BLAKE2b-256 2b01cb0d0321d9e44268d88bddf9bed043048ec8bfc9a22e4c1dab6cf1f80ed6

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a684b9bc886c2169d9adbb454726f87ef67ab8c05e9d051c86f7f44ccc42f165
MD5 5699f41772a5c704b6ef3fe1b5af84b6
BLAKE2b-256 64f34b5371b629a6a3c70e8a502ce1273025c3c165c5a72958136651a1ff9599

See more details on using hashes here.

File details

Details for the file bgfx_python-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: bgfx_python-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.8

File hashes

Hashes for bgfx_python-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 62e461bad8be605a1ef2790107504f13530161de28c1e0a7c139f3738e59598b
MD5 05e91950a7492e48a7dcbcd85ce25ee4
BLAKE2b-256 56c82598fc4565f57b575ad049467c95d878a751df70c8cd80fe42333e763db8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page