Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inochi2d/inochi2d-c
A layer for using Inochi2D with non-D programming languages via a C ABI
https://github.com/inochi2d/inochi2d-c
Last synced: about 2 months ago
JSON representation
A layer for using Inochi2D with non-D programming languages via a C ABI
- Host: GitHub
- URL: https://github.com/inochi2d/inochi2d-c
- Owner: Inochi2D
- License: bsd-2-clause
- Created: 2022-07-01T21:40:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-16T13:12:36.000Z (over 1 year ago)
- Last Synced: 2023-07-16T13:55:24.246Z (over 1 year ago)
- Language: D
- Size: 32.2 KB
- Stars: 12
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Inochi2D SDK for C ABIs
This repository contains the neccesary code to use the reference Inochi2D implementation outside of DLang, as well as with non-Inochi2D renderers.## Initializing and Closing Inochi2D
You will need to pass a function with the signature `double timingFunc()` to Inochi2D on initialization.
* timingFunc should return the current time of the application rendering the game in `sec.ms` format.
* timingFunc is used for physics as well animation calculations```c
double timingFunc() {
return glfwGetTime();
}
```To initialize Inochi2D itself you will need to call `inInit` passing your timing function in.
Remember to run inCleanup when you're done using Inochi2D to unload the DLang runtime!```c
inInit(&timingFunc);
// Game and Inochi2D goodness happens here
inCleanup();
```## Loading a puppet
Use `inLoadPuppet` to load a puppet, you will need to pass an UTF-8 encoded null-terminated string to this function.
Use `inDestroyPuppet` to destroy a puppet when it no longer is needed.```c
InPuppet* puppet = inLoadPuppet("myPuppet.inp");
// Do stuffinDestroyPuppet(puppet);
```## Getting arrays from Inochi2D
Such functions take arguments including two: `Type** arr_ptr, size_t* len_ptr`:
0) If arr_ptr == null, length is written into `*len_ptr`. End.
1) If *arr_ptr == null, an array allocated by D is written into `*arr_ptr`.
2) Otherwise, fill the buffer passed by 'arr_ptr' with length.User can use these in following way.
0) D manages the memory: Call function with `*arr_ptr==NULL`.
1) C manages the memory:
1) call function with `arr_ptr==NULL`. function returns length of the buffer.
2) call function with array pre-allocated (`*buff != NULL`) given the length. function fills values to provided array.
Example:```c
struct {
size_t len;
InParameter **cont;
} parameters;
// let D allocate memory
parameters.cont = NULL;
inPuppetGetParameters(myPuppet, ¶meters.cont, ¶meters.len);
for (size_t i = 0; i < parameters.len; i++) {
char *name = inParameterGetName(parameters.cont[i]);
bool isVec2 = inParameterIsVec2(parameters.cont[i]);
printf("Parameter #%zu: %s is%s vec2.\n", i, name, isVec2 ? "" : " not");
}
```## Using Inochi2D with your own renderer
Inochi2D requires the following GPU accellerated features to be present:
* Framebuffer support (Inochi2D needs 2)
* sRGB->Linear RGB conversion support
* Premultiplied Alpha support
* Vertex buffers
* Stencil buffers
* Pixel shaders
* ROP support or method to emulate porter-duff blending in shader
* At least 4096x4096 texture resolution supportOptionally the following features may be present
* SPIR-v shader support (For per-part shaders)