- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这不是 OpenGL ES 2 without GLKit 的副本
我在 iOS 上编写 OpenGL 程序已有 4 年,在 ES2 上编写程序将近 2 年。但是随着 GLKit 和 Storyboards 的加入,以及最新的 Xcode,项目模板有所不同。并且不再有创建 EAGLView 类的 OpenGL 模板。我不想使用 GLKit。我更喜欢始终以编程方式做事。我尽量避免使用 Nib ,而且我以前从未使用过 Storyboard。但在下面的这种情况下,我将保留模板中的原样。
我的步骤:
我从一个新项目开始,然后选择单 View 应用程序。我运行它,它运行良好,但出现白屏。
接下来我转到构建阶段并添加 QuartzCore、OpenGLES。
然后我创建新文件并添加一个 Objective-C 类,使其成为 UIView 的子类并命名为 EAGLView。在我导入的 .h 和 EAGLContext *context
在 initWithFrame 的 .m 文件中,我添加了这段初始化代码...
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGB565, kEAGLDrawablePropertyColorFormat,
nil];
// Creates the EAGLContext and set it as the current one.
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!_context || ![EAGLContext setCurrentContext:_context])
{
NSLog(@"_context no workie!");
return nil;
}
在我的 ViewController.h 中,我添加了 @class EAGLView;
和一个属性 EAGLView *glView;
我在 viewDidLoad 的 ViewController.m 中添加:
CGRect rect = [[UIScreen mainScreen] applicationFrame];
int width=rect.size.width;
int height=rect.size.height;
glView = [[EAGLView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
if([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
glView.contentScaleFactor = [[UIScreen mainScreen] scale];
}
glView.contentMode = UIViewContentModeScaleToFill;
self.view = glView;
然后我运行它。我收到此错误消息:
-[CALayer setDrawableProperties:]: 无法识别的选择器发送到实例 0x8e441c0
我的 CAEAGLLayer eaglLayer 怎么没有 .drawableProperties 的选择器?我是否错过了某处步骤?
* 更新 *
我找到了这个解决方案:
在 EAGLView.m 中,我添加了以下内容:
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
现在它可以正常运行而不会崩溃。谁能告诉我为什么需要它?
最佳答案
您总是需要覆盖此方法。似乎默认图层类是 CALayer
,它没有 setDrawableProperties:
方法。您可以看到 CAEAGLLayer
是 CALayer
的子类。
在管道的某处,类似这样的东西被称为
[[[self class] layerClass] performSelector:@selector(setDrawableProperties:) withObject:properties];
它会在您不覆盖 layerClass
方法的情况下生成异常。
关于ios - 在不使用 GLKIT 的情况下创建(从头开始)iOS 7.0 OpenGL ES 2.0 应用程序时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23560153/
场景 我正在构建一个应用程序来处理视频帧的色度值。我正在使用来自另一个项目的 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 的标准实现中不受支持;但可以使用自定义着色器进行模
我是一名优秀的程序员,十分优秀!