2D Vector Graphics Engine Powered by a JIT Compiler

Overview
Issues
  • Systematic use of uint32_t instead of enum

    Systematic use of uint32_t instead of enum

    The systematic use of uint32_t instead of the enum type is making the API very painful to use. I do not care much that the compiler cannot check that I am using the right enum but I am spending far more time than acceptable trying to figure out which enum type I should use for each function parameter.

    I do not now why that was done like that but I assume that there must be a reason (backward compatibility? consistency with the C api? make bindings easier? ...)

    If keeping uint32_t is really important then I propose the following approach that should solve the problem for the C++ api by providing the required information to Doxygen without changing the ABI.

    1. Declare the following template type

       #include <type_traits>
       template<typename T> using bl_enum = typename std::underlying_type<T>::type;
      

    or if you know that all enums are uint32_t

        template<typename T> using bl_enum = uint32_t;
    
    1. And replace each uint32_t by bl_enum<XXX> where XXX is the required enum type.
    enhancement 
    opened by schauveau 11
  • how will multi-threading work

    how will multi-threading work

    What is the intention for multi-threading? I am currently contemplating having several BLContext objects connected to the same BLImage. This is to support multiple "windows" on the same "framebuffer". The challenge for the window manager will be in some way controller the ordering of blits into the framebuffer. Of course, having each window with its own backing store, and just bliting in z order will do the trick.

    Is the intention of multi-threading to simply deal with multiple threads within a single drawing context? Or is there any intention of helping to manager multiple contexts? I assume the former (multi-thread within single context).

    Just want to be clear so I don't waste time creating something that's already on the roadmap.

    opened by Wiladams 11
  • Change interface to make possible to use library on _d.impl" hacks">

    Change interface to make possible to use library on "old" compillers without "->_d.impl" hacks

    A lot of library functions can be accessed only using "internal" mecanics like casting from "_d.impl" pointers to actual implementation. Using such code in application may be huge problem if some internals changes in future. I think its needed to add all such functional to system headers and make them looks like functions.

    F.i. to get current stroke width value now I need to use something like this:

    BLContextCore *core;
    double old_width = ((BLContextImpl*)core->_d.impl)->state->strokeOptions.width;
    

    I think its much better to have something like:

    #define blGetStrokeWidth( ctx ) ((BLContextImpl*)(ctx)->_d.impl)->state->strokeOptions.width
    

    in system header for ANSI and inline function for C++ mode.

    opened by JouriM66 9
  • Flush denormals to zero problem

    Flush denormals to zero problem

    Blend2D has problems when the CPU's FPU is set to flush denormals to zero. This is mostly related to our quadratic and cubic roots functions where we compare with tMin and tMax.

    This issue originated from https://github.com/blend2d/blend2d-samples/issues/2

    bug 
    opened by kobalicek 9
  • C API Help

    C API Help

    This issue is provided for C-API users.

    If you think that something in C-API is not documented well please add a comment here and we will try to update the documentation.

    opened by kobalicek 9
  • Clang in MSVC 2019

    Clang in MSVC 2019

    Hello again

    Blend2D suggest to use Clang, so I did generate the build project files for MSVC 2019 with clang installed using the following command:

    cmake -T ClangCL .. -DBLEND2D_STATIC=True
    

    It did generate project with LLVM (clang-cl) as Platform Toolset, but there are some warnings:

    2>clang-cl : warning : unknown argument ignored in clang-cl: '-fno-exceptions' [-Wunknown-argument]
    2>clang-cl : warning : unknown argument ignored in clang-cl: '-fno-rtti' [-Wunknown-argument]
    2>clang-cl : warning : unknown argument ignored in clang-cl: '-fno-math-errno' [-Wunknown-argument]
    

    Which I suppose might be crucial for those optimizations mentioned on the website regarding choosing compiler.

    The project does compile fine though.

    opened by iryont 8
  • Is there an Easy way to measure text?

    Is there an Easy way to measure text?

    I am getting lost between font, metrics, glyph buffers and the like. Is there an obvious way to measure the size of a string?

    More specifically, the text bounding box for some text. I know it's an obviously complex thing, but looking for the Cairo equivalent "toy" interface.

    opened by Wiladams 8
  • Malformed BLRegion being formed after adding BLBoxI's

    Malformed BLRegion being formed after adding BLBoxI's

    The following operation:

    var region = BLRegion()
    region.combine(box: BLBoxI(x0: 20, y0: 50, x1: 260, y1: 270), operation: .or)
    region.combine(box: BLBoxI(x0: -56, y0: -169, x1: 185, y1: 52), operation: .or)
    region.combine(box: BLBoxI(x0: -46, y0: -134, x1: 29, y1: -118), operation: .or)
    

    results in an invalid region.

    Context: The combine method invokes blRegionCombineRB(this, this, &box, operation), like the combine method from BLRegion::combine.

    After these operations, the BLRegion pointer seems to be filled with garbage from the memory, but I'm not sure what exactly could be happening.

    opened by LuizZak 7
  • Build error MSVC 19.16.27030.1

    Build error MSVC 19.16.27030.1

    Visual Studio 15 2017 CMake creates project and all that. ultimately cl compiler will report error: D8016: '/Ox' and '/RTC1' command-line options are incompatible. I'm compiling for 32-bit also. Last time around I just went into the project and disabled either or both of these and moved along, but I think it's worth reporting if you want to fix this at the source.

    opened by Wiladams 7
  • Assertion failure when appending particular sequence of boxes to BLRegion

    Assertion failure when appending particular sequence of boxes to BLRegion

    The following code triggers an assertion in region.cpp line 1595:

    var region = BLRegion()
    region.combine(box: BLBoxI(x0: 174, y0: 92, x1: 506, y1: 463), operation: .or)
    region.combine(box: BLBoxI(x0: 189, y0: 466, x1: 482, y1: 478), operation: .or)
    region.combine(box: BLBoxI(x0: 189, y0: 478, x1: 482, y1: 484), operation: .or)
    
    // Bang!
    region.combine(box: BLBoxI(x0: 189, y0: 440, x1: 482, y1: 446), operation: .or)
    
    bug 
    opened by LuizZak 6
  • [Questions] blitImage performance and BLImage color modulation

    [Questions] blitImage performance and BLImage color modulation

    I wrote a simplistic backend for my game using Blend2D. However, its performance with pretty much only blitImage being called thousands of times with images of varying width from 16x16 to 64x64 (and sometimes bigger for UI elements, but only a few) is rather bad compared to simplistic software blitter on SDL2 (about 38 fps on Blend2D vs 76 fps on SDL2 software renderer). I kind of expected Blend2D to a bit faster due to all the SIMD going on unlike within SDL2 software blitter. However, it does not appear to be the case.

    The question would be, is this rather expected because Blend2D seems to be vector graphics engine and I shouldn't expect much performance from simplistic image blitting or is there something I can do to make it faster?

    Another question - how can I modulate the color of BLImage with blitImage function? Is this even possible? For example, I have a white mask which needs to be first modulated by a color value and then blended into the target with specific composition mode (setCompOp). I did try doing it with setStyle(BL_COMP_OP_MODULATE, BLRgba32(255, 0, 0, 255)), but it does not appear to be working.

    opened by iryont 6
  • Fix build for VS 2017

    Fix build for VS 2017

    Here are some small patches to make blend2d build with VS 2017. We found this issue when building blend2d from vcpkg using VS 2017 which is described in this issue

    opened by jasonbeverage 5
  • Clipping paths

    Clipping paths

    I would like to write a Rive renderer using Blend2D. It looks like BL supports all the required features, except I can't find reference to clipping paths (only clipRect) in the docs.

    Are clip paths planned for the future?

    This would be the only blocker to a Rive renderer at first glance.

    opened by projectitis 0
  • Create a blank image and fill it with fonts

    Create a blank image and fill it with fonts

    `int main() { string strText = "ABCDEEG"; int w = 200; int h = 50; int fontSize = 24;

    BLFontFace face;
    face.createFromFile("SourceHanSansSC-Regular.otf");
    
    BLFont font;
    font.createFromFace(face, fontSize);
    
    BLFontMetrics fm = font.metrics();
    
    IplImage *img = cvCreateImage(cvSize(w, h), 8, 4);
    
    cvSetZero(img);
    BLImage bl;
    bl.createFromData(w, h, BL_FORMAT_PRGB32, img->imageData, img->widthStep);
    
    
    BLContext ctx(bl);
    ctx.setFillStyle(BLRgba32(0xFFFFFFFF));
    
    int y = (h - fontSize) / 2 + fm.ascent - fm.descent;
    ctx.fillUtf8Text(BLPoint(10, y), font, strText.c_str());
    
    ctx.end();
    
    cv::Mat mat;
    mat = cv::cvarrToMat(img);
    
    cv::imwrite("2.png", mat);
    bl.writeToFile("3.png");
    
    return 0;
    

    }`

    opened by HowToExpect 3
  • Unexpected lines in SDL2 textures from BLImages

    Unexpected lines in SDL2 textures from BLImages

    Following the example of implementing blend2d with SDL2 in this sample , I came to a possible bug that can be produced through the example below.

    #include <SDL2/SDL.h>
    #include "blend2d.h"
    
    int main(){
        SDL_Window * window;
        SDL_Renderer * renderer;
        
        if(SDL_Init(SDL_INIT_VIDEO) != 0){
            error("Unable to init sdl");
        }
        
        if(!(window = SDL_CreateWindow("win", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE))){
            error("Unable to create sdl window");
        }
        
        if(!(renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC))){
            error("Unable to create sdl renderer");
        }
        
        SDL_Event e;
        
        SDL_Texture * texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 500, 500);
        
        SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
    
        BLImage img = BLImage(500, 500, BL_FORMAT_PRGB32);
        
        BLContext ctx = BLContext(img);
        
        ctx.setCompOp(BL_COMP_OP_CLEAR);
        ctx.fillAll();
        
        ctx.setCompOp(BL_COMP_OP_SRC_OVER);
        ctx.setFillStyle(BLRgba32(0xFFFEFEFE));
        ctx.fillRoundRect(50, 50, 400, 400, 50);
        
        ctx.end();
        
        img.writeToFile("img.png");
        
        BLImageData data;
        img.getData(&data);
        SDL_UpdateTexture(texture, NULL, data.pixelData, int(data.stride));
        
        SDL_Rect rect = {50,50,500,500};
        
        while (true) {
            while (SDL_PollEvent(&e) != 0) {
                if(e.type == SDL_QUIT)
                    exit(0);
            }
            SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
            SDL_RenderClear(renderer);
            SDL_RenderCopy(renderer, texture, nullptr, &rect);
            SDL_RenderPresent(renderer);
        }
    }
    

    Which results in:

    Captura de ecrã 2022-03-11, às 23 42 53

    The problem is that lines (that do not exist in the image generated by the context) appear in the curved regions of the Paths (in the SDL2 texture).

    (Translated by Google)
    opened by ReneMuala 8
  • a simple cubic going crazy

    a simple cubic going crazy

    it's a just a simple cubic, but for some degenerate cases it takes seconds and gigabytes of memory !

    // a simple cubic,
     // it is a degenerate curve for beta 0, PI/2, PI, ...
     // it works for beta = 0.0
     //  BUT for beta = 2*PI    (same curve as for beta = 0)
     //  it uses GigaBYTES !
    BLPath mycurve(double R, double beta) {
    
      BLPath path;
      double x = R*cos(beta);
      double y = R*sin(beta);
    
      path.moveTo(x,y);
      path.cubicTo(0.0,2*y,  0.0,-2*y,  x,-2*y);
    
      return path;
    }
    
    
    BLImage render(const BLContextCreateInfo& cci) {
      BLImage img(512, 512, BL_FORMAT_PRGB32);
      BLContext ctx(img, cci);
    
      ctx.clearAll();
    
      BLPoint P;
      double R = 200.0;
    
      // build a path p0  with beta 0.0
      BLPath path0 = mycurve(R, 0.0);
    
       // for beta=360,  mycurve(R,2*PI)   should be  equal to mycurve(R,0) 
       //  but ...
       //  we have an approx PI ... 
    
      double PI =3.141592653589793; 
      BLPath path360 = mycurve(R, 2*PI);
    
    
      // TEST !!!   repeat 50 times  ... Strace gives <Execution timed out>
    
      ctx.setStrokeStyle(BLRgba32(0xFFFFFFFF));
    
      for (int i=0; i< 50; ++i) {
          ctx.strokePath(path0);
    
        ctx.strokePath(path360);
      }
      return img;
    }
    
    bug 
    opened by abu-irrational 3
Owner
Blend2D
Blend2D project
Blend2D
Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal

Low Level Graphics Library (LLGL) Documentation NOTE: This repository receives bug fixes only, but no major updates. Pull requests may still be accept

Lukas Hermanns 1.3k May 12, 2022
A terminal-based graphics library for both 2D and 3D graphics.

TermGL A terminal-based graphics library for both 2D and 3D graphics. Written in C, created for terminals supporting ANSI escape codes. Table of Conte

null 193 May 9, 2022
kaun is a replacement for löve's built-in love.graphics module intended for 3D graphics

kaun kaun is a replacement for löve's built-in love.graphics module intended for 3D graphics. It is a Lua module you can require from a shared library

Joel Schumacher 4 Apr 5, 2021
This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.

DirectX-Graphics-Samples This repo contains the DirectX 12 Graphics samples that demonstrate how to build graphics intensive applications for Windows

Microsoft 4.5k May 13, 2022
The DirectX Shader Compiler project includes a compiler and related tools used to compile High-Level Shader Language (HLSL) programs into DirectX Intermediate Language (DXIL) representation

DirectX Shader Compiler The DirectX Shader Compiler project includes a compiler and related tools used to compile High-Level Shader Language (HLSL) pr

Microsoft 2.2k May 12, 2022
Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.

This project is not actively maintained. NanoVG NanoVG is small antialiased vector graphics rendering library for OpenGL. It has lean API modeled afte

Mikko Mononen 4.3k May 5, 2022
rlottie is a platform independent standalone c++ library for rendering vector based animations and art in realtime

rlottie rlottie is a platform independent standalone c++ library for rendering vector based animations and art in realtime. Lottie loads and renders a

Samsung 682 May 17, 2022
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

bgfx - Cross-platform rendering library GitHub Discussions Discord Chat What is it? Cross-platform, graphics API agnostic, "Bring Your Own Engine/Fram

Бранимир Караџић 11.5k May 10, 2022
3D engine from scratch (without OpenGL or any other 3D graphics library)

Simple 3d engine based on SFML library. I tried to make this engine powerful and easy to understand.

Vectozavr 20 Apr 6, 2022
Dear PyGui 3D Engine (early development) and Graphics API demos.

Marvel This repo is the working location of the eventual Dear PyGui 3D Engine. It also contains several single file examples of creating a triangle wi

Jonathan Hoffstadt 74 May 8, 2022
Vire is a C++ voxel rendering engine. It is written in C++14 and uses OpenGL for graphics.

Vire Vire is a C++ voxel rendering engine. It is written in C++14 and uses OpenGL for graphics. Downloads If you'd just like to just download and try,

null 33 May 4, 2022
Horde3D is a small 3D rendering and animation engine. It is written in an effort to create an engine being as lightweight and conceptually clean as possible.

Horde3D Horde3D is a 3D rendering engine written in C++ with an effort being as lightweight and conceptually clean as possible. Horde3D requires a ful

Volker Vogelhuber 1.2k May 5, 2022
Open 3D Engine (O3DE) is an Apache 2.0-licensed multi-platform AAA Open 3D Engine

Open 3D Engine (O3DE) is an Apache 2.0-licensed multi-platform 3D engine that enables developers and content creators to build AAA games, cinema-quality 3D worlds, and high-fidelity simulations without any fees or commercial obligations.

O3DE 4.8k May 18, 2022
ORE (OpenGL Rendering Engine) is a rendering engine developed for my college minor project assessment.

ORE (OPENGL RENDERING ENGINE) What is ORE? ORE(OpenGL Rendering Engine) is a rendering engine with great and easy to use UI that allows the user to lo

HARSHIT BARGUJAR 4 Dec 20, 2021
A modern cross-platform low-level graphics library and rendering framework

Diligent Engine A Modern Cross-Platform Low-Level 3D Graphics Library Diligent Engine is a lightweight cross-platform graphics API abstraction library

Diligent Graphics 2.3k May 9, 2022
Lightweight and modular C++11 graphics middleware for games and data visualization

Magnum — Lightweight and modular C++11/C++14 graphics middleware for games and data visualization Looking for an open-source library that gives you gr

Vladimír Vondruš 4k May 10, 2022
Yocto/GL: Tiny C++ Libraries for Data-Driven Physically-based Graphics

Yocto/GL: Tiny C++ Libraries for Data-Oriented Physically-based Graphics Yocto/GL is a collection of small C++17 libraries for building physically-bas

Fabio Pellacini 2.3k May 6, 2022
📽 Highly Optimized Graphics Math (glm) for C

?? OpenGL Mathematics (glm) for C Documentation Almost all functions (inline versions) and parameters are documented inside the corresponding headers.

Recep Aslantas 1.4k May 9, 2022
A library for high-performance, modern 2D graphics with SDL written in C.

SDL_gpu, a library for making hardware-accelerated 2D graphics easy. by Jonathan Dearborn SDL_gpu is licensed under the terms of the MIT License. See

Jonathan Dearborn 1k May 10, 2022