1 #include <pangolin/pangolin.h>
2 #include <thread>
3
4 static const std::string window_name = "HelloPangolinThreads";
5
setup()6 void setup() {
7 // create a window and bind its context to the main thread
8 pangolin::CreateWindowAndBind(window_name, 640, 480);
9
10 // enable depth
11 glEnable(GL_DEPTH_TEST);
12
13 // unset the current context from the main thread
14 pangolin::GetBoundWindow()->RemoveCurrent();
15 }
16
run()17 void run() {
18 // fetch the context and bind it to this thread
19 pangolin::BindToContext(window_name);
20
21 // we manually need to restore the properties of the context
22 glEnable(GL_DEPTH_TEST);
23
24 // Define Projection and initial ModelView matrix
25 pangolin::OpenGlRenderState s_cam(
26 pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),
27 pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)
28 );
29
30 // Create Interactive View in window
31 pangolin::Handler3D handler(s_cam);
32 pangolin::View& d_cam = pangolin::CreateDisplay()
33 .SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)
34 .SetHandler(&handler);
35
36 while( !pangolin::ShouldQuit() )
37 {
38 // Clear screen and activate view to render into
39 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
40 d_cam.Activate(s_cam);
41
42 // Render OpenGL Cube
43 pangolin::glDrawColouredCube();
44
45 // Swap frames and Process Events
46 pangolin::FinishFrame();
47 }
48
49 // unset the current context from the main thread
50 pangolin::GetBoundWindow()->RemoveCurrent();
51 }
52
main(int,char **)53 int main( int /*argc*/, char** /*argv*/ )
54 {
55 // create window and context in the main thread
56 setup();
57
58 // use the context in a separate rendering thread
59 std::thread render_loop;
60 render_loop = std::thread(run);
61 render_loop.join();
62
63 return 0;
64 }
65