SDK C API
From Kraytracing Wiki
Contents |
Introduction
Actually we will talk about C++ API. There is a pure_c_wrapper.cpp module that allows to use Kray SDK with pure C. C/C++ function names are the same. C++ functions are methods of Kray object, so you call them like this (load function):
kray.load();
Pure C functions have kray_ prefix instead
kray_load();
For those who like code examples more then reading docs, there are main.cpp and main_c.c in SDK files package that loads Kray lib, sets up simple scene, renders and releases library.
Loading Kray library
To load Kray library use platform independent
char load();
method of kray object. It returns 1 when load succeeds, or 0 when failed (lib not available, or incompatible version). Macro
KRAY_API_VERSION
defines host API version (you can also use getHostApiVersion() function in C++). To check library version (works only after successful load). Call:
int getLibApiVersion();
Setting up scene
Scene setup is done with series of kray.parse() calls. It takes Kray script command as its parameters. Example:
kray.parse("echo 'Hello world!';");
Since parsing script can be time consuming. Often called functions (like adding a poly to a scene) have direct C interface. For details see Kray script reference.
Rendering
Releasing library
In C you need to call:
kray_release();
In C++ you can call
kray.release();
or kray object destructor will do it for you.
