MCPcopy Create free account
hub / github.com/RenderKit/ospray / main

Function main

apps/ospTutorial/ospTutorial.cpp:37–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35using namespace rkcommon::math;
36
37int main(int argc, const char **argv)
38{
39 // image size
40 vec2i imgSize;
41 imgSize.x = 1024; // width
42 imgSize.y = 768; // height
43
44 // camera
45 vec3f cam_pos{0.f, 0.f, 0.f};
46 vec3f cam_up{0.f, 1.f, 0.f};
47 vec3f cam_view{0.1f, 0.f, 1.f};
48
49 // triangle mesh data
50 std::vector<vec3f> vertex = {vec3f(-1.0f, -1.0f, 3.0f),
51 vec3f(-1.0f, 1.0f, 3.0f),
52 vec3f(1.0f, -1.0f, 3.0f),
53 vec3f(0.1f, 0.1f, 0.3f)};
54
55 std::vector<vec4f> color = {vec4f(0.9f, 0.5f, 0.5f, 1.0f),
56 vec4f(0.8f, 0.8f, 0.8f, 1.0f),
57 vec4f(0.8f, 0.8f, 0.8f, 1.0f),
58 vec4f(0.5f, 0.9f, 0.5f, 1.0f)};
59
60 std::vector<vec3ui> index = {vec3ui(0, 1, 2), vec3ui(1, 2, 3)};
61
62#ifdef _WIN32
63 bool waitForKey = false;
64 CONSOLE_SCREEN_BUFFER_INFO csbi;
65 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
66 // detect standalone console: cursor at (0,0)?
67 waitForKey = csbi.dwCursorPosition.X == 0 && csbi.dwCursorPosition.Y == 0;
68 }
69#endif
70
71 // initialize OSPRay; OSPRay parses (and removes) its commandline parameters,
72 // e.g. "--osp:debug"
73 OSPError init_error = ospInit(&argc, argv);
74 if (init_error != OSP_NO_ERROR)
75 return init_error;
76
77 // use scoped lifetimes of wrappers to release everything before ospShutdown()
78 {
79 // create and setup camera
80 ospray::cpp::Camera camera("perspective");
81 camera.setParam("aspect", imgSize.x / (float)imgSize.y);
82 camera.setParam("position", cam_pos);
83 camera.setParam("direction", cam_view);
84 camera.setParam("up", cam_up);
85 camera.commit(); // commit each object to indicate modifications are done
86
87 // create and setup model and mesh
88 ospray::cpp::Geometry mesh("mesh");
89 mesh.setParam("vertex.position", ospray::cpp::CopiedData(vertex));
90 mesh.setParam("vertex.color", ospray::cpp::CopiedData(color));
91 mesh.setParam("index", ospray::cpp::CopiedData(index));
92 mesh.commit();
93
94 // put the mesh into a model

Callers

nothing calls this directly

Calls 10

ospInitFunction · 0.85
mapMethod · 0.80
writePPMFunction · 0.70
setParamMethod · 0.45
commitMethod · 0.45
clearMethod · 0.45
renderFrameMethod · 0.45
unmapMethod · 0.45
pickMethod · 0.45
handleMethod · 0.45

Tested by

no test coverage detected