There are few assumptions for properly understanding your question:
There is an API in which your app as a whole is being developed, such as Cocoa API. Suppose this is what you meant by asking for “Preferably using Cocoa”.
The basic OpenGL drawing routines are plain-C, no matter if wrapped in GLUT, Cocoa or whatsoever.
There’s no such method as “Creating a window with OpenGL context” in Cocoa API, AFAIK. You first have to create a window as such, be it programmatically or be it using the Interface Builder.
You can use the Interface Builder (in Xcode) for setting up the window in which the OpenGL drawing should be displayed. The following is not a working code, it’s just a simplest case walk-through. You must then declare an interface, such as:
@interface myOpenGLView :NSOpenGLView
{
@public
//declare public members
@private
//declare private members
}
//declare properties and methods
- (void) drawRect: (NSRect) bounds;
@end
myOpenGLView *myView;
which is subclassing NSOpenGLView. Habitually this is written into a separate class .m and .h files, not in the AppDelegate.
Upon dragging the OpenGLView from the Objects Palette into your window make sure to declare it in Xcode right pane (Utilities area) as Custom Class myOpenGLView. Up to here I can’t imagine getting away without Objective-C. However,inside a method body, you still deal with traditional-style OpenGL-C.
-(void) drawRect: (NSRect) bounds
{
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
drawSomething();
glFlush();
}
The method which updates the drawing should not draw explicitly, but call the following method instead:
[self.myView setNeedsDisplay: YES];
Of course there’s much more to it, depending on the complexity of what you’re after. There are few simple examples which may help in starting your learning with OpenGL in OS X, such as:
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_drawing/opengl_drawing.html
or this:
Creating an OpenGL View without Interface Builder
or even this:
https://www.youtube.com/watch?v=7ModmPsxhug
but there’s nothing zippy or snappy about creating OpenGL views in Cocoa. It takes a bit of learning patience which pays off. I hope this can help.