3

이 질문이 사소하거나 넌센스 인 경우 미리 사과드립니다 ... 이것은 내가 개발중인 첫 번째 앱 중 하나입니다. (Unfortunatley) 저는 개발자가 아닙니다.OpenGL 3.2 코어가있는 NSOpenGLView

NSOpenGLView의 하위 클래스 인 사용자 지정보기가 포함 된 NSWindow가 있습니다. NSWindowNSOpenGLView 이후

이 인터페이스 빌더를 통해 생성, 나는 initNSOpenGLContextNSOpenGLPixelFormat 할 필요가 없습니다.

저는 최근에 OS X Lion으로 전환했으며 새로운 OpenGL 3.2를 활용하려고합니다. NSOpenGLContext을 초기화하기 전에

NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = 
    { 
     NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, 
     0 
    }; 

    NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; 
    NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease]; 

: 애플의 문서에서

나는 OpenGL을 3.2 단순히 뭔가를 쓸 필요가 가능하도록 것을 알아 냈다.

이것은 (내게조차도) 꽤 쉽지만, 결코 내 앱에서 이것을 구현할 수 있습니까? initNSOpenGLContext?

NSOpenGLView은 Interface Builder에서 작성되었으므로 -initWithFormat:shareContext: 메서드는 호출되지 않습니다.

-(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]; 
} 

glGetString(GL_VERSION)으로보고 있지만, 생성 된 컨텍스트가 더 이상 응용 프로그램과 상호 작용으로는 OpenGL 3.2를 제대로 넣었는 ... 아무것도 없다 :

그러므로 나는이 같은으로 -initWithCoder: 메소드를 오버라이드 (override) 시도 보기에서 그려진.

내가 아는 모든 것을 시도했지만 ... 나는 이것을 해결할 수 없다.

대신 어떻게해야합니까?

답변

1

당신의 코드는 OpenGL 2.1 기반으로 들립니다. OpenGL 3.2 in Lion은 코어 프로필 (호환 프로필 없음) 만 지원합니다. 즉, 모든 고정 기능 파이프 라인 (예 : glBegin/End, glVertex, glPushMatrix, glMultMatrix)이 모두 완료되었음을 의미합니다.

코드를 대단히 업데이트해야합니다. 이미 VBO를 사용하면 작업량이 줄어 듭니다.

4

NSOpenGLView에는 setOpenGLContext 메서드가 있습니다. 그렇게 3.2 컨텍스트를 뷰에 전달하고 나중에 NSOpenGLContext에서 setView를 호출하십시오.

나는 이것을 테스트하지는 않았지만 방금 자신의 OpenGL보기를 만들었지 만 작동 할 것입니다.

0

내 하위 클래스의 awakeFromNib에서 [setPixelFormat ...]을 사용하면 나에게 도움이된다.하지만 필자는 문서에서 아무것도 약속하지 않기 때문에 불편 함을 느낀다.

이 재정의는 Interface Builder의 모든 설정입니다. 인터페이스 형식 작성기에서 선택한 형식에 필요한 픽셀 형식을 추가하기 위해 픽셀 형식을 검사하는 비 권장되지 않는 방법을 볼 수 없습니다.

IB 사람들이 거기에 정보를 추가하거나 NSOpenGLView 클래스가 하위 클래스에 대한 메커니즘을 f에 추가하기를 바랍니다.