pgl
PrimitiveOpenGL3Dprimitivelibrary
pgl Documentation

PGL, a primitive OpenGL 3D primitive library

https://github.com/wcaarls/pgl

example.jpg
Example

The library consists of the following main classes:

There are also utility Vector3 and matrix functions to specify points and coordinate Transformations such as Rotations and Translations. They mostly behave like you would expect them to.

In general, the classes have public members that can be accessed directly, such as a Primitive::transform or Camera::fovy.

The code to generate the example above is essentially

// Initialize our scene
scene = new pgl::Scene();
scene->attach(new pgl::Box({2, 2, 0.05}, {0, 0, -1}));
scene->attach(new pgl::WireBox({2, 2, 2}));
scene->attach(new pgl::Sphere(0.05));
scene->attach(new pgl::Arrow({-1, -1, -1}, { 0, -1, -1}, 0.02))->color = {1, 0, 0};
scene->attach(new pgl::Arrow({-1, -1, -1}, {-1, 0, -1}, 0.02))->color = {0, 1, 0};
scene->attach(new pgl::Arrow({-1, -1, -1}, {-1, -1, 0}, 0.02))->color = {0, 0, 1};
// Add a custom object that we'll animate
scene->attach(object = new pgl::Object());
object->attach(new pgl::Capsule({-0.3, 0, 0}, {0.3, 0, 0}, 0.02))->color = {1, 0, 0};
object->attach(new pgl::Capsule({0, -0.3, 0}, {0, 0.3, 0}, 0.02))->color = {0, 1, 0};
// Add STL model
scene->attach(new pgl::Model("teapot.stl", {0, 0, -1}, 0.1))->color = {1, 1, 0};
// Add some planes
scene->attach(new pgl::Plane({-100, 0, 0}, {0, 100, 0}, {0, 0, 10}))->color = {0.5, 0.5, 1};
scene->attach(new pgl::Plane({1, 0, 0}, {0, 1, 0}, {0, 0, -1}, pgl::Texture("ceramic-tiles.ppm"), 9));
scene->attach(new pgl::Plane({1, 0, 0}, {0, 0, 1}, {0, 1, 0}, pgl::Checkerboard4x4()))->color = {0, 1, 1};
// Initialize camera
camera = new pgl::Camera(scene);
// Initialize orbit controller
controller = new pgl::OrbitController(camera__);
controller->view(0.5, 0.4, 4);

The Camera's draw function would then be called in the window's refresh callback. To enable mouse interaction, the Controller's callback functions must be appropriately hooked into the window system. They are compatible with GLFW constants.

Note that it is not necessary to use the scene graph. You can draw the primitives in your own code by directly calling their draw function.