所以即時嘗試創建一個openGL視圖(在我的窗口中)。我正在製作一個可可應用程序。 我設法通過界面生成器創建一個,但爲了教育目的,我想繼續,沒有它。只是在紙上。在沒有Interface Builder的情況下創建一個OpenGL視圖
這裏是要告訴你我正在努力的一點。 所以基本上做了什麼 - 到目前爲止嘗試的是這樣的: 我創建了一個從NSOpenGLView繼承的新類「MyOpenGLView.h/m」。 我沒有添加私人變數或方法,只是類名。我做的唯一的事情就是覆蓋initWithFrame:(在它內部添加一個self = [super initWithFrame:pixelFormat:]。) 我在Web上閱讀了它,必須先使用類似這樣的東西實例化它,然後才能使用它)。這裏是代碼:
- (id) initWithFrame:(NSRect)frameRect
{
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc]
initWithAttributes:(NSOpenGLPixelFormatAttribute[])
{
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 32,
nil
}];
self = [super initWithFrame:frameRect pixelFormat:pixelFormat];
[[self openGLContext] makeCurrentContext];
}
所以我有另一個名爲「MyViewController.h/m」的類處理我的視圖? 並且我有我的MyOpenGLView * myView。 在.m文件我一起去是這樣的:
myView = [[MyOpenGLView alloc] initWithFrame:CGRectMake(0,0,100.0,100.0)];
if (!myView) { NSLog(@"ERROR"); }
,當然還有,我得到的錯誤。
在我的窗口應用程序中沒有移植openGL視圖。我會猜測它關於方法被調用的層次結構,但之後再次..我不知道。你可以幫助我嗎?
self.view = [[OpenGLViewCoreProfile alloc] initWithFrame:mainDisplayRect pixelFormat:pix]; - 你不是在這裏啓動視圖嗎? – Bisder 2012-01-25 09:23:50
是的。但是我沒有寫我自己的'initWithFrame:pixelFormat:'方法。我依靠從NSOpenGLView繼承的方法。 – user1139069 2012-01-26 01:35:11