我正在尝试在Mac OS X上设置OpenGL上下文,而不使用GLUT或类似的东西。这是我到目前为止所做的。
CGLPixelFormatAttribute pixelFormatAttributes[] = {
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
kCGLPFAColorSize, (CGLPixelFormatAttribute) 24,
kCGLPFAAlphaSize, (CGLPixelFormatAttribute) 8,
kCGLPFAAccelerated,
kCGLPFAFullScreen,
kCGLPFADoubleBuffer,
kCGLPFASampleBuffers, (CGLPixelFormatAttribute) 1,
kCGLPFASamples, (CGLPixelFormatAttribute) 4,
(CGLPixelFormatAttribute) 0,
};
CGLPixelFormatObj pixelFormat;
GLint numberOfPixels;
CGLChoosePixelFormat(pixelFormatAttributes, &pixelFormat, &numberOfPixels);
CGLContextObj contextObject;
CGLCreateContext(pixelFormat, 0, &contextObject);
CGLDestroyPixelFormat(pixelFormat);
CGLSetCurrentContext(contextObject);
// OpenGL stuff here
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_POLYGON);
glVertex3f(0.25f, 0.25f, 0.0f);
glVertex3f(0.75f, 0.25f, 0.0f);
glVertex3f(0.75f, 0.75f, 0.0f);
glVertex3f(0.25f, 0.75f, 0.0f);
glEnd();
glFlush();
CGLSetCurrentContext(NULL);
CGLDestroyContext(contextObject);
但这不起作用,我在这里遗漏了什么吗?
答案 0 :(得分:1)
您正在执行您所描述的内容 - 您创建了一个OpenGL上下文。您可能对OpenGL上下文的含义有错误的理解。它只是一个包含OpenGL实例的抽象实体。它不是用户直接可见的任何内容,例如包含OpenGL表面的窗口。
使用OpenGL无法创建用户界面元素,因为OpenGL不是用户界面库。当你说“不使用GLUT或类似的东西”时,你说你不想创建OpenGL上下文可以呈现的可见表面。
要实际创建一个窗口 - 无论是普通窗口还是全屏幕 - 您需要使用GLUT或GLFW等用户界面库。由于您似乎正在构建仅支持OSX的应用程序,因此您可能希望使用AppKit / Cocoa,除非您对ObjC不满意。
答案 1 :(得分:0)
您似乎必须使用CGLSetFullScreenOnDisplay()
来“打开窗口”。