{"id":30446969,"url":"https://github.com/nickscha/csr","last_synced_at":"2025-08-23T11:20:35.758Z","repository":{"id":310712131,"uuid":"1040943367","full_name":"nickscha/csr","owner":"nickscha","description":"C89, single header, nostdlib software renderer","archived":false,"fork":false,"pushed_at":"2025-08-19T19:27:30.000Z","size":868,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-19T20:39:53.605Z","etag":null,"topics":["3d-graphics","c89","nostdlib","single-header","software-renderer"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nickscha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-19T18:32:52.000Z","updated_at":"2025-08-19T19:56:54.000Z","dependencies_parsed_at":"2025-08-19T20:39:55.714Z","dependency_job_id":"c23902cb-b49f-498b-95a3-653793ebbd15","html_url":"https://github.com/nickscha/csr","commit_stats":null,"previous_names":["nickscha/csr"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/nickscha/csr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fcsr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fcsr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fcsr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fcsr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nickscha","download_url":"https://codeload.github.com/nickscha/csr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickscha%2Fcsr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271746793,"owners_count":24813586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d-graphics","c89","nostdlib","single-header","software-renderer"],"created_at":"2025-08-23T11:20:31.152Z","updated_at":"2025-08-23T11:20:35.749Z","avatar_url":"https://github.com/nickscha.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# csr\nA C89 standard compliant, single header, nostdlib (no C Standard Library) software renderer (CSR).\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/nickscha/csr\"\u003e\u003cimg src=\"assets/csr.png\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nFor more information please look at the \"csr.h\" file or take a look at the \"examples\" or \"tests\" folder.\n\n\u003e [!WARNING]\n\u003e THIS PROJECT IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! USE THIS PROJECT AT YOUR OWN RISK!\n\n\u003ca href=\"https://github.com/nickscha/csr\"\u003e\u003cimg src=\"assets/csr_voxel_head.gif\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/nickscha/csr\"\u003e\u003cimg src=\"assets/csr.gif\"\u003e\u003c/a\u003e\n\n## Quick Start\n\nDownload or clone csr.h and include it in your project.\n\n```C\n#include \"csr.h\" /* C Software Renderer                                  */\n#include \"vm.h\"  /* Linear Algebra Math library. Any library can be used */\n\nint main() {\n\n    /* Vertex data array with interleaved position and color (RGB) */\n    float vertices[] = {\n        /* Position x,y,z  | Color r,g,b */\n        -0.5f, -0.5f,  0.5f, 255.0f,   0.0f,   0.0f, /* 0: Red     */\n         0.5f, -0.5f,  0.5f,   0.0f, 255.0f,   0.0f, /* 1: Green   */\n         0.5f,  0.5f,  0.5f,   0.0f,   0.0f, 255.0f, /* 2: Blue    */\n        -0.5f,  0.5f,  0.5f, 255.0f, 255.0f,   0.0f, /* 3: Yellow  */\n        -0.5f, -0.5f, -0.5f, 255.0f,   0.0f, 255.0f, /* 4: Magenta */\n         0.5f, -0.5f, -0.5f,   0.0f, 255.0f, 255.0f, /* 5: Cyan    */\n         0.5f,  0.5f, -0.5f, 255.0f, 255.0f, 255.0f, /* 6: White   */\n        -0.5f,  0.5f, -0.5f, 128.0f, 128.0f, 128.0f  /* 7: Gray    */\n    };\n\n    /* Index data counterclockwise to form the triangles of a cube.  */\n    int indices[] = {\n        0, 3, 2, 0, 2, 1, /* Front face (+z normal, facing camera)   */\n        4, 5, 6, 4, 6, 7, /* Back face (-z normal, away from camera) */\n        3, 7, 6, 3, 6, 2, /* Top face (+y normal)                    */\n        0, 1, 5, 0, 5, 4, /* Bottom face (-y normal)                 */\n        1, 2, 6, 1, 6, 5, /* Right face (+x normal)                  */\n        0, 4, 7, 0, 7, 3  /* Left face (-x normal)                   */\n    };\n\n    unsigned long vertices_size = sizeof(vertices) / sizeof(vertices[0]);\n    unsigned long indices_size  = sizeof(indices)  / sizeof(indices[0]);\n\n    /* Define the render area */\n    #define WIDTH 400\n    #define HEIGHT 300\n\n    /* In this example we can fit everything on the stack! \n\n       For larger render areas you can allocate a block of memory like this:\n\n       unsigned long memory_size = csr_memory_size(width, height);\n       void *memory = your_memory_allocation_function(memory_size);\n    */\n    #define MEMORY_SIZE (WIDTH * HEIGHT * sizeof(csr_color)) + (WIDTH * HEIGHT * sizeof(float))\n    unsigned char memory_total[MEMORY_SIZE] = {0};\n    void *memory = (void *)memory_total;\n\n    csr_color clear_color = {40, 40, 40};\n    csr_context instance = {0};\n\n    if (!csr_init_model(\u0026instance, memory, MEMORY_SIZE, WIDTH, HEIGHT, clear_color))\n    {\n        return 1;\n    }\n\n    {\n        /* CSR does not force you to a specific linear algebra vector math library!\n           For demonstration use we use the \"vm.h\" library you can also find in the tests folder.\n        */\n        v3 world_up          = vm_v3(0.0f, 1.0f, 0.0f);\n        v3 cam_position      = vm_v3(0.0f, 0.0f, 2.0f);\n        v3 cam_look_at_pos   = vm_v3_zero;\n        float cam_fov        = 90.0f;\n\n        m4x4 projection      = vm_m4x4_perspective(vm_radf(cam_fov), (float)instance.width / (float)instance.height, 0.1f, 1000.0f);\n        m4x4 view            = vm_m4x4_lookAt(cam_position, cam_look_at_pos, world_up);\n        m4x4 projection_view = vm_m4x4_mul(projection, view);\n\n        m4x4 model_base      = vm_m4x4_translate(vm_m4x4_identity, vm_v3_zero);\n        v3 model_rotation    = vm_v3(0.5f, 1.0f, 0.0);\n\n        int frame;\n\n        for (frame = 0; frame \u003c 10; ++frame)\n        {   \n            /* Rotate the cube around the model_rotation axis */\n            m4x4 model_view_projection = vm_m4x4_mul(\n                projection_view, \n                vm_m4x4_rotate(model_base, vm_radf(5.0f * (float)(frame + 1)), model_rotation)\n            );\n\n            /* Clear Screen Frame and Depth Buffer */\n            csr_clear_screen(\u0026instance);                                                                   \n\n            /* Render cube */ \n            csr_render(\n                \u0026instance, \n                CSR_RENDER_SOLID, \n                CSR_CULLING_CCW_BACKFACE, 6, \n                vertices, vertices_size, \n                indices, indices_size, \n                model_view_projection.e\n            );\n\n            /* Afterwards you can write the instance.framebuffer to a screen or write to a file (like ppm format).\n            \n               In the csr_test.c file we write each frame into a ppm file\n               and then using ffmpeg (via the build.bat script) to generate a mp4 and gif file.\n            */\n        }\n    }\n\n    return 0;\n}\n```\n\n### Switch Row/Column major layout\nBy default the m4x4 (Matrix 4x4) uses a **column major** order for storing data (used by OpenGL).\nIf you want to change to a row major order you can use the following define before including the header.\n\n```C\n#define CSR_M4X4_ROW_MAJOR_ORDER\n#include \"csr.h\"\n```\n\n## Run Example: nostdlib, freestsanding\n\nIn this repo you will find the \"examples/csr_win32_nostdlib.c\" with the corresponding \"build.bat\" file which\ncreates an executable only linked to \"kernel32\" and is not using the C standard library and executes the program afterwards.\n\n## \"nostdlib\" Motivation \u0026 Purpose\n\nnostdlib is a lightweight, minimalistic approach to C development that removes dependencies on the standard library. The motivation behind this project is to provide developers with greater control over their code by eliminating unnecessary overhead, reducing binary size, and enabling deployment in resource-constrained environments.\n\nMany modern development environments rely heavily on the standard library, which, while convenient, introduces unnecessary bloat, security risks, and unpredictable dependencies. nostdlib aims to give developers fine-grained control over memory management, execution flow, and system calls by working directly with the underlying platform.\n\n### Benefits\n\n#### Minimal overhead\nBy removing the standard library, nostdlib significantly reduces runtime overhead, allowing for faster execution and smaller binary sizes.\n\n#### Increased security\nStandard libraries often include unnecessary functions that increase the attack surface of an application. nostdlib mitigates security risks by removing unused and potentially vulnerable components.\n\n#### Reduced binary size\nWithout linking to the standard library, binaries are smaller, making them ideal for embedded systems, bootloaders, and operating systems where storage is limited.\n\n#### Enhanced performance\nDirect control over system calls and memory management leads to performance gains by eliminating abstraction layers imposed by standard libraries.\n\n#### Better portability\nBy relying only on fundamental system interfaces, nostdlib allows for easier porting across different platforms without worrying about standard library availability.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickscha%2Fcsr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnickscha%2Fcsr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickscha%2Fcsr/lists"}