Python wrapper for BGFX Library
Project description
BGFX Python
Python 3.6+ wrapper for the BGFX library.
Key Features • How To Use • Build CPP bindings • Using ImGUI • Examples • Logging • Credits • License
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bgfx-python-1.0.4.tar.gz.
File metadata
- Download URL: bgfx-python-1.0.4.tar.gz
- Upload date:
- Size: 93.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0033d9b475692084bc70e95aecd8ed63bad552a5167c830b8574d04c9a0785b9
|
|
| MD5 |
252b7457c8e31e493fb738ed72a3bfbf
|
|
| BLAKE2b-256 |
db9853fb87d454004e03ab9e2d3d40f590bd6914afad4a471f588466ea57e303
|
File details
Details for the file bgfx_python-1.0.4-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 3.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a641c38a70a69077ba68b8e74fecb0fac33f9f20e5708a50d44757761d29d8e
|
|
| MD5 |
a8de70c646c003f4a9d4f6f5aa4f5f08
|
|
| BLAKE2b-256 |
34b83b1782e32ffbfabd339627e4b76a52a7d56bcbe845e637ca9bd5e8a3b341
|
File details
Details for the file bgfx_python-1.0.4-cp38-cp38-manylinux2014_x86_64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 5.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
810961dcc73b5321fcc8b9217f5a62e55826f6d3bebe3d6f8390b53964c45cfc
|
|
| MD5 |
c9b5f50c4cb1c8c730d1c38cf5fd5a4f
|
|
| BLAKE2b-256 |
68115d77d8d847bf36284118a2511890136dbfc2a98d5d2e127d2df0de82992c
|
File details
Details for the file bgfx_python-1.0.4-cp38-cp38-macosx_10_9_x86_64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b521f0505c510939b238285a4e6a16b25dfd4f2c326fca2a17531140b08ba053
|
|
| MD5 |
400b1ac906fd8b83afbdcc2f2bc23904
|
|
| BLAKE2b-256 |
91cb800aa9b14624a565fb78babed728f741b209ea475f7a4c86c98f9f28a1c2
|
File details
Details for the file bgfx_python-1.0.4-cp37-cp37m-win_amd64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 3.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
390f03d4789577ba8f4ea856d74084008a272af86f08d1e2c8e127036ae4b88a
|
|
| MD5 |
31c3a6ec5ba8cf3a86836f3261a7ee5d
|
|
| BLAKE2b-256 |
1eea7c7e05715505fdfdfe1c0d2feb8182e481376d4f60197a0ad9da1866b413
|
File details
Details for the file bgfx_python-1.0.4-cp37-cp37m-manylinux2014_x86_64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 5.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8205923bd62d60db170e9c898c8b1996425da69e12317c815358366ccd97855
|
|
| MD5 |
722756fc4031c7400f4eef7af26a48d1
|
|
| BLAKE2b-256 |
cd7c2b6053b58817da595451b07fc8d082796205a48748620dbc3bf44383793c
|
File details
Details for the file bgfx_python-1.0.4-cp37-cp37m-macosx_10_9_x86_64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
902ac33ed3eb2753b0a8119ef986f0e14d6bd6cf731a183cab964d01d0a10008
|
|
| MD5 |
4c86547d3ca6465bbce6df87b9dac209
|
|
| BLAKE2b-256 |
b68a658e71390173b1e0d93c4623822b86d7046f4cca495f56b7e4adcb8afd09
|
File details
Details for the file bgfx_python-1.0.4-cp36-cp36m-win_amd64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 3.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edd5944840e0cd9a0d9bee1f29ad57b5562ec3603bac84ce92bc420f7841412f
|
|
| MD5 |
6a5f5138d6c90bcca8cdb6f49053ef5e
|
|
| BLAKE2b-256 |
fb4a8d83df71fe0896b9df6ddb1a83fd21fdf4813718b9741d079e7f58e2e15d
|
File details
Details for the file bgfx_python-1.0.4-cp36-cp36m-manylinux2014_x86_64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 5.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ff021a7845bf9a1a2ab27248f3c9216b4891f9139ed2286a2516c5fbac2f81b
|
|
| MD5 |
f3773ac51a934abc1165eee0460d85ca
|
|
| BLAKE2b-256 |
d2b640b14fd65a85acba6409b442236a1bc36f3fb89d363e9bf295a733d07ac6
|
File details
Details for the file bgfx_python-1.0.4-cp36-cp36m-macosx_10_9_x86_64.whl.
File metadata
- Download URL: bgfx_python-1.0.4-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
086ba737c04c6e95c765370e8b080b20cf2b3380a2395f5fff24817004439b17
|
|
| MD5 |
c33fe9aab231134efd21fe370424bf83
|
|
| BLAKE2b-256 |
e1a3bcc141fcf86fb61d6c68cc72045971882bb11e2595c8a8e45f13064254a1
|