Draw Something

gdt::drawable

template <typename GRAPHICS, typename ACTUAL>
class gdt::drawable

A drawable is an almost ready to draw 3D entity you load from a file, holding the required surface data you need to provide your rendering pipeline.

Why almost?

In GDT, a drawable object contains the 3D vertices information of a model, without any material properties or texture map data. These attributes are stored in gdt::material objects or being set directly using gdt::pipeline instances.

Another part missing from gdt::drawable objects in the specific instance information about the position, rotation and scale of the model in the 3D world containing it. This information is being stored in the gdt::instance or gdt::instances template that can contain drawables or other type of GDT assets.

Here’s how you can subclass gdt::drawable to create your own assets:

class zombie : public my_app::asset<zombie>,
               public my_app::drawable<zombie> {
  public:
    moon(const my_app::context& ctx):
        my_app::drawable<zombie>(ctx, "res/zombie.smd") {}
};

And here’s how you could instantiate a drawable in your scene class:

gdt::instance<zombie> _zombie;
gdt::instances<zombie, 1000> _army_of_zombies;

Now, if you want direct control over your drawable instances, you can use gdt::driven together with a gdt::direct_driver or other drivers to help you manipulate your instances transformations:

gdt::driven<gdt::instance<zombie>, gdt::direct_driver> _movable_zombie;

Inherits from gdt::is_drawable< ACTUAL >

Public Functions

drawable(const graphics_context<GRAPHICS> &ctx, std::string filename, std::function<std::unique_ptr<model>(const char *filename)> loader = read_smd)

Construct a drawable from the provided SMD model filename.

Parameters
  • ctx: a graphics_context compatible context object
  • filename: full path to a valid SMD model
  • loader: file loader - SMD file loader by default

gdt::material

template <typename GRAPHICS>
struct gdt::material

GDT standard material for gdt::drawable objects.

Public Functions

material(const graphics_context<GRAPHICS> &ctx, const typename GRAPHICS::texture *d, const typename GRAPHICS::texture *n, const typename GRAPHICS::texture *s)

Constructs a new material using diffuse, normal and specular texture maps.

gdt::forward_pipeline

template <typename GRAPHICS>
class gdt::forward_pipeline

The forward rendering pipeline supports standard forward rendering and supports a single directional light. Here’s how a gdt::scene render method could look like using this pipeline:

void render(const my_app::context& ctx) override
{
    my_app::render_pass(ctx)
        .target(my_app::graphics::screen_buffer)
        .clear({0, 0, 0, 1});

    _pipeline.use(ctx)
        .set_material(_zombie.get_drawable().get_material())
        .set_camera(_camera)
        .draw(_moon);
}

Inherits from gdt::pipeline< GRAPHICS, forward_pipeline< GRAPHICS > >