Skip to content

Instantly share code, notes, and snippets.

@mogeta
Created August 21, 2012 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogeta/3409830 to your computer and use it in GitHub Desktop.
Save mogeta/3409830 to your computer and use it in GitHub Desktop.
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