Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drawing to a Window or View
#import <Cocoa/Cocoa.h>
@interface MyOpenGLView : NSOpenGLView
{
}
- (void) drawRect: (NSRect) bounds;
@end
#import "MyOpenGLView.h"
#include <OpenGL/gl.h>
@implementation MyOpenGLView{
}
static void drawAnObject ()
{
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();
}
-(void) drawRect: (NSRect) bounds{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
drawAnObject();
glFlush();
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment