- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
有没有办法让 GLKView 的背景透明?我试过解决方案 here但这对我不起作用。
*编辑:我需要帮助使其完全透明。背景主要是白色和灰色,但我只是用更鲜艳的颜色进行了测试,果然你可以隐约看到背景。任何想法为什么它会部分透明但不完全使用以下代码?
这是我的 View Controller 中的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease];
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.view.layer;
eaglLayer.opaque = NO;
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.backgroundColor = [UIColor clearColor];
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[self setupGL];
}
- (void)setupGL
{
[EAGLContext setCurrentContext:self.context];
self.effect = [[[GLKBaseEffect alloc] init] autorelease];
self.effect.light0.enabled = GL_FALSE;
self.effect.light0.diffuseColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 0.0f);
self.effect.light0.ambientColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 0.0f);
glDisable(GL_DEPTH_TEST);
glGenVertexArraysOES(1, &_vertexArray);
glBindVertexArrayOES(_vertexArray);
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, VERTEX_POS_DATA_SIZE, GL_FLOAT, GL_FALSE, VERTEX_DATA_SIZE * sizeof(GLfloat), BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, VERTEX_COLOR_DATA_SIZE, GL_FLOAT, GL_FLOAT, VERTEX_DATA_SIZE * sizeof(GLfloat), BUFFER_OFFSET(VERTEX_POS_DATA_SIZE * sizeof(GLfloat)));
glLineWidth(10.0);
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
if (!needsRedraw) return;
needsRedraw = NO;
glClearColor(0.65f, 0.65f, 0.65f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self.effect prepareToDraw];
glDrawArrays(GL_LINE_STRIP, 0, vertexCount);
}
我已经尝试将 的 backgroundColor 设置为 [UIColor clearColor] 并将 eaglLayer 设置为不透明。哎呀,我什至尝试将 eaglLayer 的 backgroundColor 设置为不透明度为 0 的 CGColorRef。
最佳答案
嗯,我认为这无关紧要,因为 alpha 已经是 0.0f,但是当我改变时
glClearColor(0.65f, 0.65f, 0.65f, 0.0f);
到
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
它使背景完全透明。
感谢大家的建议和帮助!
关于iphone - 具有透明背景的 OpenGL ES 2.0 GLKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10636176/
场景 我正在构建一个应用程序来处理视频帧的色度值。我正在使用来自另一个项目的 Objective-C 代码并将其翻译成 Swift。但是我遇到了一段奇怪的代码,我想将其翻译成 Swift,如果我能弄清
我正在 opengles 中制作一个基本应用程序,我从“raywenderlich”Glkit 教程开始。这将在应用程序的启动屏幕中显示一个立方体。他在教程中提到了以下几行来执行此操作。 To mak
有没有一种方法可以将CATransform3D转换为GLKMatrix4,还是我总是需要手动将它们从值转换为值? 我想转换会更快。 最佳答案 不幸的是,到目前为止还没有。 Apple最有可能使用隐藏的
我在使用 GLKit 对 PNG 图像着色时遇到问题。 我有一个白色 PNG 图像,我将其加载到应用程序中,然后使用它来创建纹理: UIImage *image = [ UIImage imageNa
过去几天我一直在使用一些具有颜色属性和位置属性的 GLKit 代码,但是当我尝试添加普通属性时,它每次都会崩溃。 顶点着色器: attribute vec4 SourceColor; attrib
我有一个使用 glKit 运行的游戏,我想在每一帧渲染后使用着色器添加一些后期处理效果。 是否可以在 glKit 下执行此操作? 最佳答案 这是可能的。 您需要创建自己的屏幕外帧缓冲区对象和相关纹理。
我正在尝试使用 OpenGL ES 和 GLKit 绘制类似这样的东西 但是我明白了 虽然纹理是透明的,但模型的上层替换了下面的纹理而不是混合。有可能以某种方式修复它吗? - (void)setup
我使用以下链接获取在 iOS 中绘制 3D 立方体的源代码。 http://www.raywenderlich.com/5235/beginning-opengl-es-2-0-with-glkit-
我最近开始了一个基于 OpenGL 示例的新 iOS 项目。我添加了自己的相机移动代码,并且添加了一个包含 Block 实例的 NSMutableArray(当前仅包含 3D 位置)。我已经修改了绘图
当我尝试在 OpenGl ES 2.0 中创建一个带有附加纹理的 FBO 时,如下所示: glGenFramebuffers(1, &framebuffer); glGenTextur
我正在运行 XCode 为 iOS 的 OpenGL 项目创建的样板 OpenGL 示例代码。这会设置一个简单的 ViewController 并使用 GLKit 来处理其余的工作。 应用程序的所有更
我正在尝试转换 OGL ES 1.1。代码到 GLKit。 GLKit 提供了一对纹理插槽: 纹理2d0 纹理2d1 每个纹理都有一个环境模式: GLKTextureEnvModeReplace, G
我是 OpenGL/GLKit 的新手,在深度测试方面遇到了麻烦。下图显示了一个柱子,有五个横梁与它相交。它们都在中间(柱子内部)相遇,但正如您所见,本应被遮挡的光束部分仍然可见。它们疯狂地闪烁,当我
我正在使用 Ray Wenderlich 的教程使用 GLKit 制作一个简单的 OpenGlES 2 应用程序,但我遇到了一些问题。 我将示例代码更改为通过将顶点和索引数据添加到现有顶点和索引数据结
我使用了 this link 中的代码映射人脸的纹理。此代码使用 GLKIT 来呈现图像。代码在模拟器中运行良好,但如果我在设备中运行,则相同的代码无法运行。以下是它在设备中而不是在我的 ipad 中
我一直在阅读使用 GLKit 和您自己的自定义着色器是多么容易。但是,到目前为止,我还没有找到有关如何实际操作的任何信息。如何将我自己的着色器“插入”到现有的 GLKit 项目中? 最佳答案 好吧,你
我刚刚安装了当前的 Xcode 4 版本,并实现了新的“GLKit”API,该 API 也用于 iOS 的 OpenGL 模板。所以,我想开发一款适用于 iOS、Mac 和 Windows 的跨平台游
在 iOS 5 中,使用 EAGLView,您可以: glPushMatrix(); glTranslatef(x, y, 0.0f); glDrawArrays(GL_TRIANGLE_STRIP,
我几乎完成了我的应用程序。其中一个 View 使用 GLKit。我只是内存有问题。基本上发生的事情是,当显示 GLKView 时,内存消耗不断上升(在 Instruments 中看到)。在某个时候它显
我正在尝试使用 GLKit 绘制半透明多边形,但没有成功。所以我想知道是否有可能首先在 GLKit 中使用半透明多边形,因为我知道它在 OpenGL 的标准实现中不受支持;但可以使用自定义着色器进行模
我是一名优秀的程序员,十分优秀!