int main(int argc, char *argv[]) { int err = 0; int frames = 0; time_t start = 0; time_t stop = 0; EON_Light *light; EON_Obj *model; EON_Mat *material; EON_Cam *camera; EON_Rend *rend; EON_Frame *frame; EONx_Console *console; EONViewer view; view.logger = CX_log_open_console(CX_LOG_MARK, stderr); opts_Defaults(&view.opts); err = opts_Parse(&view.opts, argc, argv); if (err) { return opts_ErrCode(err); } CX_log_trace(view.logger, CX_LOG_INFO, EXE, "Shading mode: %s", shade_ModeToStr(view.opts.shade)); CX_log_trace(view.logger, CX_LOG_INFO, EXE, "Frame Size: %ix%i", view.opts.width, view.opts.height); CX_log_trace(view.logger, CX_LOG_INFO, EXE, "Model rotation: X=%f Y=%f Z=%f", view.opts.rx, view.opts.ry, view.opts.rz); EONx_ConsoleStartup("Eon3D Model Viewer", NULL); material = EON_MatCreate(); material->ShadeType = view.opts.shade; material->Ambient.R = 200; material->Ambient.G = 200; material->Ambient.B = 200; EON_MatInit(material); EON_MatInfo(material, view.logger); console = EONx_ConsoleCreate(view.opts.width, view.opts.height, 90); EONx_ConsoleBindEventKey(console, 's', onkey_Screenshot, &view); // XXX EONx_ConsoleBindEventKey(console, 'q', onkey_Quit, &view); // XXX model = EONx_ReadPLYObj(view.opts.filename, material); EON_ObjInfo(model, view.logger); frame = EONx_ConsoleGetFrame(console); camera = EONx_ConsoleGetCamera(console); camera->Pos.Z = -view.opts.distance; light = EON_LightNew(EON_LIGHT_VECTOR, 0.0, 0.0, 0.0, 1.0, 1.0); rend = EON_RendCreate(camera); start = time(NULL); while (!EONx_ConsoleNextEvent(console)) { model->Xa += view.opts.rx; model->Ya += view.opts.ry; model->Za += view.opts.rz; EONx_ConsoleClearFrame(console); EON_RenderBegin(rend); EON_RenderLight(rend, light); EON_RenderObj(rend, model); EON_RenderEnd(rend, frame); EONx_ConsoleShowFrame(console); frames++; } stop = time(NULL); CX_log_trace(view.logger, CX_LOG_INFO, EXE, "%i frames in %f seconds: %.3f FPS\n", frames, (double)stop-(double)start, (double)frames/((double)stop-(double)start)); return EONx_ConsoleShutdown(); }
int main(int argc, char *argv[]) { int frames = 0; EON_Mat *mat[3]; EON_Cam *cam; EON_Obj *land; EON_Obj *sky, *sky2; Landscape ls; EONx_Console *con; EON_Rend *rend; EON_Frame *frame; EON_Font *font; uint64_t ts = 0; CX_LogContext *Logger = CX_log_open_console(CX_LOG_MARK, stderr); srand(0); // initialize prng EONx_ConsoleStartup("Eon3D :: Fly v1.1", NULL); con = EONx_ConsoleCreate(800, // Screen width 600, // Screen height 90.0 // Field of view ); frame = EONx_ConsoleGetFrame(con); cam = EONx_ConsoleGetCamera(con); rend = EON_RendCreate(cam); cam->Pos.Y = 800; // move the camera up from the ground font = EON_TextDefaultFont(); setup_materials(con, mat, Logger); // intialize materials and palette memset(&ls, 0, sizeof(ls)); setup_landscape(&ls, mat[0],mat[1],mat[2]); // create landscape land = ls.land; sky = ls.sky; sky2 = ls.sky2; EON_ObjInfo(land, Logger); EON_ObjInfo(sky, Logger); EON_ObjInfo(sky2, Logger); frames = 0; // set up for framerate counter ts = eon_gettime_ms(); while (!EONx_ConsoleNextEvent(con)) { // save time when the frame began, to be used later. uint64_t elapsed = 0; frames++; cam->Pos.Z += 1; EONx_ConsoleClearFrame(con); if (cam->Pos.Y > 2000) { // if above the sky, only render the skies, with no far clip plane cam->ClipBack = 0.0; EON_RenderBegin(rend); EON_RenderObj(rend, sky); EON_RenderObj(rend, sky2); } else { // otherwise, render the sky (but not the second sky), // and the land, with a far clip plane cam->ClipBack = 10000.0; EON_RenderBegin(rend); EON_RenderObj(rend, sky); EON_RenderObj(rend, land); } EON_RenderEnd(rend, frame); elapsed = (eon_gettime_ms() - ts) / 1000000; EON_TextPrintf(font, cam, frame, cam->ClipLeft+5, cam->ClipTop, 0.0, "%.3f FPS", (frames/ (double) elapsed)); EONx_ConsoleShowFrame(con); // wraparound if (cam->Pos.X > LAND_SIZE/2) cam->Pos.X = -LAND_SIZE/2; if (cam->Pos.X < -LAND_SIZE/2) cam->Pos.X = LAND_SIZE/2; if (cam->Pos.Z > LAND_SIZE/2) cam->Pos.Z = -LAND_SIZE/2; if (cam->Pos.Z < -LAND_SIZE/2) cam->Pos.Z = LAND_SIZE/2; if (cam->Pos.Y < 0 ) cam->Pos.Y = 8999; if (cam->Pos.Y > 8999 ) cam->Pos.Y = 0; } EON_FontDelete(font); EON_ObjDelete(land); EON_ObjDelete(sky); EON_ObjDelete(sky2); EON_MatDelete(mat[0]); EON_MatDelete(mat[1]); EON_MatDelete(mat[2]); EONx_ConsoleShutdown(); return CX_log_close(Logger); }
int main(int argc, char *argv[]) { int err = 0; int frames = 0; time_t start = 0; time_t stop = 0; EONLandGen lgen; EONx_Console *con; EON_Cam *cam; EON_Rend *rend; EON_Frame *frame; EON_Font *font; uint64_t ts = 0; lgen.logger = CX_log_open_console(CX_LOG_MARK, stderr); opts_Defaults(&lgen.opts); err = opts_Parse(&lgen.opts, argc, argv); if (err) { return opts_ErrCode(err); } if (lgen.opts.seed == 0) { lgen.opts.seed = time(0); } CX_log_trace(lgen.logger, CX_LOG_INFO, EXE, "Frame Size: %ix%i", lgen.opts.width, lgen.opts.height); CX_log_trace(lgen.logger, CX_LOG_INFO, EXE, "Generation Seed: %i", lgen.opts.seed); srand(lgen.opts.seed); EONx_ConsoleStartup("Eon3D Land Generator", NULL); con = EONx_ConsoleCreate(lgen.opts.width, lgen.opts.height, 90); EONx_ConsoleBindEventKey(con, 's', onkey_Screenshot, &lgen); // XXX EONx_ConsoleBindEventKey(con, 'q', onkey_Quit, &lgen); // XXX frame = EONx_ConsoleGetFrame(con); cam = EONx_ConsoleGetCamera(con); rend = EON_RendCreate(cam); cam->Pos.Y = 800; // move the camera up from the ground font = EON_TextDefaultFont(); world_setupLandscape(&lgen.world, lgen.logger); // create landscape ts = eon_gettime_ms(); while (!EONx_ConsoleNextEvent(con)) { // save time when the frame began, to be used later. uint64_t elapsed = 0; frames++; cam->Pos.Z += 1; EONx_ConsoleClearFrame(con); // otherwise, render the sky (but not the second sky), // and the land, with a far clip plane cam->ClipBack = 10000.0; EON_RenderBegin(rend); EON_RenderObj(rend, lgen.world.sky); EON_RenderObj(rend, lgen.world.land); EON_RenderEnd(rend, frame); elapsed = (eon_gettime_ms() - ts) / 1000000; EON_TextPrintf(font, cam, frame, cam->ClipLeft+5, cam->ClipTop, 0.0, "%.3f FPS", (frames/ (double) elapsed)); EONx_ConsoleShowFrame(con); // wraparound if (cam->Pos.X > LAND_SIZE/2) cam->Pos.X = -LAND_SIZE/2; if (cam->Pos.X < -LAND_SIZE/2) cam->Pos.X = LAND_SIZE/2; if (cam->Pos.Z > LAND_SIZE/2) cam->Pos.Z = -LAND_SIZE/2; if (cam->Pos.Z < -LAND_SIZE/2) cam->Pos.Z = LAND_SIZE/2; if (cam->Pos.Y < 0 ) cam->Pos.Y = 8999; if (cam->Pos.Y > 8999 ) cam->Pos.Y = 0; } CX_log_trace(lgen.logger, CX_LOG_INFO, EXE, "%i frames in %f seconds: %.3f FPS\n", frames, (double)stop-(double)start, (double)frames/((double)stop-(double)start)); world_cleanLandscape(&lgen.world); EON_FontDelete(font); EONx_ConsoleShutdown(); return CX_log_close(lgen.logger); }
int main(int argc, char *argv[]) { const char *filename; int frames = 0; int framenum = 100000; time_t start = 0, stop = 0; // Our variables EON_Light *TheLight; // Our light EON_Mesh *TheModel; // Our cube object EON_Mat *ModelMat; // The material for the cube EON_Cam *TheCamera; EON_Rend *TheRend; EON_Frame *TheFrame; NullConsole *TheConsole; double distance = 50; int ch = -1; int verbose = 1; CX_LogContext *Logger = CX_log_open_console(CX_LOG_MARK, stderr); while (1) { ch = getopt(argc, argv, "d:n:v:h?"); if (ch == -1) { break; } switch (ch) { case 'd': distance = atof(optarg); break; case 'n': framenum = atoi(optarg); break; case 'v': verbose = atoi(optarg); break; case '?': /* fallthrough */ case 'h': /* fallthrough */ default: usage(); return 0; } } /* XXX: watch out here */ argc -= optind; argv += optind; if (argc != 1) { usage(); return 1; } filename = argv[0]; if (verbose) { CX_log_trace(Logger, CX_LOG_INFO, EXE, "settings> rendering model = %s", filename); CX_log_trace(Logger, CX_LOG_INFO, EXE, "settings> frame limit = %i", framenum); } ModelMat = EON_MatCreate(); ModelMat->ShadeType = EON_SHADE_FLAT; ModelMat->Ambient.R = 216; ModelMat->Ambient.G = 216; ModelMat->Ambient.B = 216; EON_MatInit(ModelMat); EON_MatInfo(ModelMat, Logger); TheConsole = NullConsoleCreate(800, // Screen width 600 // Screen height ); TheModel = EONx_ReadPLYMesh(filename, ModelMat); if (TheModel == NULL) { CX_log_trace(Logger, CX_LOG_ERROR, EXE, "failed to load model '%s', aborting", filename); return 1; } EON_MeshInfo(TheModel, Logger); TheFrame = TheConsole->fb; TheCamera = TheConsole->cam; TheCamera->Pos.Z = -distance; // Back the camera up from the origin TheLight = EON_LightNew(EON_LIGHT_VECTOR, // vector light 0.0, 0.0, 0.0, // rotation angles 1.0, // intensity 1.0); // falloff, not used for vector lights TheRend = EON_RendCreate(TheCamera); start = time(NULL); while (frames < framenum) { // Rotate by 1 degree on each axis TheModel->Rotation.X += 1.0; TheModel->Rotation.Y += 1.0; TheModel->Rotation.Z += 1.0; NullConsoleClearFrame(TheConsole); EON_RenderBegin(TheRend); // Start rendering with the camera EON_RenderLight(TheRend, TheLight); // Render our light EON_RenderMesh(TheRend, TheModel); // Render our object EON_RenderEnd(TheRend, TheFrame); // Finish rendering frames++; } stop = time(NULL); CX_log_trace(Logger, CX_LOG_INFO, EXE, "%i frames in %f seconds: %.3f FPS", frames, (double)stop-(double)start, (double)frames/((double)stop-(double)start)); return CX_log_close(Logger); }