pangolin库使用三(子图, imageTexture,)

#include <pangolin/pangolin.h>
//更新数组函数
int main(int argc,char ** argv)
{
  int w=640;
  int h=480;
  float Aspect=w/h;
  pangolin::CreateWindowAndBind("mult",w,h);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);

  pangolin::OpenGlRenderState cam(
    pangolin::ProjectionMatrix(w,h,w/2,h/2,w/2,h/2,0.2,100),
    pangolin::ModelViewLookAt(1,1,1,0,0,0,pangolin::AxisX)
    );
  pangolin::OpenGlRenderState s_cam2(pangolin::ProjectionMatrix(w,h,w/2,h/2,w/2,h/2,0.2,100), pangolin::ModelViewLookAt(-1,-1,-1,0,0,0, pangolin::AxisY) );
pangolin::Handler3D handel(cam);

  
  return 0;
}

自定义一帧显示

  pangolin::View& dam1=pangolin::Display("1")//添加子图1
  .SetAspect(Aspect).SetHandler(&handel)
  ;

  pangolin::View& dam2=pangolin::Display("21")//添加子图2
  .SetAspect(Aspect).SetHandler(&handel)
  ;
  pangolin::View& dam3=pangolin::Display("321")//添加子图3
  .SetAspect(Aspect).SetHandler(&handel)
  ;
  pangolin::Display("multiplay1")//设置主界面
  .SetBounds(0,1,0,1)
  .SetLayout(pangolin::LayoutEqualVertical)//设置垂直平分显示模式
  .AddDisplay(dam1)//添加子图
  .AddDisplay(dam2)
  .AddDisplay(dam3)
  ;

  while (!pangolin::ShouldQuit())
  {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
    
    dam1.Activate(cam);
    pangolin::glDrawColouredCube();//画一个正方形
    dam3.Activate(cam);
    pangolin::glDrawColouredCube();
    dam2.Activate(cam);
    imageTexture.RenderToViewport();//输出到屏幕
    pangolin::FinishFrame();
  }

使用pangolin::GlTexture imageTexture()自定义一帧

void setImageData(unsigned char * imageArray, int size){
    for(int i = 0 ; i < size;i++) {
        imageArray[i] = (unsigned char)(rand()/(RAND_MAX/255.0));
    }
  	unsigned char* imageArray = new unsigned char[3*w*h];//穿件一个3*w*h的数据
  	pangolin::GlTexture imageTexture(w,h,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);//初始化一帧
  	setImageData(imageArray,3*w*h);//更新数组
	imageTexture.Upload(imageArray,GL_RGB,GL_UNSIGNED_BYTE);//更新阵数据
	imageTexture.RenderToViewport();//输出到屏幕

多线程

#include <pangolin/pangolin.h>
#include <thread>

static const std::string window_name = "HelloPangolinThreads";

void setup() {
    pangolin::CreateWindowAndBind(window_name, 640, 480);

    glEnable(GL_DEPTH_TEST);

    pangolin::GetBoundWindow()->RemoveCurrent();
    //setup()函数是在主线程创建的,因此在主线程调用完之后,需要使用GetBoundWindow()->RemoveCurrent()对其解绑
}

void run() {
    pangolin::BindToContext(window_name);
    glEnable(GL_DEPTH_TEST);

    pangolin::OpenGlRenderState s_cam(
            pangolin::ProjectionMatrix(640,480,420,420,320,240,0.2,100),
            pangolin::ModelViewLookAt(-2,2,-2, 0,0,0, pangolin::AxisY)
    );

    pangolin::Handler3D handler(s_cam);
    pangolin::View& d_cam = pangolin::CreateDisplay()
            .SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f)
            .SetHandler(&handler);

    while( !pangolin::ShouldQuit() )
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        d_cam.Activate(s_cam);

        pangolin::glDrawColouredCube();

        pangolin::FinishFrame();
    }

    pangolin::GetBoundWindow()->RemoveCurrent();
}

int main()
{
    setup();

    std::thread render_loop;//新建一个线程
    render_loop = std::thread(run);//然后将函数run加载到线程中
    render_loop.join();//运行线程

    return 0;
}

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页