环境:IOS
依赖库:GLKit
目标:借助openGL离屏渲染在不影响前端展示的情况下渲染出所需要的模型并截图保存(因为前端展示的和需要的图片背景、角度等参数不同)
//print screen when model rotates to angle
void printScreen(GLint* viewPort, const char* fileName)
{
GLbyte* colorArr = new GLbyte[viewPort[2] * viewPort[3] * 4];
if(colorArr==NULL)
{
NSLog(@"Funtion printScreen new colorArr Error!");
return;
}
glReadPixels(viewPort[0], viewPort[1], viewPort[2], viewPort[3], GL_RGBA, GL_UNSIGNED_BYTE, colorArr);
int WW=viewPort[2];
int HH=viewPort[3];
cv::Mat img;
vector<cv::Mat> imgPlanes;
img.create(HH, WW, CV_8UC3);
split(img, imgPlanes);
for(int i = 0; i < HH; i ++) {
uchar* plane0Ptr = imgPlanes[2].ptr<uchar>(i);
uchar* plane1Ptr = imgPlanes[1].ptr<uchar>(i);
uchar* plane2Ptr = imgPlanes[0].ptr<uchar>(i);