- Brief introduction
- Flow Display
- OpenGL related operations
- 1. Determine which display mode to use and initialize the corresponding object with it, and obtain the interface to used as picture control (transform).
- 2. Set the drawing’s component context (SurfaceContext) and initialize (setup)
- 3. Rewrite the drawing function
drawInRectofGLKView, and add the code that triggers the SDK rendering - 4. After doing all this, you can open the stream.
- 5. After the preview operation, use the following method to release resources
- Some other notes
- Sample code
Brief introduction
This document wil introduce how to use the C++ layer API to write Streaming-related apps, and use the OpenGL rendering function provided by the SDK. Before reading this document, it is recommended to read the Previous document, As the programming flow is nearly the same, this document will focus on the use of OpenGL rendering related API. At the same time, a working IOS example project will be provided.
Flow Display
For the main Flow, please refer to the Flow Display section in the previous document.
The differences are:
1. The prevous document’s sample code is written for android using java, but naming and usage of the Java and the C++ API are almost the same.
2. When choosing the rendering mode, here we use the OpenGL rendering provided by the SDK, the code is as follows.
pancamPreview->enableGLRender(pancamGL);
OpenGL related operations
1. Determine which display mode to use and initialize the corresponding object with it, and obtain the interface to used as picture control (transform).
/* use the panorama mode, we also support some other modes such as asteroid mode */pancamGL->init(ICH_GL_PANORAMA_TYPE_SPHERE);/* get transform interface */pancamGL->getPancamGLTransform(pancamGLTransform);
Common rendering modes include ordinary spheres and asteroids. .etc
2. Set the drawing’s component context (SurfaceContext) and initialize (setup)
/* set surface */surfaceContext = make_shared<ICatchSurfaceContext_IosEAGL>();pancamGL->setSurface(ICH_GL_SURFACE_TYPE_SPHERE, surfaceContext);/* set up the gl context(render) */[EAGLContext setCurrentContext:self.context];int ret = surfaceContext->setup();NSLog(@"setupGL with surfaceContext: %p, ret %d\n", surfaceContext.get(), ret);
3. Rewrite the drawing function drawInRect of GLKView, and add the code that triggers the SDK rendering
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect{int windowW = (int)view.drawableWidth;int windowH = (int)view.drawableHeight;if (surfaceContext && surfaceContext->needSetup()) {surfaceContext->setup();surfaceContext->setViewPort(0,0, windowW, windowH);}if (surfaceContext && surfaceContext->needRender()) {surfaceContext->setViewPort(0,0, windowW, windowH);surfaceContext->render();NSLog(@"call render");}}
4. After doing all this, you can open the stream.
5. After the preview operation, use the following method to release resources
Release surface context related resources
NSLog(@"tear down gl in\n");[EAGLContext setCurrentContext:self.context];if (surfaceContext != nil)surfaceContext->tearDown();
Release open gl related resources
pancamGL->clearFormat();pancamGL->release();
Some other notes
1. You should use the GLKView as a rendering component, rather than a normal View class.
2. If you want to rotate and zoom the picture, you need to use the transform interface obtained previously. The code is as follows:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{for(UITouch *touch in event.allTouches) {CGPoint pointC = [touch locationInView:nil];pointP.x = pointC.x;pointP.y = pointC.y;}}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{for(UITouch *touch in event.allTouches) {// Create ICatch GL pointCGPoint pointC = [touch locationInView:nil];auto pointGLC = make_shared<ICatchGLPoint>(pointC.x, pointC.y);auto pointGLP = make_shared<ICatchGLPoint>(pointP.x, pointP.y);NSLog(@"px %f py %f ex %f ey %f", pointGLP->getX(), pointGLP->getY(), pointGLC->getX(), pointGLC->getY());// Rotateif (pancamGL != NULL) {pancamGLTransform->rotate(pointGLP, pointGLC);}// Update Prev pointpointP.x = pointC.x;pointP.y = pointC.y;}}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{// Nothing to do}- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{// Nothing to do}
These functions are generally developed in combination with touch, gestures, gyroscopes, etc. The above codes use the touch screen related methods.
Sample code
We also provide a IOS sample project based on Xcode, which is used to show the operations mentioned above. Now we will explain some contents in the project:
You can download the source code from github
- All the sample code is located in the source file
ViewController.mm - Due to Github related restrictions, you need to obtain the SDK download link from Here. The SDK version V_3.6.0.18 and later will work well with the App.
