首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在NSWindow中绘制

在NSWindow中绘制
EN

Stack Overflow用户
提问于 2011-04-25 16:34:48
回答 1查看 962关注 0票数 2

我正在为一个图形框架做一个可可包装器。

为了最终画出这个东西,我这样做:

代码语言:javascript
复制
- (void)drawRect:(NSRect)rect
{
 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
 CGContextDrawImage(ctx, NSRectToCGRect(rect), image);
}

NSView的子类中。

现在我研究了其他框架,如Gosu,Irrlicht等,我发现它们总是在做复杂的NSOpenGL工作,比如:

代码语言:javascript
复制
// Settings, depending on fullscreen or not
NSOpenGLPixelFormatAttribute windowedAttrs[] =
{
 NSOpenGLPFADoubleBuffer,
 NSOpenGLPFAScreenMask,
 (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
 NSOpenGLPFADepthSize,
 (NSOpenGLPixelFormatAttribute)16,
 (NSOpenGLPixelFormatAttribute)0
};
NSOpenGLPixelFormatAttribute fullscreenAttrs[] =
{
 NSOpenGLPFADoubleBuffer,
 NSOpenGLPFAScreenMask,
 (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()),
 NSOpenGLPFAFullScreen,
 NSOpenGLPFADepthSize,
 (NSOpenGLPixelFormatAttribute)16,
 (NSOpenGLPixelFormatAttribute)0
};
NSOpenGLPixelFormatAttribute* attrs = fullscreen ? fullscreenAttrs : windowedAttrs;

// Create pixel format and OpenGL context
ObjRef<NSOpenGLPixelFormat> fmt(
  [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]);
::context = [[NSOpenGLContext alloc] initWithFormat: fmt.obj() shareContext:nil];

他们为什么要这么做?我的“简单”方式可以吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-10 07:26:49

我同意ryyst的观点。您正在使用CGContext,它本质上是Quartz 2DAPI。OpenGL是图形的另一种选择,特别适用于复杂的3D渲染。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5776656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档