1

我正在尝试使用 Google 的新 Maps SDK,并在 Google Maps 顶部添加了添加的子视图控制器。谷歌地图本身工作正常,正如预期的那样。我的 openGL 控制器(GLKit)在不使用地图时也是如此。但是在拖动地图时,GLKView 正在调用 setNeedsDisplay,您可以看到地图没有完全绘制。只有当停止拖动地图时,视图才会完全恢复。

我在 gitHub 上有项目:https ://github.com/rendulic/GMaps3D

我也知道谷歌的问题:http://code.google.com/p/gmaps-api-issues/issues/detail?id=4752,但没有解决方法对我不起作用。

我有 2 个控制器: - ViewController(它初始化 Google Maps) - OpenGLController(ViewController 的子控制器)

ViewController 的 google maps init in viewDidLoad:

[super viewDidLoad];

// setting up mapView
_mapView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:46.550814 longitude:15.645118 zoom:18 bearing:0 viewingAngle:65];
_mapView.camera = camera;
_mapView.delegate = self;
_mapView.mapType = kGMSTypeNormal;
_mapView.settings.compassButton = YES;
_mapView.settings.myLocationButton = YES;

_mapView.settings.zoomGestures = YES;

// defining landscape size and portrait size on the map view
_portraitRect = CGRectMake(0, 0, _mapView.frame.size.width, _mapView.frame.size.height);
// adding status bar height
_landscapeRect = CGRectMake(0, 0,_mapView.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height, _mapView.frame.size.width);

// adding button view relative to mapView
MapMenuView *menuView = [[MapMenuView alloc] initWithFrame:CGRectMake( _mapView.frame.size.width - 50, 50, 60, 80)];
menuView.tag = 6661; // unique tag for the view (needed after orientation change so the position can be modified)
[self.view addSubview:menuView];


UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
_openGLController = (OpenGLController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"openGLController"];

[_openGLController setPreferredFramesPerSecond:30];

[self addChildViewController:_openGLController];
[self.view addSubview:_openGLController.view];
[self didMoveToParentViewController:self];

// set delegate for openGL redraw
[self setViewControllerDelegate:_openGLController];

}

这是 OpenGLController 中的 OpenGL 设置:

 EAGLContext *firstContext = [EAGLContext currentContext];

_glView.context = firstContext;
_glView.delegate = self;

if (!_glView.context) {
    NSLog(@"Failed to create NSContext");
}

_glView.drawableMultisample = GLKViewDrawableMultisample4X;
_glView.drawableDepthFormat = GLKViewDrawableDepthFormat16;
_glView.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.5];

glEnable(GL_CULL_FACE);

// init effect
_effect = [[GLKBaseEffect alloc] init];

// init textures
NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithBool:YES],
                          GLKTextureLoaderOriginBottomLeft,
                          nil];

NSError * error;
NSString *path = [[NSBundle mainBundle] pathForResource:@"barrack" ofType:@"png"];
GLKTextureInfo * info = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&error];
if (info == nil) {
    NSLog(@"Error loading file: %@", [error localizedDescription]);
}


_effect.texture2d0.name = info.name;
_effect.texture2d0.enabled = true;


// 60 frames per seconds call
/*CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[displayLink setFrameInterval:1/60];
*/

// prepare buffers
glGenVertexArraysOES(1, &_vertexArray);
glBindVertexArrayOES(_vertexArray);

glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

glGenBuffers(1, &_indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);

glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));

glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, TexCoord));

glBindVertexArrayOES(0);

}

这是 drawInRect 正在执行的操作:

[self setupGL];
[self update];

glClearColor(0,0,0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glFlush();

[_effect prepareToDraw];

glBindVertexArrayOES(_vertexArray);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [[TextureManager sharedTextureManager] getTexture:TEXTURE_BARRACK]);

glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);

glFlush();
4

0 回答 0