Advertisement

Switch between two views in opengl

Started by April 29, 2019 11:21 AM
3 comments, last by CrazyCdn 5 years, 9 months ago

I want to create two views in opengl and then switch between both of them depending on a gui option.

If I select that option in gui, then view 1 should be visible otherwise view 2 should be visible.

(I am basically using Pangolin library which uses opengl in the background)

My code is as below :

// view 1
    pangolin::OpenGlRenderState camera1 = pangolin::OpenGlRenderState(
        pangolin::ProjectionMatrix(w, h, 400, 400, w / 2.0, h / 2.0, 0.1,
                                   10000),
        pangolin::ModelViewLookAt(15, 5, 10, 0, 0, 0, pangolin::AxisY));

    pangolin::View& view1 =
        pangolin::CreateDisplay().SetBounds(0.0, 1.0, 0, 1.0,
                                            -w / static_cast<float>(h));
    auto* handler = new pangolin::Handler3D(camera1);
    view1.SetHandler(handler);

// view 2
    pangolin::OpenGlRenderState camera2 = pangolin::OpenGlRenderState(
            pangolin::ProjectionMatrix(w, h, 400, 400, w / 2.0, h / 2.0, 0.1,
                                       10000),
            pangolin::ModelViewLookAt(15, 5, 10, 0, 0, 0, pangolin::AxisY));

    pangolin::View& view2 =
            pangolin::CreateDisplay().SetBounds(0.0, 1.0, 0, 1.0,
                                                -w / static_cast<float>(h));
    view2.SetHandler(new pangolin::Handler3D(camera2));


if(option){
view1.Activate(camera1);
}
else
{
camera2.SetModelViewMatrix(pangolin::ModelViewLookAt(camDistFromCenter, 5, camDistFromCenter, 0, 0, 0, pangolin::AxisY));
view2.Activate(camera2);
}

I am able to switch between the two views but the problem is that the gui is not interactive anymore. I am not able to rotate or zoom in or out.

Normally OpenGL is single threaded/ single context rendering so if you want to switch a view, you need to switch the whole context using a MakeCurrent function to first release the currently active context and then activating the desired one

Advertisement

Instead of changing contextes thus nit sure if android would allow you to. You just should create separated render function Draw(int view)

{

If (view == 1) SetprojetcmatsAndDrawScene(1);

If (view == 2)

Sameasabove(99);

}

 

Even you consider changing rendering technique or explain more and more briefly

You've really not given us enough information.  What is the GUI, is it OpenGL based?  Win32 menu based?  Are the cameras just switching?  So it's not the context that are changing just where the cameras are pointing?  Or are the cameras rendering to two different viewports on the screen?  Have you tried, instead of having two views, just making one and switching which camera is active in that?  Also, these forums have source posting ability, it makes a post a lot neater, it's the <> icon.


// Note: Only one view, just switch camera's:
if(option){
   view.Activate(camera1);
}
else
{
   camera2.SetModelViewMatrix(pangolin::ModelViewLookAt(camDistFromCenter, 5, camDistFromCenter, 0, 0, 0, pangolin::AxisY));
   view.Activate(camera2);
}

 

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This topic is closed to new replies.

Advertisement