この質問が些細なことやナンセンスである場合は、事前にお詫び申し上げます...これは私が開発している最初のアプリの 1 つです。(残念ながら) 私は開発者ではありません。
のサブクラスであるカスタム ビューを含む NSWindow がありますNSOpenGLView
。
NSWindow
と はNSOpenGLView
Interface Builder で作成されるため、どちらも必要ありinit
ませNSOpenGLContext
んNSOpenGLPixelFormat
。
最近 OS X Lion に切り替えたので、新しい OpenGL 3.2 を活用したいと考えています。
Appleのドキュメントから、OpenGL 3.2を有効にするには、次のように書くだけでよいことがわかりました。
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease];
を初期化する前にNSOpenGLContext
.
これは(私にとっても)非常に簡単ですが、アプリにこれを実装するにはどうすればよいinit
NSOpenGLContext
ですか?
NSOpenGLView
は Interface Builder から作成されるため、メソッドは-initWithFormat:shareContext:
呼び出されません。
-initWithCoder:
したがって、私は次のような方法でメソッドをオーバーライドしようとしました:
-(id)initWithCoder:(NSCoder *)aDecoder
{
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease];
[super initWithCoder:aDecoder];
[self setOpenGLContext:openGLContext];
[openGLContext makeCurrentContext];
}
OpenGL 3.2 は、によって報告されたように正しく読み込まれますglGetString(GL_VERSION)
が、作成されたコンテキストはアプリと対話しなくなりました...ビューには何も描画されません..
知っていることはすべて試しました...しかし、これを解決できません。
代わりにどうすればいいですか?