Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "MyOpenGLView.h"
- @implementation MyOpenGLView
- - (id)initWithFrame: (NSRect)frameRect pixelFormat: (NSOpenGLPixelFormat*)format;
- {
- self = [super initWithFrame:frameRect];
- if (self) {
- _pixelFormat = [format retain];
- [[NSNotificationCenter defaultCenter] addObserver: self
- selector: @selector(_surfaceNeedsUpdate:)
- name: NSViewGlobalFrameDidChangeNotification
- object: self];
- }
- return self;
- }
- - (NSOpenGLContext*) openGLContext
- {
- return _openGLContext;
- }
- - (void) _surfaceNeedsUpdate: (NSNotificationCenter*)notification
- {
- [self update];
- }
- - (void) lockFocus
- {
- NSOpenGLContext* context = [self openGLContext];
- [super lockFocus];
- if ([context view] != self)
- {
- [context setView: self];
- }
- [context makeCurrentContext];
- }
- - (void) drawRect
- {
- NSOpenGLContext* context = [self openGLContext];
- [context makeCurrentContext];
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1.0f, 0.85f, 0.35f);
- glBegin(GL_TRIANGLES);
- {
- glVertex3f( 0.0, 0.6, 0.0);
- glVertex3f( -0.2, -0.3, 0.0);
- glVertex3f( 0.2, -0.3 ,0.0);
- }
- glEnd();
- glFlush();
- [context flushBuffer];
- }
- - (void) viewDidMoveToWindow
- {
- NSOpenGLContext* context = [self openGLContext];
- [super viewDidMoveToWindow];
- if ([self window] == nil)
- [context clearDrawable];
- }
- - (void) update
- {
- [self drawRect];
- }
- - (NSOpenGLPixelFormat*) pixelFormat
- {
- return _pixelFormat;
- }
- - (void)dealloc
- {
- [super dealloc];
- }
- - (void)drawRect:(NSRect)dirtyRect
- {
- // Drawing code here.
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement