46 #if defined(USEOPENGL) 55 int ray(
int argc,
char **argv);
62 #if !defined(TACHYON_JNI_CLASSNAME) 63 #define TACHYON_JNI_CLASSNAME "com/photonlimited/Tachyon/Tachyon" 65 #if !defined(TACHYON_JNI_WRAPFUNC) 66 #define TACHYON_JNI_WRAPFUNC Java_com_photonlimited_Tachyon_Tachyon_nativeMain 69 void logtojava(JNIEnv *env, jobject thiz,
const char *logstring) {
72 jclass clazz = (*env)->FindClass(env, TACHYON_JNI_CLASSNAME);
74 jmethodID logOutput = (*env)->GetMethodID(env, clazz,
"logOutput",
75 "(Ljava/lang/String;)V");
78 (*env)->CallVoidMethod(env, thiz, logOutput, (*env)->NewStringUTF(env, logstring));
81 jclass clazz = (env)->FindClass(TACHYON_JNI_CLASSNAME);
82 jmethodID logOutput = (env)->GetMethodID(clazz,
"logOutput",
83 "(Ljava/lang/String;)V");
86 (env)->CallVoidMethod(thiz, logOutput, (env)->NewStringUTF(logstring));
91 JNIEnv *global_jnienv;
98 void TACHYON_JNI_WRAPFUNC(JNIEnv* env, jobject thiz ) {
104 fprintf(stderr,
"--stderr fprintf---------------------------------\n");
105 printf(
"---regular printf----------------------------\n");
107 logtojava(global_jnienv, global_thiz,
"--Log event ---------------------\n");
110 printf(
"Android platform info:\n");
111 printf(
" sizeof(char): %d\n",
sizeof(
char));
112 printf(
" sizeof(int): %d\n",
sizeof(
int));
113 printf(
" sizeof(long): %d\n",
sizeof(
long));
114 printf(
" sizeof(void*): %d\n",
sizeof(
void*));
118 rargv[0] =
"tachyon.so";
119 rargv[1] =
"/sdcard/balls.dat";
121 rargv[3] =
"/sdcard/outfile.tga";
127 logtojava(global_jnienv, global_thiz,
"--Log event ---------------------\n");
128 fprintf(stderr,
"--stderr fprintf---------------------------------\n");
129 printf(
"---regular printf----------------------------\n");
135 strncpy(logstring, msg,
sizeof(logstring)-2);
136 strcat(logstring,
"\n");
138 logtojava(global_jnienv, global_thiz, logstring);
142 logtojava(global_jnienv, global_thiz,
".");
144 printf(
"\rRendering Progress: %3d%% complete \r", percent);
159 printf(
"\rRendering Progress: %3d%% complete \r", percent);
167 #if defined(USEOPENGL) 171 static int tachyon_display_reshape(
dispHandle *dh) {
172 float wscalex, wscaley, wminscale;
173 float wxoffset, wyoffset;
174 int wsx, wsy, instereo, maxx, maxy;
180 wscalex = wsx / (float) maxx;
181 wscaley = wsy / (float) maxy;
182 wminscale = (wscalex < wscaley) ? wscalex : wscaley;
183 wxoffset = ((wminscale * maxx) - wsx) / 2.0f;
184 wyoffset = ((wminscale * maxy) - wsy) / 2.0f;
186 glDrawBuffer(GL_BACK);
187 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
188 glClearColor(0.0, 0.0, 0.0, 1.0);
189 glViewport(0, 0, wsx, wsy);
190 glClear(GL_COLOR_BUFFER_BIT);
192 glShadeModel(GL_FLAT);
193 glViewport((
int) -wxoffset, (
int) -wyoffset, wsx, wsy);
194 glMatrixMode(GL_PROJECTION);
196 glOrtho(0.0, wsx, 0.0, wsy, -1.0, 1.0);
198 glMatrixMode(GL_MODELVIEW);
199 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
200 glPixelZoom(wminscale, wminscale);
218 #if defined(USEOPENGL) 219 dh->img = (
unsigned char *) malloc((dh->
xsize)*(dh->
ysize)*3);
220 if (dh->img != NULL) {
224 tachyon_display_reshape(dh);
226 printf(
"Couldn't allocate image buffer for framebuffer display!!\n");
238 #if defined(USEOPENGL) 239 if (dh->img != NULL) {
244 int wsx, wsy, instereo;
262 printf(
"Toggling fullscreen mode %s...\n",
263 (dh->
fson) ?
"on" :
"off");
265 printf(
"Fullscreen mode not available...\n");
271 printf(
"ignored keypress %0x: '%c'\n",
272 evkey, (isalnum(evkey)) ? evkey :
'\0');
278 tachyon_display_reshape(dh);
288 dh->img = (
unsigned char *) calloc(1, dh->
xsize*dh->
ysize*3);
292 tachyon_display_reshape(dh);
298 dh->img = (
unsigned char *) calloc(1, wsx*wsy*3);
303 tachyon_display_reshape(dh);
310 dh->img = (
unsigned char *) calloc(1, dh->
xsize*dh->
ysize*3);
314 tachyon_display_reshape(dh);
321 dh->img = (
unsigned char *) calloc(1, dh->
xsize*dh->
ysize*3);
325 tachyon_display_reshape(dh);
332 dh->img = (
unsigned char *) calloc(1, dh->
xsize*dh->
ysize*3);
336 tachyon_display_reshape(dh);
343 dh->img = (
unsigned char *) calloc(1, dh->
xsize*dh->
ysize*3);
347 tachyon_display_reshape(dh);
362 #if defined(USEOPENGL) 363 if (dh->img != NULL) {
380 float fpsexpave = 0.0f;
384 #if defined(USEOPENGL) 390 #if defined(USEOPENGL) 399 printf(
"Interactive Camera Flight\n");
401 outfilename[0] =
'\0';
407 #if defined(USEOPENGL) 415 printf(
"WARNING: Spaceball mode disabled when running with distributed memory");
421 #if defined(RT_ACCUMULATE_ON) 435 fpsexpave = (fpsexpave * 0.90f) + (fps * 0.10f);
439 printf(
"\rRendering Frame: %9d %.1f FPS ", frameno, fpsexpave);
443 #if defined(USEOPENGL) 462 printf(
"\rCompleted animation of %d frames \n", frameno);
463 printf(
"Animation Time: %10.4f seconds (Averaged %.1f FPS)\n",
469 printf(
"\nFinished Running Camera.\n");
487 char outfilename[1000];
493 #if defined(USEOPENGL) 499 if ((camfp = fopen(opt.
camfilename,
"r")) != NULL) {
512 printf(
"Running Camera File: %s\n", opt.
camfilename);
519 while (!feof(camfp) && !done) {
520 fscanf(camfp,
"%f %f %f %f %f %f %f %f %f",
521 &cv.
x, &cv.
y, &cv.
z, &cu.
x, &cu.
y, &cu.
z, &cc.
x, &cc.
y, &cc.
z);
523 cmv.
x = cv.
x; cmv.
y = cv.
y; cmv.
z = cv.
z;
524 cmu.
x = cu.
x; cmu.
y = cu.
y; cmu.
z = cu.
z;
525 cmc.
x = cc.
x; cmc.
y = cc.
y; cmc.
z = cc.
z;
535 outfilename[0] =
'\0';
538 printf(
"\rRendering Frame: %9d %.1f FPS ", frameno, fps);
544 printf(
"\rRendering Frame to %s (%.1f FPS) ", outfilename, fps);
565 printf(
"\rCompleted animation of %d frames \n", frameno);
566 printf(
"Animation Time: %10.4f seconds (Averaged %.1f FPS)\n",
573 printf(
"Couldn't open camera file: %s\n", opt.
camfilename);
574 printf(
"Aborting render.\n");
582 printf(
"\nFinished Running Camera.\n");
597 #if defined(ANDROID) || defined(VXWORKS) 598 int ray(
int argc,
char **argv) {
600 int main(
int argc,
char **argv) {
617 sprintf(strbuf,
"Tachyon Parallel/Multiprocessor Ray Tracer Version %s ",
620 sprintf(strbuf,
"Copyright 1994-2022, John E. Stone <john.stone@gmail.com> ");
622 sprintf(strbuf,
"------------------------------------------------------------ ");
626 if ((rc =
getargs(argc, argv, &opt, node)) != 0) {
637 printf(
"Rendering %d scene files.\n", opt.
numfiles);
640 for (fileindex=0; fileindex<opt.
numfiles; fileindex++) {
650 printf(
"\nRendering scene file %d of %d, %s\n", fileindex+1, opt.
numfiles, filename);
656 len = strlen(filename);
658 if (len > 4 && (!strcmp(filename+len-4,
".nff") ||
659 !strcmp(filename+len-4,
".NFF"))) {
662 else if (len > 3 && (!strcmp(filename+len-3,
".ac") ||
663 !strcmp(filename+len-3,
".AC"))) {
667 else if (len > 4 && (!strcmp(filename+len-4,
".mgf") ||
668 !strcmp(filename+len-4,
".MGF"))) {
678 printf(
"Scene Parsing Time: %10.4f seconds\n",
rt_timer_time(parsetimer));
684 printf(
"Parser failed due to nonexistent input file: %s\n", filename);
687 printf(
"Parser failed due to nonexistent included file.\n");
690 printf(
"Parser failed due to an input file syntax error.\n");
693 printf(
"Parser unexpectedly hit an end of file.\n");
696 printf(
"Parser ran out of memory.\n");
700 printf(
"Aborting render, continuing with next scene file...\n");
702 printf(
"Aborting render.\n");
718 char multioutfilename[FILENAME_MAX];
719 sprintf(multioutfilename, opt.
outfilename, fileindex);
unsigned int ParseAC3D(char *modelfile, SceneHandle scene)
int glwin_get_lastevent(void *voidhandle, int *evdev, int *evval, char *evkey)
void * glwin_create(const char *wintitle, int width, int height)
double rt_timer_time(rt_timerhandle v)
static int animate_scene(argoptions opt, SceneHandle scene, int node)
void rt_timer_destroy(rt_timerhandle v)
void rt_resolution(SceneHandle voidscene, int hres, int vres)
Set the horizontal and vertical resolution (in pixels) for the specified scene.
void glwin_destroy(void *voidhandle)
int tachyon_spaceball_update(sbHandle *bh, SceneHandle scene)
int glwin_handle_events(void *voidhandle, int evblockmode)
void rt_accumulation_mode(SceneHandle voidscene, int mode)
Request Tachyon to use (or disuse) an internal floating point accumulation buffer, combining the newest frame with previously accumulated frames, normalizing the pixel values using an internal subframe counter.
void rt_timer_start(rt_timerhandle v)
char camfilename[FILENAME_MAX]
camera filename
void glwin_draw_image(void *voidhandle, int xsize, int ysize, unsigned char *img)
char ** filenames
list of model files to render
void freeoptions(argoptions *opt)
unsigned int ParseMGF(char *mgfname, SceneHandle scene, int defaultflag)
char spaceballport[FILENAME_MAX]
spaceball serial port device
void rt_timer_stop(rt_timerhandle v)
void rt_renderscene(SceneHandle voidscene)
Render the current scene.
#define RT_ACCUMULATE_ON
accum.
void * tachyon_init_spaceball(SceneHandle scene, void *glwin, char *serialport)
unsigned int readmodel(const char *modelfile, SceneHandle scene)
int nosave
don't write output image to disk
#define GLWIN_EV_POLL_NONBLOCK
int glwin_get_winsize(void *voidhandle, int *xsize, int *ysize)
static dispHandle * tachyon_display_create(SceneHandle scene)
int rt_initialize(int *argc, char ***argv)
Initialize Tachyon library, must be first Tachyon API called.
flt x
X coordinate or direction component.
#define TACHYON_VERSION_STRING
string version info
static void tachyon_display_delete(dispHandle *dh)
int glwin_fullscreen(void *voidhandle, int fson, int xinescreen)
int numfiles
number of files to render
flt y
Y coordinate or direction component.
int rt_numnodes(void)
distributed memory parallel node count
SceneHandle rt_newscene(void)
Allocate, initialize, and return a handle for a new scene.
char outfilename[FILENAME_MAX]
name of output image file
void rt_rawimage_rgb24(SceneHandle voidscene, unsigned char *img)
Have Tachyon save the output image in the specified memory area, in raw 24-bit, packed, pixel interleaved, unsigned RGB bytes.
void rt_outputfile(SceneHandle voidscene, const char *outname)
Set the filename for the output image for the specified scene.
void rt_set_ui_message(void(*func)(int, char *))
Set function pointer for user interface output callbacks.
static int tachyon_display_draw(SceneHandle scene, dispHandle *dh)
void rt_set_ui_progress(void(*func)(int))
Set function pointer for user interface progress callbacks.
static void my_ui_message(int a, char *msg)
#define GLWIN_EV_KBD
all non-special chars
void rt_deletescene(SceneHandle voidscene)
Destroy and deallocate the specified scene.
int postsceneoptions(argoptions *opt, SceneHandle scene)
static void my_ui_progress(int percent)
int presceneoptions(argoptions *opt, SceneHandle scene)
static int fly_scene(argoptions opt, SceneHandle scene, int node)
void rt_finalize(void)
Shut down Tachyon library for good, at final use before program termination.
int glwin_resize(void *voidhandle, int width, int height)
int usecamfile
use camera file
int spaceballon
spaceball input enabled
unsigned int ParseNFF(char *nffname, SceneHandle scene)
rt_timerhandle rt_timer_create(void)
void rt_get_resolution(SceneHandle voidscene, int *hres, int *vres)
Get the horizontal and vertical resolution (in pixels) for the specified scene.
void rt_camera_position(SceneHandle voidscene, apivector camcent, apivector viewvec, apivector upvec)
Set camera position and orientation.
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
int getargs(int argc, char **argv, argoptions *opt, int node)
int glwin_get_wininfo(void *voidhandle, int *instereo, int *havestencil)
flt z
Z coordinate or direction component.
int main(int argc, char **argv)