Giter VIP home page Giter VIP logo

jaysmito101 / cgl Goto Github PK

View Code? Open in Web Editor NEW
391.0 4.0 37.0 46.94 MB

CGL (C Game Library) is a multipurpose library mainly for recreational coding / demo scenes / prototyping / small games / experimentation.

Home Page: https://jaysmito101.github.io/cgl/

License: MIT License

C 53.48% Python 0.23% Cython 12.75% Rust 33.54%
3d c9 graphics opengl cpp phong-lighting rendering tilemap game gamedev

cgl's Introduction

Lines of code Maintenance Support me on Patreon


Index


CGL

CGL (C Graphics Library) is a multipurpose library mainly for recreational coding / demo scenes / prototyping / small games / experimentation. This has a lot of utilities for graphics. And best of all all of it is inside a single header file cgl.h. Also CGL is made purely in C but is also compatible with C++.

NOTE : Do not think that header only means its going to increase compile time as the implementation needs be enabled only for 1 file using #define CGL_IMPLEMENTATION. See Examples


Target Platforms

  • Windows
  • Linux
  • MacOS (untested)
  • WebAssembly (Beta)
  • Android (Coming Soon)

What does CGL Provide?

  • cgl-rs

  • cgl-py

  • Windowing library (Optional)

    • You can completely disable it by #define CGL_EXCLUDE_WINDOW_API
    • This windowing library is primarily a wrapper GLFW along with a few extra functionalities. Example : In case you are using some library like nuklear for GUI it will mess up all glfw callbacks so with CGL you can restore the CGL callbacks with a call to CGL_window_resecure_callbacks
  • Utility functionalities

    • Reading/Writing files
    • Random float/int/bool/vec2/vec3/color generation
    • CRC32/CRC64
    • ROT13 encryption
    • General Purpose Hashing Functions refer here
    • Colored printf (red, green, blue, gray/yellow)
    • Point/Triangle intersection check
    • 3D transform API (matrix calculation, etc)
    • TODO: [ MD5 / SHA 256 / SHA 128 / AES ]
  • Noise API

    • Multiple faster Alternatives to libc's rand
    • Procedural Coherent Noise Algorithms
      • Perlin's Noise (Improved Version)
      • OpenSimplex2
      • Value Noise
      • Worley Noise (or Cellular Noise)
    • Fractals like FBm, Rigid, Billow, PingPong
    • Parameters for Octaves/Lacunarity/Weighted Strength/Gain
  • Triangulation

    • Bower Watson Algorithm for Delaunay Triangulator
  • Artificial Intelligence

    • Neural Netowrks
    • Backpropagation
    • Serializing/Deserializing networks
    • Multi Variable Linear Regression
  • Graph Algorithms

    • A* Path Finding (general purpose)
    • N Dimensional Spatial Partition and Localization (n dimensional version of a quad tree)
  • Data structures

    • List(dynamic array) + Stack (implemented together)
    • Hashtable -> This hastable is general purpose. Key can be string or a n-bit buffer. The value can be anything int, string, float, custom types, ...
      • Hashtable Iterator -> Iterate through the hashtable using a simple API
  • Logger

    • Can be enabled/disabled by #define CGL_DISABLE_LOGGER
    • Log to multiple log files simultaneously
    • Log to console with colored output for seperate log levels
    • Logger with auto timestamps
  • Cross Platform Networking (Optional)

    • You can disable all networking by #define CGL_EXCLUDE_NETWORKING
    • Low-level sockets
    • SSL sockets (optional) (requires OpenSSL)
    • HTTP/HTTPS request (beta)
  • General Purpose Markov Chains (Optional) Example

    • Can work with any type of data ( text / image / etc. )
    • Train/Generate with 3 - 4 lines of code
    • Trainer implemented for text generation (n-gram based)
    • Custom trainer API for custom scenarios
  • Cross Platform Threading

    • Threads
    • Mutex
    • Condition Variables (TODO)
    • NOTE: Implemented using Win32 Threads on Windows and pthread on Linux. (on Linux you need to link pthread to build)
  • Bloom

    • Apply bloom to any tuxtures with just 1 line of code
    • Implementation based of Unity's bloom
    • Custom thresholding
    • Custom downsample/upsample passes
    • Entirely done in Compute Shaders
  • 2D Collision Detection

    • Detect collisions between 2D polygons
    • Generate Seperating Axes for polygons
    • Get Overlap distance
    • GJK (Gilbert–Johnson–Keerthi distance algorithm)
    • EPA (Expanding Polytope Algorithm)
    • SAT (Seperate Axis Theorem)
  • Marching Square

    • Fully Customizablt Marcher
    • Linear Interpolation supported
    • Generates 2D Mesh (Triangles) for CGL
  • Toon Post Processor

    • Outline Effect
    • Toon Shading Effect
    • Hatching Effect
    • All in a single post process call ( no per object calculation)
    • Completely implemented in Compute Shader
    • Customizable
  • CGL Ray Cast

    • Fast 2D Ray Cast
    • Custom Walls
    • Bake to Triangle Mesh
    • Public ray cast functions
  • CGL Node Editor

    • Very fast as its powered by CGL Widgets
    • Custom nodes, pins, links
    • Minimal & Powerful
    • Render your own nodes & links type API
    • Zoom In/Out
    • Global Offsets
  • CGL Audio API

    • Cross Platform (OpenAL backend)
    • Simple API
    • WAV File Loader/Sampler
  • CSV API

    • CSV parser
    • CSV serializer
    • CSV document data structure
  • CGL Widgets (Optional)

    • You can disable it by #define CGL_EXCLUDE_WIDGETS
    • API Like p5.js
    • Text widgets (render high quality crisp text without loading or baking any font)
    • Batch Renderer backend (very fast even for a large number of widgets)
    • draw (filled or stroked) :
      • triangle [CGL_widgets_add_triangle]
      • general quad [CGL_widgets_add_quad]
      • rectangle [CGL_widgets_add_rect CGL_widgets_add_rect2f]
      • line [CGL_widgets_add_line]
      • circle [CGL_widgets_add_circle CGL_widgets_add_circle2f]
      • oval [CGL_widgets_add_oval, CGL_widgets_add_oval2f]
      • arc
    • Plot
      • Scatter plot
      • Bar Graph (vertical/horizontal)
      • Pie Chart
      • Plot a function
    • font based text widgets (load custom font for high quality text rendering with widgets api)
    • Surrport for rendering 3D meshes with widgets API
    • Support for Textures to Widgtes API (efficient)
    • Advanced Bezier Curve( lines or dotted) widget
    • Add individual vertices
    • Adjust stroke color/thickness
    • Customize Batch renderer max vertices capacity (for low memory systems)
  • Math library

    • Advanced Matrix Library (this is seperate from matrix lib for graphics)
      • Linear Algebra for matrixx math
    • vec2/vec3/vec4
    • mat3/mat4 (for graphics)
    • add/sub/mul/div/scale/length/normalize/lerp/min/max/equal for vec2/vec3/vec4
    • rotate_x/rotate_y/rotate_z for vec3
    • scale/translate/rotate_x/rotate_y/rotate_z/add/sub/mul for mat4
    • perspective for mat4
    • transpose for mat4/(mat3 TODO)
    • Rotation Matrices using Goldman's Method
    • look_at matrix
    • Quaternion math
    • Transform vectors
    • NOTE: Most of math functions are implemented via macros so will be totally inclined and quite fast without any unnecessary function calls
  • High Level OpenGL API for (Optional)

    • You can completely disable it by #define CGL_EXCLUDE_GRAPHICS_API
    • Texture (2D / 2D Array / Cube map)
    • Framebuffers
    • SSBO (Shader Storage Buffer Object)
    • UBO (Uniform Buffer Object)
    • Shaders
      • Vertex & Fragment (Geometry Shader not included as its not very widely used)
      • Compute Shader API
  • CGL Mesh API

    • CGL has a high level API for handling meshes
    • 2 types of meshes are there
      • CPU mesh -> stores the data also used for mesh operations like
        • generate triangle
        • generate quad
        • load OBJ (beta)
        • generate cube
        • generate plane
        • generate cylinder
        • generate sphere
        • generate mesh out of any parametric surface function refer here
        • calculate normals
        • perform operation on meshes
          • add 2 meshes
          • offset vertices
          • etc .
      • GPU mesh -> the pointer to the data stored on GPU side (internally handles the Vertex buffer, Index buffer, Vertex Array) and can used for
        • render
        • render instanced
        • render wireframe
        • render wireframe instanced
  • CGL camera

    • CGL provides a proper camera abstraction
    • Perspective & Orthographic
    • It internally handles all matrix calculations (just input the position and rotation)
    • Auto calculates the Up, Right, Front vectors
  • Text Rendering (Optional) (Requires FreeType2)

    • You can completely disable it with #define CGL_EXCLUDE_TEXT_RENDER
    • Load Fonts from .ttf files
    • Bake bitmaps for characters
    • Bake textures from strings
  • Trail Renderer

    • Fast 3D Trail Renderer
    • Bake to mesh
    • Custom Shader support
    • Fully customizable
  • Sky Renderer (Optional)

    • You can completely disable it with #define CGL_EXCLUDE_SKY_RENDERER
    • Supports both a Sky Box (cube mesh) and Sky Sphere/Dome (sphere mesh)
    • Supports Cube map Textured Sky
    • Supports Realtime Procedurally Generated Sky ( + procedural clouds)
    • Render a beautiful sky with just 3 - 5 lines of code
  • Phong Renderer (Optional)

    • You can disable it via #define CGL_EXCLUDE_PHONG_RENDERER
    • It has:
      • Phone Pipeline -> it is the pipeline holding shader data and global engine data. Options available are
        • enable/disable blinn correction
        • enable/disable depth test
        • enable/disable gamma correction
        • setup ambient lighting
        • add/remove lights
      • Phong Light -> It can be of 3 types:
        • Directional -> it takes (direction, color, intensity)
        • Point -> it takes (position, color, itensity, constant, linear, quadratic)
        • Spot (TODO)
      • Phong Material
        • dissuse texture/color
        • specular texture/color
        • shininess
        • normal maps (TODO)
  • Tilemap Renderer (Optional)

    • You can disable it with #define CGL_EXCLUDE_TILEMAP_RENDERER
    • Renders a NxN tilemap with a single line of code
    • Each tile can have following states
      • clear (transparent or disabled)
      • solid color
      • texture -> Texture can be supplied via:
        • texture 2d array -> you need to provide depth for each tile
        • tileset or texture atlas -> you have to provide bounds (normalized 0.0-1.0) of the area of the alas to be used on tile
    • NOTE: this tile render renders only 4 vertices and has only 1 draw call (not a instanced call so its quite fast

Things that are being worked on:

  • PBR renderer (optional)
  • IBL (optional)

Showreels

Checkout out: here

**For more see Examples


cgl's People

Contributors

jaysmito101 avatar s-mackeo avatar shahank42 avatar utkarsh006 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cgl's Issues

update the readme

proper documentation about contribution guidelines and many important points , please assign me under JWOC.

Feature Request: Add HTTP Request/Response Parser

CGL has a basic http request function but the way it parses the requests received is very basic. It needs a proper parser for HTTP requests to parse it into its own data structure.

Relevant CGL functions:

int CGL_net_http_request(const char* method, const char* host, const char* path, void* 
response_buffer, size_t* size, const char* accept, const char* user_agent, const char* body);
int CGL_net_http_get(const char* host, const char* path, void* buffer, size_t* size, const char* accept, const char* user_agent);
int CGL_net_http_post(const char* host, const char* path, void* buffer, size_t* size, const char* accept, const char* user_agent, const char* body);

Bug: SAT collision detection fails on certain edge cases

As the title suggests the SAT collision tests fails on certain close cases specially if the difference of size of 2 polygons is big.

Relevant functions:

bool CGL_sat_collision_overlap_on_axis(CGL_shape* a, CGL_shape* b, CGL_vec2 axis, float* overlap_amount);
bool CGL_sat_collision_detect(CGL_shape* a, CGL_shape* b, CGL_vec2* n_vector);
void CGL_sat_collision_calculate_axes(CGL_shape* shape, CGL_vec2* axes, CGL_int* axes_count);

Update README.md

  • The README file is too large and hard to understand in one go.
  • Will make the file concise and easier to read.
  • Contributing under KWOC'22.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.