Skip to content

Instantly share code, notes, and snippets.

@DylanLukes
Created September 24, 2010 01:12
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 DylanLukes/594711 to your computer and use it in GitHub Desktop.
Save DylanLukes/594711 to your computer and use it in GitHub Desktop.
//
// CNWorldView+Drawing.m
// Concorde
//
// Created by Dylan Lukes on 9/22/10.
// Copyright 2010 Dylan Lukes. All rights reserved.
//
#import "CNWorldView+Drawing.h"
#import "Common.h"
#import <OpenGL/gl.h>
#import <GLUT/GLUT.h>
@implementation CNWorldView (Drawing)
- (void)setupOpenGL{
GLfloat width = [self bounds].size.width;
GLfloat height = [self bounds].size.height;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2*(width/height), 2*(width/height),
-2.0f, 2.0f,
-2.0f, 2.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
- (CVReturn)drawWithGL{
static const Vertex3D vertices[] = {
{-1.0f, 0.0f, -1.0f},
{-1.0f, 0.0f, 1.0f},
{ 1.0f, 0.0f, -1.0f},
{ 1.0f, 0.0f, 1.0f},
};
[[self openGLContext] makeCurrentContext];
// Reset matrices
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Perform isometric axis rotations
glRotatef(ISOANGLE, 1.0f, 0.0f, 0.0f); // around X 45°
glRotatef(-45.0f, 0.0f, 1.0f, 0.0f); // around Y 45° + rotation offset
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(0.41, 0.66, 0.25, 1.0);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
drawAxes();
//glColor4f(0.41, 0.66, 0.25, 1.0);
//glutWireCube(1);
glDisableClientState(GL_VERTEX_ARRAY);
glSwapAPPLE();
return kCVReturnSuccess;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment