.onedev-buildspec.yml Loading last commit info...
Packaging/Linux
examples
include/TessesFrameworkGFX
src
.gitignore
CMakeLists.txt
Config.cmake.in
LICENSE.md
README.md
font.png
README.md

Tesses Framework GFX

A simple graphics library for C++

TGFX Font

You can use the font freely (I made it)

To Install (from source)

git clone https://onedev.site.tesses.net/tesses-framework/tessesframework-gfx.git
cd tessesframework-gfx
cmake -S .. -B .
make -j`nproc`
sudo make install

To Install (from source, without fetchcontent)

Get Tesses Framework https://onedev.site.tesses.net/tesses-framework

git clone https://onedev.site.tesses.net/tesses-framework/tessesframework-gfx.git
cd tessesframework-gfx
cmake -S .. -B . -DTESSESFRAMEWORKGFX_FETCHCONTENT=OFF
make -j`nproc`
sudo make install

To install on ubuntu from package manager

Set up my repos here

sudo apt update
sudo apt install tessesframework-gfx

To use in C++ include

#include <TessesFrameworkGFX/TessesFrameworkGFX.hpp>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;

...

int main(int argc, char** argv) 
{
    TF_Init();
    ...
    TF_Quit();
}

To create an image

Image image(640,480); //or without arguments

To draw a line

image.DrawLine(Point(40,50),Point(50,60), Colors::Blue, 2); //line thickness is 2

To draw a rectangle

image.DrawRectangle(Rectangle(8,8,20,20), Colors::Green, 5); //border size is 5
image.FillRectangle(Rectangle(8,40,20,28), Colors::Yellow); //fill a rectangle

To draw text in that font above (it is my font)

the font is 16x16 but this function treats it as 18 width (for padding so the text isn't squished), this also only supports uppercase letters and the ascii table (no lower case or non ascii chars, non ascii chars will appear as spaces and lower case will appear as uppercase)

image.DrawString("Hello, world", Point(0,1),Colors::Red);

Image formats

Loading images (png and jpeg use stb, bmp is my own implementation)

auto strm = std::make_shared<FileStream>("file.png","rb");
Formats::Png::Load(strm, &image);

Saving images (png and jpeg use stb, bmp is my own implementation)

auto strm = std::make_shared<FileStream>("file.png","wb");
Formats::Png::Save(strm, &image);

Resizing images (uses nearest neighbor by default and is the only option right now)

Image newImage;
image.Resize(&newImage,Size(320,240));

Drawing images onto other images

Overwrite just overwrites existing pixels in destination from source, Invert inverts the src pixels when copying from source to destination (does not touch source, just so we are clear), InvertIfNotTransparent inverts pixels in the destination image if the alpha channel in source image is >127 also point is for location in destination, it will use 0, 0 in source and w, h for source

Image srcImg;
image.DrawImage(&srcImg, Point(10,10), ImageCopyEffect::Overwrite);

Resizing and drawing to another image

We need to combine the last two examples

  • srcImg: the source picture
  • tmpImg: the resized image
  • image: the image we want to draw to
Image srcImg; //this would not be right here it would have data in it (even text you want to make bigger)
Image tmpImg;
srcImg.Resize(&tmpImg,Size(320,240));
image.DrawImage(&tmpImg, Point(10,10), ImageCopyEffect::Overwrite);

Webcam

On windows and linux if TESSESFRAMEWORKGFX_ENABLE_WEBCAM is defined in cmake You can use this to find webcams It will not find any if TESSESFRAMEWORKGFX_ENABLE_WEBCAM is not defined and Device::IsEnabled() will return false Uses https://github.com/rojarand/libwebcam released under MIT (FetchContent, and is optional)

auto devs = Device::GetDevices();
for(auto dev : devs)
{
    std::cout << dev.Name << std::endl;
    for(auto res : dev.Resolutions)
    {
        std::cout << "\t" << res.ToString() << std::endl;

        //if this camera and resolution are desired
        Device dev2(dev.Device, res,10); //10 fps
        dev2.Open();
        do {
            
            auto frame = auto frame = dev2.ReadFrame();
            if(frame != nullptr)
            {
                //frame is a shared pointer to an image
                Image* img = frame.get(); //if you need a pointer for saving or whatnot
            }
        } while(true);

        dev2.Close();

    }
    std::cout << std::endl;
}
Please wait...
Page is in error, reload to recover