Skip to content

czq1989/tow

Repository files navigation

TOW

TOW is a tiny OpenGL wrapper written in Literate. The Literate code of TOW is not much different from C++, you can read them without any knowledge about Literate. TOW only encapsulates the primary functions of OpenGL but provides more convenient methods with safety and less overhead🚀.

To draw things on the screen, usually, you only need these two objects: Framebuffer and Graphicpipeline, see the code below for detail.

// draw a simple triangle
tow::FramebufferPtr fb;
tow::GraphicPipelinePtr pipeline;

void init(){
    using namespace tow;

    fb = Framebuffer::create();

    vec2 vertices[] = { {-1, -1}, {1, -1}, {0, 1} };
    auto layout = VertexLayout::create();
    layout->add("a_position", {GL_FLOAT, 2});
    layout->stride(sizeof(vec2));

    auto bufGroup = BufferGroup::create();
    bufGroup->createBuffer("b_vertex", vertices, {GL_ARRAY_BUFFER, sizeof(vec2), 3});

    pipeline = GraphicPipeline::create({bufGroup, "b_vertex"}, layout);
}

void render(int x, int y, int w, int h){
    fb->bind(x, y, w, h);
    tow::drawArrays(pipeline, GL_TRIANGLES);
}

How to build

On Windows, make sure you have installed vs2017 or later before running premake5.bat.

On other platforms, you should install premake5, make and Literate corresponding to the platform, and then type in the command:

make -C lit all
premake5 your_action

How to clone

For most people, enter the command:

git clone https://github.com/czq1989/tow.git

But if you are in China and the cloning speed is slow, you can enter the command:

git clone https://gitclone.com/github.com/czq1989/tow.git

Examples

glTF Model Viewer

A viewer that can load gltf/glb file, and supports PBR, skin, morph target, and animation. Most files I have tested are from sketchfab and GeneratedAssets, however, in order to keep this repository small, I don't put all of them into the assets folder.

gltf_model_viewer gltf_model_viewer gltf_model_viewer

Shader Toy

A simple shader toy emulator that you can write glsl code to implement cool graphic effects.

shader_toy

UI Editor

An editor that is used to edit game UI elements. If you have a PSD file that all UI elements have already been arranged, drop it into the editor, then you can make some changes again or save it as a JSON file.

ui_editor

Block World Editor

A block editor like Minecraft, but easier to select and create blocks.

block_world_editor

Simple Paint

A simple and fast paint tool based on SDF supports undo, redo and layer blending.

simple paint

Credits

Thanks to: