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.
  1. 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).
  1. /* use the panorama mode, we also support some other modes such as asteroid mode */
  2. pancamGL->init(ICH_GL_PANORAMA_TYPE_SPHERE);
  3. /* get transform interface */
  4. pancamGL->getPancamGLTransform(pancamGLTransform);

Common rendering modes include ordinary spheres and asteroids. .etc

2. Set the drawing’s component context (SurfaceContext) and initialize (setup)
  1. /* set surface */
  2. surfaceContext = make_shared<ICatchSurfaceContext_IosEAGL>();
  3. pancamGL->setSurface(ICH_GL_SURFACE_TYPE_SPHERE, surfaceContext);
  4. /* set up the gl context(render) */
  5. [EAGLContext setCurrentContext:self.context];
  6. int ret = surfaceContext->setup();
  7. 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
  1. - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
  2. {
  3. int windowW = (int)view.drawableWidth;
  4. int windowH = (int)view.drawableHeight;
  5. if (surfaceContext && surfaceContext->needSetup()) {
  6. surfaceContext->setup();
  7. surfaceContext->setViewPort(0,0, windowW, windowH);
  8. }
  9. if (surfaceContext && surfaceContext->needRender()) {
  10. surfaceContext->setViewPort(0,0, windowW, windowH);
  11. surfaceContext->render();
  12. NSLog(@"call render");
  13. }
  14. }

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

    1. NSLog(@"tear down gl in\n");
    2. [EAGLContext setCurrentContext:self.context];
    3. if (surfaceContext != nil)
    4. surfaceContext->tearDown();
  • Release open gl related resources

    1. pancamGL->clearFormat();
    2. 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:
  1. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  2. {
  3. for(UITouch *touch in event.allTouches) {
  4. CGPoint pointC = [touch locationInView:nil];
  5. pointP.x = pointC.x;
  6. pointP.y = pointC.y;
  7. }
  8. }
  9. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  10. {
  11. for(UITouch *touch in event.allTouches) {
  12. // Create ICatch GL point
  13. CGPoint pointC = [touch locationInView:nil];
  14. auto pointGLC = make_shared<ICatchGLPoint>(pointC.x, pointC.y);
  15. auto pointGLP = make_shared<ICatchGLPoint>(pointP.x, pointP.y);
  16. NSLog(@"px %f py %f ex %f ey %f", pointGLP->getX(), pointGLP->getY(), pointGLC->getX(), pointGLC->getY());
  17. // Rotate
  18. if (pancamGL != NULL) {
  19. pancamGLTransform->rotate(pointGLP, pointGLC);
  20. }
  21. // Update Prev point
  22. pointP.x = pointC.x;
  23. pointP.y = pointC.y;
  24. }
  25. }
  26. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  27. {
  28. // Nothing to do
  29. }
  30. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
  31. {
  32. // Nothing to do
  33. }

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

  1. All the sample code is located in the source file ViewController.mm
  2. 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.