heyx3 / Bplus.jl

A modern OpenGL 4.6 rendering framework, written in Julia.
Other
69 stars 3 forks source link
3d gamedev graphics-programming julia opengl

B+

A game and 3D graphics framework for Julia, using OpenGL 4.6 + bindless textures. Offers game math, wrappers for OpenGL/GLFW/Dear ImGUI, scene graph algorithms, and numerous other modules.

Add it to your project with ] add Bplus or using Pkg; Pkg.add("Bplus").

A number of example projects are provided in the BpExamples repo:

Example Projects

Here is an open-source game project that heavily uses the ECS system:

Drill8

An ongoing voxel toy project of mine:

Voxel Toy Project

If you're wondering why Julia, read about it here!

Structure

To import everything B+ has to offer, just do using Bplus; @using_bplus. All documented modules are available directly inside (e.x. Bplus.Math), but under the hood this library is segmented into several smaller packages:

You can, for example, integrate BplusCore into your own project to get all the game math, without having to use OpenGL, Dear ImGUI, or any of the other parts of the library.

Tests

Unit tests follow Julia convention: kept in the test folder, and centralized in test/runtests.jl. Each sub-package (BplusCore, BplusApp, and BplusTools) runs its own tests, and this package runs each of those in sequence. The test behavior is standardized by BplusCore, which provides the path to a test-running Julia file through BplusCore.TEST_RUNNER_PATH.

I never liked how the official Julia Test package does not let you assign messages to tests, so my tests are implemented with my own macros:

Codebase

The three sub-packages are organized into a clear order. Each one has a set of modules within it.

---------  BplusCore  ----------
|                              |
|   Utilities         Math     |
|                              |
--------------------------------
              |
              |
              |
              |
--------------  BplusApp  ---------------
|                                       |
|                  GL                   |
|                /    \                 |
|               /      \                |
|              /        \               |
|           GUI          Input          |
|                                       |
-----------------------------------------
              |
              |
              |
              |
--------------  BplusTools  ---------------
|                                         |
|    ECS      Fields      SceneTree       |
|                                         |
-------------------------------------------

To import all B+ sub-modules into your project, you can use this snippet: using Bplus; @using_bplus.

Below is a quick overview of the modules. A thorough description is available here. You can also refer to the inline doc-strings, comments, and sample projects.

Bplus.Utilities

A dumping ground for all sorts of convenience functions and macros.

Detailed info can be found in this document, but here are the highlights:

Bplus.Math

Typical game math stuff, but using Julia's full expressive power.

Detailed info can be found in this document, but here is a high-level overview:

Bplus.GL

Wraps OpenGL constructs, and provides a centralized place for a graphics context and its accompanying window. This is the big central module of B+ along with Math.

Detailed information can be found in this document, but here is a high-level overview:

Bplus.Input

Detailed explanation available here.

Provides a greatly-simplified window into GLFW input, as a GL Context Service. Input bindings are defined in a data-driven way that is easily serialized through the StructTypes package.

Make sure to update this service every frame with service_Input_update(); this is already done for you if you build your game logic within @game_loop.

Bplus.GUI

Helps you integrate B+ projects with the Dear ImGUI library, exposed in Julia through the CImGui.jl package.

Detailed information can be found in this document, but here is how you use it at a basic level:

  1. Initialize the service with service_GUI_init().
  2. Start the frame with service_GUI_start_frame().
  3. After starting the frame, use CImGui as normal.
  4. End the frame with service_GUI_end_frame()

If you use @game_loop, then this is all handled for you and you can use CImGui freely.

To send a texture (or texture View) to the GUI system, you must wrap it with gui_tex_handle(tex_or_view)

Bplus.ECS

A very simple entity-component system that's easy to iterate on, loosely based on Unity3D's model. If you want a high-performance, use an external Julia ECS package instead such as Overseer.jl.

Detailed information can be found in this document, but here is a high-level overview:

Helpers

Things that don't neatly fit into the other modules are documented here.

Bplus.SceneTree

Provides a memory-layout-agnostic implementation of scene graph algorithms. Still a work-in-progress, but the architecture is pretty much done.

Read about this feature here.

Bplus.Fields

A data representation of scalar or vector fields, i.e. functions of some Vec{N1, F1} to some Vec{N2, F2}. As well as a nifty little language for quickly specifying them.

This is the first of a series of planned modules that will help you play with procedural content generation. For example, you can use a Field to easily fill a texture with interesting noise.

I'm not going to write more about this module for now, but check out the unit tests for examples.

License

Copyright William Manning 2019-2023. Released under the MIT license.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.