This is a general framework for fragment-shader-based figure drawing
By manipulating pixels directly, you can paint any surface you want.
With great power comes great responsibility. You have to implement all of the following:
- Geometry representation (usually as signed distance functions)
- Composition of a scene
- Blending different objects in the scene
- Antialiasing
However, if you plan to draw only simple primitives like circles, lines, and ovals. You might want to consider using cairo
project. It provides beautiful line
drawings.
Put a shader.frag
file next to the executable. Edit the shader and reload to draw things. Save as PNG if you want.
Check sample_shader.frag
and shader.frag
to see provided uniforms and attributes,
- Mouse drag (left button) - change
translateX
andtranslateY
- Mouse scroll - modify
scale
- S key - save current figure as
fig.png
- R key - reload shader
shader.frag
. Use this after updating the shader
- A C++ compiler with C++17 spec support
- A GPU with OpenGL >= 4.6 support
- glfw3
- glew
- libpng
Use cmake
to process CMakeLists.txt and generate a project for your toolchains.
Install gcc, make, glfw3, glew, libpng, mesa
and run cmake . && make
Install glfw, glew, libpng
and configure vcpkg with your build system
(see https://github.com/microsoft/vcpkg)
- Open your web browser, download
glfw3, glew, libpng
. - Install all the dependencies.
- Install all the dependencies of the dependencies (i.e. libzlib).
- Install and open
cmake-gui
. Configure to generate a VS project. - It might stop while configuring. Find all the missing variables.
- Open up the project. Build all.