Reputation: 33
I'm trying to set up an OpenGL context on Mac OS X without using GLUT or anything of the likes. This is what I have so far.
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);
But this doesn't work, am I missing something here?
Upvotes: 1
Views: 3267
Reputation: 1
It seems you have to use CGLSetFullScreenOnDisplay()
to "open the window".
Upvotes: 0
Reputation: 39768
You are doing what you describe - you create an OpenGL context. You may have a wrong understanding about what an OpenGL context is. It is just an abstract entity that contains an OpenGL instance. It is not anything that is directly visible to the user, like a window containing an OpenGL surface.
Creating user interface elements is not possible with OpenGL, because OpenGL is not a user interface library. When you say "without using GLUT or anything of the likes", you're saying that you do not want to create a visible surface your OpenGL context can render to.
To actually create a window - be it a normal or fullscreen - you need to use a user interface library like GLUT or GLFW. As you seem to be building an OSX-only application, you probably want to use AppKit/Cocoa, unless you're not comfortable with ObjC.
Upvotes: 1