From 3922037a9e512d81be901f99d314921ed5a69d7c Mon Sep 17 00:00:00 2001 From: m1ka Date: Sun, 16 Aug 2026 11:30:29 +0200 Subject: [PATCH] Add licensing + fix last memory mgmt issue --- .gitignore | 1 + LICENSE | 19 +++++++++++++++++++ README.md | 20 ++++++++++++++++++++ canvas.c | 14 ++++++++++---- canvas.h | 4 ++++ main.c | 4 ++-- render.c | 2 +- 7 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 LICENSE create mode 100644 README.md diff --git a/.gitignore b/.gitignore index ca1223e3deb9af4fcd063035cbb1fd7b91dc518d..5fde678e746d3be22106f28fe02797c9e9326c35 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /bin /shaders/*.h /compile_commands.json +/.cache diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..fd055fa27fb370a370d7ebadc70c95b8a53fb7ce --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2026 m1kadev + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by: + +(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or + +(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution. + +Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise. + +DISCLAIMER + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0b27a52d125da42e695c7b1c2d6203b28c5a766e --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# sofa - opengl reference code for software rendering + +## Building + +```sh +make baselayout # or mkdir -p {obj,bin} +make engine +# make run +``` + +## Code + +All code is c99 and compiles with `-Wall -Wextra -Werrror -pedantic`; feel free to use this as a +reference for rendering/shaders/makefile/pkgconfig snippets + + +## platforms + +Tested under Darwin (`Darwin chives.local 25.6.0 Darwin Kernel Version 25.6.0: Fri Jul 31 19:11:03 PDT 2026; root:xnu-12377.161.14~5/RELEASE_ARM64_T8132 arm64`). The provided OpenGL is hopefully portable +on any POSIX C99 compiler. diff --git a/canvas.c b/canvas.c index 05449b989bd91e5a144febd0e3530d01e2fb5297..40037da3654292841011b5cbe333b7e33281debb 100644 --- a/canvas.c +++ b/canvas.c @@ -8,13 +8,19 @@ canvas_t canvas_create(GLint w, GLint h) { color_t* data = calloc(w * h, sizeof(color_t)); - for (int i = 0; i < (w*h); i++) { - data[i] = COL_BLUE; - } - return (canvas_t){ .data = data, .w = w, .h = h }; } + +void canvas_clear(canvas_t* self, color_t clear) { + for (int i = 0; i < ( self->w * self->h ); i++) { + self->data[i] = clear; + } +} + +void canvas_destroy(canvas_t* self) { + free(self->data); +} diff --git a/canvas.h b/canvas.h index 7fe3eab4fd7b9b75424916d2a7e66f8de29b8cc1..db99c79bc402e35ec11033767048b20e086630cd 100644 --- a/canvas.h +++ b/canvas.h @@ -14,4 +14,8 @@ typedef struct { canvas_t canvas_create(GLint w, GLint h); +void canvas_clear(canvas_t* self, color_t clear); + +void canvas_destroy(canvas_t* self); + #endif diff --git a/main.c b/main.c index 97145067b286d2690eebc2260e9917fb3211c80e..82aae2b5ff5b6a2e5f9d07e77b42a4a989f0af4c 100644 --- a/main.c +++ b/main.c @@ -10,11 +10,11 @@ int main(void) { renderer_t renderer = renderer_create("Sofa-Engine", 720, 480); canvas_t world = canvas_create(256, 144); + canvas_clear(&world, COL_GREEN); glClearColor(0.392f, 0.584f, 0.929f, 1.0f); int t = 0; - while (renderer_healthy(&renderer)) { t++; t %= 255; @@ -28,8 +28,8 @@ int main(void) { renderer_present(&renderer, &world); } - (void)t; + canvas_destroy(&world); renderer_destroy(&renderer); return 0; diff --git a/render.c b/render.c index bb140062a2e5f489c7afb49d3ef1ab48da993dad..6e4f731907d6f4c8064c285ae684cac31214b996 100644 --- a/render.c +++ b/render.c @@ -22,7 +22,6 @@ char* file_read(const char* path) { buf = malloc(length); if (buf == NULL) return buf; fread(buf, 1, length, f); - fclose(f); return buf; @@ -214,6 +213,7 @@ void renderer_present(const renderer_t* self, const canvas_t* canvas) { } void renderer_destroy(renderer_t* self) { + glDeleteTextures(1, &self->backingTexture); glDeleteProgram(self->shaders); glDeleteBuffers(2, self->bufs); glDeleteVertexArrays(1, &(self->vao));