#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")
.SetAspect(Aspect).SetHandler(&handel)
;
pangolin::View& dam2=pangolin::Display("21")
.SetAspect(Aspect).SetHandler(&handel)
;
pangolin::View& dam3=pangolin::Display("321")
.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];
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();
}
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);
render_loop.join();
return 0;
}