- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试让 init 函数在我创建的 NSOpenGlView 子类版本中运行。
例如下面的代码。
- (id)initWithFrame:(NSRect)frameRect{
NSLog(@"Init function ran");
return self;
}
它应该将 init 函数运行的信息发送到控制台,但它没有!我尝试创建一个 init 函数和 initWithFrame:PixelFormat: 函数,看看它们是否触发了任何控制台消息,但什么也没发生。
我通过将 NSOpenGlView 拖到界面生成器中的窗口并将其类设置为我的子类版本来创建它。我的drawrect函数工作正常并绘制了一个opengl三角形,所以我知道它在那个级别上工作。
如果你好奇的话,这是我的整个类(class)
#import <Cocoa/Cocoa.h>
@interface openGLView : NSOpenGLView
- (void) drawRect:(NSRect) bounds;
@end
#import "openGLView.h"
#include <OpenGL/gl.h>
@implementation openGLView
- (id)initWithFrame:(NSRect)frameRect{
NSLog(@"Init function ran");
return self;
}
- (void) drawRect:(NSRect) bounds{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
drawAnObject();
glFlush();
NSLog(@"drawRect");
}
static void drawAnObject ()
{
glColor3f(1.0f, 0.85f, 0.35f);
glBegin(GL_TRIANGLES);
{
glVertex3f( 0.0, 0.6, 0.0);
glVertex3f( -0.2, -0.3, 0.0);
glVertex3f( 0.2, -0.3 ,0.0);
}
glEnd();
}
@end
我需要这样做的原因是这样我可以在初始化时返回一个新的 32 位像素格式,以便 DEPTH_TEST 真正起作用。据说你可以在界面生成器中设置它,但对我来说,我没有看到任何选项。这可能是因为它位于 ScrollView 内,但还不确定。
最佳答案
如果您在 Interface Builder 中创建了 View ,那么它不会调用 - (id)initWithFrame:(NSRect)frame
,而是调用 - (id)initFromCoder:(NSCoder * )编码器
关于macos - 如何让OpenGlView的init函数运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15037929/
我希望在 Cocoa 上制作一个自定义的 NSOpenGL View 。但是,我在使用 VAO 时遇到了问题。特别是,运行时,这个虚拟测试 View : /// OpenGLTestView.h: @
当选择一行时,我有一个UITableView,另一个ViewConroller被推送,并且ViewContoller应该有一个GLView >。我不确定是否将 OpenGLView 作为 subvie
我一直在运行一个很好的 Cocos2d 教程来实现 iAds,并且即将实现它(我从控制台收到 iAd 消息)... 我不断回到这个警告: CCGLView *eaglView = [[CCDirect
这是我的代码: // View Controller with navigation bar InAppPurchaseViewController *purchaseViewController =
我在向 cocos2d v2.0 添加 UIView 时遇到了一些麻烦,因为不推荐使用 openGlView 我无法向它添加 View 。我四处寻找另一种方法来做到这一点,但我找不到任何东西。 谁能告
我是一名优秀的程序员,十分优秀!