+/GENN
genetically evolving neural networks
git clone https://git.julia.blue/+/GENN
cc48e92
master
1// TIGR - TIny GRaphics Library - v1.3 2// ^^ ^^ 3// 4// rawr. 5 6/* 7This is free and unencumbered software released into the public domain. 8 9Our intent is that anyone is free to copy and use this software, 10for any purpose, in any form, and by any means. 11 12The authors dedicate any and all copyright interest in the software 13to the public domain, at their own expense for the betterment of mankind. 14 15The software is provided "as is", without any kind of warranty, including 16any implied warranty. If it breaks, you get to keep both pieces. 17*/ 18 19#pragma once 20 21#ifdef __cplusplus 22extern "C" { 23#endif 24 25// Graphics configuration. 26#ifdef _WIN32 27#define TIGR_GAPI_D3D9 28#else 29#define TIGR_GAPI_GL 30#endif 31 32// Compiler configuration. 33#ifdef _MSC_VER 34#define TIGR_INLINE static __forceinline 35#else 36#define TIGR_INLINE static inline 37#endif 38 39// Bitmaps ---------------------------------------------------------------- 40 41// This struct contains one pixel. 42typedef struct { 43unsigned char b ,g ,r ,a ; 44}TPixel ; 45 46// Windows flags. 47#define TIGR_FIXED 0 // window's bitmap is a fixed size (default) 48#define TIGR_AUTO 1 // window's bitmap will automatically resize after each tigrUpdate 49#define TIGR_2X 2 // always enforce (at least) 2X pixel scale 50#define TIGR_3X 4 // always enforce (at least) 3X pixel scale 51#define TIGR_4X 8 // always enforce (at least) 4X pixel scale 52#define TIGR_RETINA 16 // enable retina support on OS X 53 54// A Tigr bitmap. 55typedef struct Tigr { 56int w ,h ;// width/height (unscaled) 57TPixel * pix ;// pixel data 58void * handle ;// OS window handle, NULL for off-screen bitmaps. 59}Tigr ; 60 61// Creates a new empty window. (title is UTF-8) 62Tigr * tigrWindow (int w ,int h ,const char * title ,int flags ); 63 64// Creates an empty off-screen bitmap. 65Tigr * tigrBitmap (int w ,int h ); 66 67// Deletes a window/bitmap. 68void tigrFree (Tigr * bmp ); 69 70// Returns non-zero if the user requested to close a window. 71int tigrClosed (Tigr * bmp ); 72 73// Displays a window's contents on-screen. 74void tigrUpdate (Tigr * bmp ); 75 76// Sets post-FX properties for a window. 77// hblur/vblur = whether to use bilinear filtering along that axis (boolean) 78// scanlines = CRT scanlines effect (0-1) 79// contrast = contrast boost (1 = no change, 2 = 2X contrast, etc) 80void tigrSetPostFX (Tigr * bmp ,int hblur ,int vblur ,float scanlines ,float contrast ); 81 82 83// Drawing ---------------------------------------------------------------- 84 85// Helper for reading/writing pixels. 86// For high performance, just write to bmp->pix yourself. 87TPixel tigrGet (Tigr * bmp ,int x ,int y ); 88void tigrPlot (Tigr * bmp ,int x ,int y ,TPixel pix ); 89 90// Clears a bitmap to a color. 91void tigrClear (Tigr * bmp ,TPixel color ); 92 93// Fills in a solid rectangle. 94void tigrFill (Tigr * bmp ,int x ,int y ,int w ,int h ,TPixel color ); 95 96// Draws an empty rectangle. (exclusive co-ords) 97void tigrRect (Tigr * bmp ,int x ,int y ,int w ,int h ,TPixel color ); 98 99// Draws a line. 100void tigrLine (Tigr * bmp ,int x0 ,int y0 ,int x1 ,int y1 ,TPixel color ); 101 102// Copies bitmap data. 103// dx/dy = dest co-ordinates 104// sx/sy = source co-ordinates 105// w/h = width/height 106void tigrBlit (Tigr * dest ,Tigr * src ,int dx ,int dy ,int sx ,int sy ,int w ,int h ); 107 108// Same as tigrBlit, but blends with the bitmap alpha channel, 109// and uses the 'alpha' variable to fade out. 110void tigrBlitAlpha (Tigr * dest ,Tigr * src ,int dx ,int dy ,int sx ,int sy ,int w ,int h ,float alpha ); 111 112// Same as tigrBlit, but tints the source bitmap with a color. 113void tigrBlitTint (Tigr * dest ,Tigr * src ,int dx ,int dy ,int sx ,int sy ,int w ,int h ,TPixel tint ); 114 115// Helper for making colors. 116TIGR_INLINE TPixel tigrRGB (unsigned char r ,unsigned char g ,unsigned char b ) 117{ 118TPixel p ;p .r = r ;p .g = g ;p .b = b ;p .a = 0xff ;return p ; 119} 120 121// Helper for making colors. 122TIGR_INLINE TPixel tigrRGBA (unsigned char r ,unsigned char g ,unsigned char b ,unsigned char a ) 123{ 124TPixel p ;p .r = r ;p .g = g ;p .b = b ;p .a = a ;return p ; 125} 126 127 128// Font printing ---------------------------------------------------------- 129 130typedef struct { 131int code ,x ,y ,w ,h ; 132}TigrGlyph ; 133 134typedef struct { 135Tigr * bitmap ; 136int numGlyphs ; 137TigrGlyph * glyphs ; 138}TigrFont ; 139 140// Loads a font. The font bitmap should contain all characters 141// for the given codepage, excluding the first 32 control codes. 142// Supported codepages: 143// 0 - Regular 7-bit ASCII 144// 1252 - Windows 1252 145TigrFont * tigrLoadFont (Tigr * bitmap ,int codepage ); 146 147// Frees a font. 148void tigrFreeFont (TigrFont * font ); 149 150// Prints UTF-8 text onto a bitmap. 151void tigrPrint (Tigr * dest ,TigrFont * font ,int x ,int y ,TPixel color ,const char * text , ...); 152 153// Returns the width/height of a string. 154int tigrTextWidth (TigrFont * font ,const char * text ); 155int tigrTextHeight (TigrFont * font ,const char * text ); 156 157// The built-in font. 158extern TigrFont * tfont ; 159 160 161// User Input ------------------------------------------------------------- 162 163// Key scancodes. For letters/numbers, use ASCII ('A'-'Z' and '0'-'9'). 164typedef enum { 165TK_PAD0 = 128 ,TK_PAD1 ,TK_PAD2 ,TK_PAD3 ,TK_PAD4 ,TK_PAD5 ,TK_PAD6 ,TK_PAD7 ,TK_PAD8 ,TK_PAD9 , 166TK_PADMUL ,TK_PADADD ,TK_PADENTER ,TK_PADSUB ,TK_PADDOT ,TK_PADDIV , 167TK_F1 ,TK_F2 ,TK_F3 ,TK_F4 ,TK_F5 ,TK_F6 ,TK_F7 ,TK_F8 ,TK_F9 ,TK_F10 ,TK_F11 ,TK_F12 , 168TK_BACKSPACE ,TK_TAB ,TK_RETURN ,TK_SHIFT ,TK_CONTROL ,TK_ALT ,TK_PAUSE ,TK_CAPSLOCK , 169TK_ESCAPE ,TK_SPACE ,TK_PAGEUP ,TK_PAGEDN ,TK_END ,TK_HOME ,TK_LEFT ,TK_UP ,TK_RIGHT ,TK_DOWN , 170TK_INSERT ,TK_DELETE ,TK_LWIN ,TK_RWIN ,TK_NUMLOCK ,TK_SCROLL ,TK_LSHIFT ,TK_RSHIFT , 171TK_LCONTROL ,TK_RCONTROL ,TK_LALT ,TK_RALT ,TK_SEMICOLON ,TK_EQUALS ,TK_COMMA ,TK_MINUS , 172TK_DOT ,TK_SLASH ,TK_BACKTICK ,TK_LSQUARE ,TK_BACKSLASH ,TK_RSQUARE ,TK_TICK 173}TKey ; 174 175// Returns mouse input for a window. 176void tigrMouse (Tigr * bmp ,int * x ,int * y ,int * buttons ); 177 178// Reads the keyboard for a window. 179// Returns non-zero if a key is pressed/held. 180// tigrKeyDown tests for the initial press, tigrKeyHeld repeats each frame. 181int tigrKeyDown (Tigr * bmp ,int key ); 182int tigrKeyHeld (Tigr * bmp ,int key ); 183 184// Reads character input for a window. 185// Returns the Unicode value of the last key pressed, or 0 if none. 186int tigrReadChar (Tigr * bmp ); 187 188 189// Bitmap I/O ------------------------------------------------------------- 190 191// Loads a PNG, from either a file or memory. (fileName is UTF-8) 192// On error, returns NULL and sets errno. 193Tigr * tigrLoadImage (const char * fileName ); 194Tigr * tigrLoadImageMem (const void * data ,int length ); 195 196// Saves a PNG to a file. (fileName is UTF-8) 197// On error, returns zero and sets errno. 198int tigrSaveImage (const char * fileName ,Tigr * bmp ); 199 200 201// Helpers ---------------------------------------------------------------- 202 203// Returns the amount of time elapsed since tigrTime was last called, 204// or zero on the first call. 205float tigrTime (); 206 207// Displays an error message and quits. (UTF-8) 208// 'bmp' can be NULL. 209void tigrError (Tigr * bmp ,const char * message , ...); 210 211// Reads an entire file into memory. (fileName is UTF-8) 212// Free it yourself after with 'free'. 213// On error, returns NULL and sets errno. 214// TIGR will automatically append a NUL terminator byte 215// to the end (not included in the length) 216void * tigrReadFile (const char * fileName ,int * length ); 217 218// Decompresses DEFLATEd zip/zlib data into a buffer. 219// Returns non-zero on success. 220int tigrInflate (void * out ,unsigned outlen ,const void * in ,unsigned inlen ); 221 222// Decodes a single UTF8 codepoint and returns the next pointer. 223const char * tigrDecodeUTF8 (const char * text ,int * cp ); 224 225// Encodes a single UTF8 codepoint and returns the next pointer. 226char * tigrEncodeUTF8 (char * text ,int cp ); 227 228#ifdef __cplusplus 229} 230#endif