You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Go to file
CNLohr 44e21268b5
Merge pull request #91 from cntools/xlib_better_info
2 years ago
examples Fix exit button not working in examples 2 years ago
tools Final fixes for Windows. 3 years ago
wasm Fix exit button not working in examples 2 years ago
.gitignore Gitignore simple binary 3 years ago
CNFG.c Final fixes for Windows. 3 years ago
CNFG.h Cleanup usage for HTTP only 2 years ago
CNFG3D.c make rawdraw wasmable 4 years ago
CNFGAndroid.h Improve behavior for when running on the Meta Quest with OpenXR. 2 years ago
CNFGEGLDriver.c Improve behavior for when running on the Meta Quest with OpenXR. 2 years ago
CNFGEGLLeanAndMean.c Fix compile (typo leaving normal return) 3 years ago
CNFGFunctions.c Cleanup usage for HTTP only 2 years ago
CNFGHTTP.c Clarify usage for cnfghttp server 2 years ago
CNFGNullDriver.c Fix Android Update Screen With Bitmap Function 4 years ago
CNFGOGLEGLDriver.c Update CNFGOGLEGLDriver.c 3 years ago
CNFGRasterizer.c Cleanup from some notes from a static analysis tool. 2 years ago
CNFGWASMDriver.c Update CNFGWASMDriver.c 3 years ago
CNFGWinDriver.c Fix context only mode on Windows 2 years ago
CNFGXDriver.c Fixup X11 operation on Linux, and validate more scenarios. 2 years ago
LICENSE Cleanup in preparation for version tag 0.9 4 years ago
Makefile Fixup X11 operation on Linux, and validate more scenarios. 2 years ago
README.md Fix exit button not working in examples 2 years ago
chew.c Update CNFG to be more library-like 4 years ago
chew.h Bump chew for cnovr 2 years ago
chewtypes.h Add chewtypes, so you can build cnovr + OpenGL without OpenGL dev headers. 3 years ago
ogltest.c Fix exit button not working in examples 2 years ago
os_generic.h make rawdraw wasmable 4 years ago
osdtest.c Fixup X11 operation on Linux, and validate more scenarios. 2 years ago
rawdraw.c * Update rawdraw_sf to newest version. 2 years ago
rawdraw_sf.h Fixup X11 operation on Linux, and validate more scenarios. 2 years ago
simple.c add return value from CNFGHandleInput on windows 3 years ago
tccbuild.bat Add a demo using tinycc. 4 years ago

README.md

CN's Fundamental Graphics Library

An OS-Agnostic (including No OS AT ALL!) drawing system. It includes lines, boxes, linetext, points, bitmaps.

The drawing method can either be by the OS (i.e. SetPixel in Windows), rasterized in software (we draw our own lines) or by OpenGL where available. You can reconfigure it with various #defines. It also makes it really easy to get an OpenGL window on just about any supported platform.

Somewhere unusual and want to open a window and draw stuff? Use rawdraw.

Other packages too big, bulky or include junk you don't want? Use rawdraw.

Want to use OpenGL really quickly? Use rawdraw.

For embedded platforms, CNFGRASTERIZER is usually the back end which allows you to have high level commands on a framebuffer. It's what was used in ESP Channel 3. You can even play with the rasterizer on every mode except the Android port by defining it. You can even be twisted on Windows, Linux and on WASM (Web) and define it.

This is not like SDL - some drivers have different quirks, some have more features implemented than others, and a major goal is not to abstract very much, but almost to provide an exmaple how to use graphics on a specific platform.

Platform statuses

  • Windows, 100% Support for CNFGOGL and/or CNFGRASTERIZER, Native (GDI32) does not support alpha-blitting, or variable line width.
  • Linux, 100% Support for CNFGOGL and/or CNFGRASTERIZER, Native (X11) does not support alpha-blitting, or variable line thickness .
  • Android, 100% Support for CNFGOGL (It is forced on) CNFGRASTERIZER not allowed.
  • WASM, 100% Support for CNFGOGL
  • Other EGL (Like Raspberry Pi Raw Metal) Platforms, same as Android, but fixed window size.
  • EGL, CNFGOGL represent OpenGL or OpenGL ES depending on platform support.
  • Vulkan support in progress.
  • CNFG3D Support has been ported with fixed-precision numericals to ESP8266.
  • Mac/OSX Support currently unknown. Legacy files moved here: https://github.com/cntools/rawdrawtools/tree/main/attic

Usage in project

You may want to include CNFG as a submodule or as a single-file header. You can just download rawdraw_sf.h to the path your project is in and #include it.

To use it as a single file (rawdraw_sf.h), you can just wget https://raw.githubusercontent.com/cntools/rawdraw/master/rawdraw_sf.h

To use it as a submodule you can:

git submodule add https://github.com/cntools/rawdraw

paste the command above on your terminal to get a clone of the repository on your system.

note: Incase you get a error saying

fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

use the command git init first.

To use CNFG, be sure to do this, or include "CNFG.c" in your project.

#define CNFG_IMPLEMENTATION

prerequisites and some instructions for running on linux

firstly, make sure you have the following libraries installed:

xorg-dev
libx-dev
libxinerama-dev libxext-dev
mesa-common-dev libglu1-mesa-dev

to do so and also to install them incase they are not already, run the following commands:

sudo apt-get update
sudo apt-get install xorg-dev libx11-dev libxinerama-dev libxext-dev mesa-common-dev libglu1-mesa-dev

then to run the sample program in rawdraw, go to the clone of the repository on your system, open a terminal window there, and run the command make. this will create an executable file called "simple" from the c file called "simple.c". You should be able to run the executable "simple" with the command ./simple

Example program

A more comprehensive example can be found in rawdraw.c, but a basic example is as follows:



//Make it so we don't need to include any other C files in our build.
#define CNFG_IMPLEMENTATION

#include "rawdraw_sf.h"

void HandleKey( int keycode, int bDown ) { }
void HandleButton( int x, int y, int button, int bDown ) { }
void HandleMotion( int x, int y, int mask ) { }
void HandleDestroy() { }
int main()
{
	CNFGSetup( "Example App", 1024, 768 );
	while(CNFGHandleInput())
	{
		CNFGBGColor = 0x000080ff; //Dark Blue Background

		short w, h;
		CNFGClearFrame();
		CNFGGetDimensions( &w, &h );

		//Change color to white.
		CNFGColor( 0xffffffff ); 

		CNFGPenX = 1; CNFGPenY = 1;
		CNFGDrawText( "Hello, World", 2 );
		//Draw a white pixel at 3,0 30 
		CNFGTackPixel( 30, 30 );         

		//Draw a line from 50,50 to 100,50
		CNFGTackSegment( 50, 50, 100, 50 );

		//Dark Red Color Select
		CNFGColor( 0x800000FF ); 

		//Draw 50x50 box starting at 100,50
		CNFGTackRectangle( 100, 50, 150, 100 ); 

		//Bright Purple Select
		CNFGColor( 0x800000FF ); 

		//Draw a triangle
		RDPoint points[3] = { { 30, 36}, {20, 50}, { 40, 50 } };
		CNFGTackPoly( points, 3 );

		//Draw a bunch of random pixels as a blitted image.
		{
			static uint32_t data[64*64];
			int x, y;

			for( y = 0; y < 64; y++ ) for( x = 0; x < 64; x++ )
				data[x+y*64] = 0xff | (rand()<<8);

			CNFGBlitImage( data, 150, 30, 64, 64 );
		}

		//Display the image and wait for time to display next frame.
		CNFGSwapBuffers();		
	}
}

Building

Windows compile: Build with clang

clang simple.c -o simple -Irawdraw -lopengl32 -lgdi32 -luser32 

Build with TCC

C:\tcc\tcc simple.c -Irawdraw -lopengl32 -lgdi32 -luser32 C:\windows\system32\msvcrt.dll

Linux compile:

gcc -o simple simple.c -lm -lX11

Note, with the STB-style header, you don't need to #define CNFG_IMPLEMENTATION anywhere in your code, and instead can also compile in cnfg.c

Configurations

Rawdraw is a very disjoint set of configurations

CNFG Configuration options include:

  • CNFG_IMPLEMENTATION = Include code for implementation.
  • __android__ = build Android port
  • WINDOWS, WIN32, WIN64 = Windows build
  • CNFGOGL = Make underlying functions use OpenGL if possible.
  • CNFGRASTERIZER = Make the underlying graphics engine rasterized functions (software rendering)
  • CNFG3D = Include CNFG3D with this rawdraw build. This provides rasterized graphics functions. Only use this option with the rasterizer.

Platform-Specific

  • HAS_XSHAPE = Include extra functions for handling on-screen display functionality in X11.
  • HAS_XINERAMA = Use X11's Xinerama to handle full-screen more cleanly.

Flags you will probably never want to use:

  • EGL_LEAN_AND_MEAN = Bare bones EGL Driver

Extra goodies

RDUI

RDUI is mainted by Overlisted and contains a lot of extra features for rawdraw. You can check it out here: https://github.com/overlisted/rdui

chew.h

You can copy-and-paste chew.c and chew.h into your program for a single-file compile-only version of GLEW. This is WAY BETTER than having to deal with the complicated system they have set up, but it doesn't include all the functions. You can easily add OpenGL functions to it.

It provides a very easy-to-use interface for OpenGL Extensions.

os_generic.h

os_generic is a platform independent way of creating threads, managing TLS, mutices, semaphores as well as getting the current time. It has the following configuration options:

OSG_NO_IMPLEMENTATION - Do not include implementation as static functions. OSG_PREFIX - Override function prefix OSG_NOSTATIC - Do not declare the functions as static.

TextTool/Text.c etc...

There is a sister repository, https://github.com/cntools/rawdrawtools which houses a text tool.

Warnings

  • OSX Support has been moved to attic.
  • No support for openGL 1.0. If your hardware doesn't support openGL 2.0 or newer, disable openGL support. (If you are on desktop, it probably does, you just need to install updated drivers.)