我对 OpenGL 并不陌生,但也不是专家。许多教程教如何绘制、3D、2D、投影、正交等,但是设置 View 怎么样? (Cocoa、Mac 中的 NSOpenGLView)。
例如我有这个:
- (id) initWithFrame: (NSRect) frame
{
GLuint attribs[] = { //PF: PixelAttibutes
NSOpenGLPFANoRecovery,
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAStencilSize, 8,
NSOpenGLPFAAccumSize, 0,
0
};
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes: (NSOpenGLPixelFormatAttribute*) attribs];
return self = [super initWithFrame:frame pixelFormat: [fmt autorelease]];
}
而且我不太了解它们的用法,特别是在组合它们时。
例如:
如果我希望我的 View 能够全屏显示,我应该只编写 NSOpenGLPFAFullScreen 吗?或两者? (我所说的能力是指并不总是全屏)
关于双缓冲,这到底是什么? (下图:苹果的定义)
If present, this attribute indicates that only double-buffered pixel formats are considered. Otherwise, only single-buffered pixel formats are considered
关于颜色:如果 NSOpenGLPFAColorSize 是 24 并且 NSOpenGLPFAColorSize 是 8 那么这是否意味着 alpha 和 RGB 分量的处理方式不同?如果我将前者设置为 32,后者设置为 0,会发生什么情况?
等等等等,一般来说我如何学习从头开始设置我的 View ?
提前致谢。
伊格纳西奥。
最佳答案
关于颜色,我不完全确定差异。
关于双缓冲:假设您的帧速率较慢,为 3fps。如果需要三分之一秒才能在屏幕上绘制所有内容,那么您将在绘制时看到它们。例如,如果它是使用画家算法绘制的,您将首先看到背景多边形,然后您会看到更近的东西。另外,最后绘制的东西只会在被清除以绘制下一帧之前出现一瞬间。
双缓冲将所有内容渲染到屏幕外图像,然后将整个渲染图像放在屏幕上。因此,在渲染整个内容之前,您不会看到任何操作,但也不会看到不完整的帧。
了解更多,http://en.wikipedia.org/wiki/Multiple_buffering#Double_buffering_in_computer_graphics
关于cocoa - OpenGL像素格式属性(NSOpenGLPixelFormatAttibutes)解释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2782172/