Skip to content

whlook/olive.c

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Olive.c

IMPORTANT! THIS LIBRARY IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! USE THIS LIBRARY AT YOUR OWN RISK!

Simple graphics library that does not have any dependencies and renders everything into the given memory pixel by pixel. Visit https://tsoding.org/olive.c/ to see some demos.

Quick Start

The truly reusable code is the one that you can simply copy-paste.

The library itself does not require any special building. You can simple copy-paste ./olive.c to your project and #include it. But you may want to build the binary tools for this project that are located in ./build/:

$ ./build.sh

How to Use the Library

This example uses stb_image_write.h to create the PNG image

// flag_jp.c
#define OLIVEC_IMPLEMENTATION
#include "olive.c"

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#define WIDTH 900
#define HEIGHT 600

uint32_t pixels[WIDTH*HEIGHT];

int main(void)
{
    Olivec_Canvas oc = olivec_canvas(pixels, WIDTH, HEIGHT);
    // Taken from https://upload.wikimedia.org/wikipedia/en/9/9e/Flag_of_Japan.svg
    olivec_fill(oc, 0xFFFFFFFF);
    olivec_circle(oc, WIDTH/2, HEIGHT/2, 180, 0xFF2D00BC);

    const char *file_path = "flag_jp.png";
    if (!stbi_write_png(file_path, WIDTH, HEIGHT, 4, pixels, sizeof(uint32_t)*WIDTH)) {
        fprintf(stderr, "ERROR: could not write %s\n", file_path);
        return 1;
    }
    return 0;
}

Test the Library

$ ./build/test

Update the test cases

If the expected behaviour of the library has changed in the way that breaks current test cases, you probably want to update them:

$ ./build/test record

About

Simple 2D Graphics Library for C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • C 78.3%
  • JavaScript 7.3%
  • CSS 5.5%
  • HTML 5.4%
  • Shell 3.5%