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

Function main

apps/ospTutorial/ospTutorialGLM.cpp:28–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include "rkcommon/utility/SaveImage.h"
27
28int main(int argc, const char **argv)
29{
30 // image size
31 glm::ivec2 imgSize;
32 imgSize.x = 1024; // width
33 imgSize.y = 768; // height
34
35 // camera
36 glm::vec3 cam_pos{0.f, 0.f, 0.f};
37 glm::vec3 cam_up{0.f, 1.f, 0.f};
38 glm::vec3 cam_view{0.1f, 0.f, 1.f};
39
40 // triangle mesh data
41 std::vector<glm::vec3> vertex = {glm::vec3(-1.0f, -1.0f, 3.0f),
42 glm::vec3(-1.0f, 1.0f, 3.0f),
43 glm::vec3(1.0f, -1.0f, 3.0f),
44 glm::vec3(0.1f, 0.1f, 0.3f)};
45
46 std::vector<glm::vec4> color = {glm::vec4(0.9f, 0.5f, 0.5f, 1.0f),
47 glm::vec4(0.8f, 0.8f, 0.8f, 1.0f),
48 glm::vec4(0.8f, 0.8f, 0.8f, 1.0f),
49 glm::vec4(0.5f, 0.9f, 0.5f, 1.0f)};
50
51 std::vector<glm::uvec3> index = {glm::uvec3(0, 1, 2), glm::uvec3(1, 2, 3)};
52
53 // initialize OSPRay; OSPRay parses (and removes) its commandline parameters,
54 // e.g. "--osp:debug"
55 OSPError init_error = ospInit(&argc, argv);
56 if (init_error != OSP_NO_ERROR)
57 return init_error;
58
59 // use scoped lifetimes of wrappers to release everything before ospShutdown()
60 {
61 // create and setup camera
62 ospray::cpp::Camera camera("perspective");
63 camera.setParam("aspect", imgSize.x / (float)imgSize.y);
64 camera.setParam("position", cam_pos);
65 camera.setParam("direction", cam_view);
66 camera.setParam("up", cam_up);
67 camera.commit(); // commit each object to indicate modifications are done
68
69 // create and setup model and mesh
70 ospray::cpp::Geometry mesh("mesh");
71 mesh.setParam("vertex.position", ospray::cpp::CopiedData(vertex));
72 mesh.setParam("vertex.color", ospray::cpp::CopiedData(color));
73 mesh.setParam("index", ospray::cpp::CopiedData(index));
74 mesh.commit();
75
76 // put the mesh into a model
77 ospray::cpp::GeometricModel model(mesh);
78 model.commit();
79
80 // put the model into a group (collection of models)
81 ospray::cpp::Group group;
82 group.setParam("geometry", ospray::cpp::CopiedData(model));
83 group.commit();
84
85 // put the group into an instance (give the group a world transform)

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