OpenGL 3.2 w / NSOpenGLView

How to create a main profile in a custom implementation of NSOpenGLView? Which method should I override and what code should I put there?

So far I have this code:

// Header File #import <Cocoa/Cocoa.h> @interface TCUOpenGLView : NSOpenGLView @end // Source File #import "TCUOpenGLView.h" #import <OpenGL/gl.h> @implementation TCUOpenGLView - (void)drawRect:(NSRect)dirtyRect { glClear(GL_COLOR_BUFFER_BIT); glFlush(); } @end 
+6
source share
1 answer

Apple has a sample GLEssentials project code that shows how to do this (note that this is Mac OS X and iOS sample project code).

Essentially, you need to subclass NSOpenGLView (the NSGLView class in the sample code) and implement the awakeFromNib method using the following:

 - (void) awakeFromNib { NSOpenGLPixelFormatAttribute attrs[] = { NSOpenGLPFADoubleBuffer, NSOpenGLPFADepthSize, 24, // Must specify the 3.2 Core Profile to use OpenGL 3.2 NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, 0 }; NSOpenGLPixelFormat *pf = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease]; if (!pf) { NSLog(@"No OpenGL pixel format"); } NSOpenGLContext* context = [[[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil] autorelease]; [self setPixelFormat:pf]; [self setOpenGLContext:context]; } 

Also remember that if you use any OpenGL API calls that have been removed from the 3.2 API, your application will crash. Here is a PDF of specification 3.2 so you can see the changes.

+10
source

Source: https://habr.com/ru/post/921080/


All Articles