- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的 GLKViewcontroller 子类,它在被告知时呈现纹理。这本身就很好用,正是我需要它做的。但是,出于某种原因,当我试图在一个场景中使用它时,我一次有 6 个相同 View Controller 的副本(设置为指向相同 View 的容器 View )它不起作用。我有一个加载和显示纹理方法来选择从加载纹理的 map 中绘制哪个纹理。似乎只有我加载纹理的最后一个 View 才能正确绘制它们,其余部分显示为黑色方 block 。
这是我的 Storyboard的截图:
这是我的加载和绘制代码:
-(void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
[EAGLContext setCurrentContext:self.context];
self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = NO;
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
//sprite render:
if ( self.showTexture )
{
if ( firstDraw )
{
self.imageShowTime = [ATAppDelegate getCurrentTime];
firstDraw = NO;
}
self.effect.texture2d0.name = selectedTexture.name;
self.effect.texture2d0.enabled = YES;
self.effect.transform.modelviewMatrix = self.modelMatrix;
[self.effect prepareToDraw];
long offset = (long)&_quad;
glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, geometryVertex)));
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(TexturedVertex), (void *) (offset + offsetof(TexturedVertex, textureVertex)));
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
else
{
firstDraw = YES;
}
}
-(void)loadTextures:(NSArray *)textureNames
{
if ( textures == nil )
{
textures = [[NSMutableDictionary alloc] init];
}
[textures removeAllObjects];
NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
GLKTextureLoaderOriginBottomLeft,
nil];
NSError * error;
for ( NSString *texName in textureNames )
{
NSString *path = [[NSBundle mainBundle] pathForResource:texName ofType:nil];
GLKTextureInfo *newTex = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&error];
if ( newTex == nil || error != nil )
{
NSLog(@"Error loading file: %@", [error localizedDescription]);
return ;
}
NSLog(@"Loaded texture: %@ for name: %@", newTex, texName);
CGSize contentSize = CGSizeMake(newTex.width, newTex.height);
NSDictionary *texInfo = @{@"texture" : newTex, @"contentSize" : [NSValue valueWithCGSize:contentSize]};
textures[texName] = texInfo;
}
}
-(void)showTexture:(NSString *)texture
{
NSDictionary *texInfo = textures[texture];
if ( texInfo == nil )
{
NSLog(@"ERROR: no texture info found for texture name :%@ in %@", texture, textures);
}
else
{
NSLog(@"Showing texture: %@", texInfo);
}
selectedTexture = texInfo[@"texture"];
curContentSize = [texInfo[@"contentSize"] CGSizeValue];
}
最佳答案
问题很可能出现在 openGL 上下文中。问题是每个 Controller 都会创建自己的上下文,并且每个 Controller 都必须在用于任何绘制、呈现、纹理加载之前进行设置。
我从不使用像 GLKView
或 GLKViewController
这样的废话,所以请多多包涵。问题是纹理仅在一个上下文中加载,您需要为每个上下文( View Controller )加载它们,或者找到一种方法从一个 Controller 创建具有共享组的上下文:您创建一个上下文,您可以从中获取共享组,然后使用该共享组(上下文属性)初始化新上下文。结果是新上下文可能会使用在主上下文中创建的元素,例如纹理,反之亦然。一个更大的问题可能是这些 Controller 正在使用 openGL 做一些额外的工作,并且在这样做之前没有重置上下文。
无论如何,使用 openGL 制作多个 View 应该可以正常工作,所以我希望您能为您的问题找到一个好的解决方案。也许您需要做的就是在 loadTextures
方法的顶部设置当前上下文。
关于ios - 一次渲染多个 GLKViewControllers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26807835/
我的 iOS 应用程序使用 GLKViewController 来显示从本地网络上的外部相机流接收的数据。但是,几个小时后它挂起并且应用程序变得没有响应。如果我在调试器上暂停执行,我可以看到应用程序实
我有一个简单的 GLKViewcontroller 子类,它在被告知时呈现纹理。这本身就很好用,正是我需要它做的。但是,出于某种原因,当我试图在一个场景中使用它时,我一次有 6 个相同 View Co
我试图将 GLKView 嵌套在 UIView XIB 中。基本上按照这里的步骤: Nested GLKView and GLKViewController 我的CustomOpenGLControl
我正在尝试检测用户何时按下 GLKViewController 中的后退按钮。 View Controller 通过 Root View Controller (它是一个菜单)的 Storyboard
我正在尝试实现 this在我的项目中。但是我有一些麻烦。我计划使用 UiPanGestureRecognizer 来改变矩形的大小。据我了解,我应该使用 UIVIew 和自定义 drawRect 方法
我像这样创建一个 GLKViewController: // Create a GLK View Controller to handle animation timings _glkVC = [[G
我使用 OpenGL 游戏模板作为我的应用程序的起点,出于各种原因,我需要将我正在绘制的 GLKView 作为主视图的 subview 。我尝试设置“self.view = glView”,其中 gl
我有一个 MainMenuViewController 和一个 GameViewController,它是一个 GLKViewConrtroller。 我第一次从主菜单转到 GameViewContr
在我的 iPhone 应用程序中,我使用 Open GL GLKViewController。这是一个简单的游戏。我想使用 GoogleAnalytics 跟踪比赛,但它提出了更改 @interfac
我在这段代码的最后一行有一个 EXC_BAD_ACCESS(这段代码每秒被触发几次),但我无法弄清楚问题是什么: [EAGLContext setCurrentContext:_context]; g
我是一名新的 swift 开发人员。我正在使用 glkit 编写代码。我在 GLKViewController 不调用更新方法时遇到问题。请帮我修一下。谢谢你 import GLKit 游戏 Cont
我正在 iPhone 上使用 OpenGL 绘制一条线。我使用 GLView 和 GLKView 委托(delegate)来画线。但是现在我想给 GLKViewController 设置一个背景图片,
我是 OpenGL ES 的新手,正在试用 GLKit。我的目标是开发一个非常简单的应用程序,以便更好地感受 OpenGL。 我从 Apple 的示例代码(OpenGL ES 游戏)开始,实现了基本的
我尝试建立一个基于模板“OpenGL 游戏”的 Xcode 项目。该示例有一个带有一个 GLKViewController 和一个 GLKView 的 StoryBoard。 我想要: 一个 GLKV
如何从 iOS/iPhone 上的“GLKViewController”获取 FrameBuffer 或 RenderBuffer,以便将其传递给“glBindFramebuffer”?? 我正在尝试
我不确定为什么这不起作用,但也许这里有人可以阐明问题可能是什么。我正在开发基于 XCode OpenGL 模板的游戏。我有一个小的 GLKViewController,它的 View 不占用全屏区域,
我有一个非常简单的设置,有一个 mainViewController,上面有一个 GLKViewController。这个想法是将我的 GLKViewController 放在一个盒子里,在 main
根据这个question and its answer GLKViewController 与异步 OpenGL 绘图模式并不真正兼容。 有没有人知道任何开源或代码示例重新实现 GLKViewCont
{Xcode 4.4,部署目标 iOS5.0,不是 Storyboard,使用 ARC} 我一直在研究 iOS 中的 OpenGL,并且我在以编程方式创建 GLKViewController 和 GL
我尝试了一切: 1.在 UITrackingRunLoopMode 中使用重复的 NSTimers 并手动强制当前 GLKView 的 drawInRect。它不会更新任何内容,即使这些方法不断被调用
我是一名优秀的程序员,十分优秀!