我有一個簡單的遊戲,將2D圖形渲染到幀緩衝區(不使用任何OpenGL)。我打算使用CVDisplayLink來獲得一個清晰的幀率,然而網上的大多數例子都是用OpenGL或者QuickTime來處理的。如何從CVDisplayLink回調中繪製到NSView圖形上下文?
到目前爲止,我有一個子類的NSView的:
@interface GameView : NSView {
@private
CVDisplayLinkRef displayLink;
}
- (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime;
@end
我成立了CVDisplayLink回調:
CVDisplayLinkSetOutputCallback(displayLink, MyDisplayLinkCallback, self);
和我有回調函數:
我卡住的部分是在getFrameForTime:
中做什麼來繪製到GameVi中的圖形上下文EW。我的第一個猜測是做畫一樣,你會方式drawRect:
- (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime
{
CGContextRef ctxCurrent = [[NSGraphicsContext currentContext] graphicsPort];
//.. Drawing code follows
}
但ctxCurrent
是nil
我想我明白 - 通常有一些設置的drawRect:
,使您的視圖當前上下文之前出現這種情況。我認爲這是我錯過的部分。我如何獲得我的觀點的背景?
或者我是否以所有錯誤的方式去解決這個問題?
謝謝,這是工作,似乎是迄今爲止我發現最清潔。 – John