Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created August 5, 2012 02:49
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 C4Code/3261245 to your computer and use it in GitHub Desktop.
Save C4Code/3261245 to your computer and use it in GitHub Desktop.
Recreation of Openframeworks graphicsExample
//
// C4WorkSpace.m
// Examples
//
// Created by Travis Kirton
//
#import "C4WorkSpace.h"
#import "SquaresGL.h"
@implementation C4WorkSpace {
C4GL *gl;
C4Shape *circle1, *circle2;
C4Shape *greenRect, *redRect1, *redRect2;
}
-(void)setup {
//circles
circle1 = [C4Shape ellipse:CGRectMake(0,0,100,100)];
circle1.center = CGPointMake(140,420);
circle1.lineWidth = 1.0f;
circle1.fillColor = [UIColor clearColor];
circle1.strokeColor = [UIColor colorWithWhite:0.7 alpha:1.0f];
[self.canvas addShape:circle1];
circle2 = [C4Shape ellipse:CGRectMake(0, 0, 70, 70)];
circle2.center = circle1.center;
circle2.fillColor = [UIColor orangeColor];
circle2.lineWidth = 0.0f;
[self.canvas addShape:circle2];
//opengl
gl = [[C4GL alloc] initWithRenderer:[SquaresGL new]];
gl.frame = CGRectMake(0,0,80,80);
gl.center = CGPointMake(140, 300);
[self.canvas addGL:gl];
//transparency squares
greenRect = [C4Shape rect:CGRectMake(0, 0, 70, 70)];
greenRect.origin = CGPointMake(100, 180);
greenRect.fillColor = [UIColor greenColor];
greenRect.lineWidth = 0.0f;
[self.canvas addShape:greenRect];
redRect1 = [C4Shape rect:CGRectMake(0, 0, 22, 70)];
redRect1.fillColor = [UIColor redColor];
redRect1.alpha = 0.0f;
redRect1.lineWidth = 0.0f;
redRect1.origin = CGPointMake(115, 145);
[self.canvas addShape:redRect1];
redRect2 = [C4Shape rect:CGRectMake(0, 0, 22, 70)];
redRect2.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.33];
redRect2.lineWidth = 0.0f;
redRect2.origin = CGPointMake(156, 145);
[self.canvas addShape:redRect2];
for(int i = 0; i < 20; i++) {
CGPoint endPoints[2] = {CGPointMake(50+i*3, 100), CGPointMake(25+i*6, 0)};
C4Shape *l = [C4Shape line:endPoints];
l.lineWidth = 1.0f;
[self.canvas addShape:l];
}
C4Label *label;
label = [C4Label labelWithText:@"circle"];
label.center = CGPointMake(160, 420);
label.rotation = PI;
[self.canvas addLabel:label];
}
@end
//
// SquaresGL.h
// C4iOS
//
// Created by Travis Kirton
//
#import "C4EAGLES1Renderer.h"
@interface SquaresGL : C4EAGLES1Renderer
@end
//
// SquaresGL.m
// C4iOS
//
// Created by moi on 12-08-03.
// Copyright (c) 2012 POSTFL. All rights reserved.
//
#import "SquaresGL.h"
@implementation SquaresGL
-(void)render {
[EAGLContext setCurrentContext:self.eaglContext];
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//reigns in the drawing area because the layer will clip to its viewport
glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, self.frameBuffer);
glViewport(0, 0, self.width, self.height);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
for(int i = 0; i < 200; i ++){
GLfloat x = ((random()%180)-100)/100.0f;
GLfloat y = ((random()%180)-100)/100.0f;
GLfloat w = (0.1f + (random()%10)/50.0f);
GLfloat squareVertices[8] = {
x,y,
x+w, y,
x, y+w,
x+w, y+w,
};
GLfloat r = (random()%255)/255.0f;
GLfloat g = (random()%255)/255.0f;
GLfloat b = (random()%255)/255.0f;
glColor4f(r,g,b, 1.0);
glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glDisableClientState(GL_VERTEX_ARRAY);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, self.renderBuffer);
[self.eaglContext presentRenderbuffer:GL_RENDERBUFFER_OES];
glFinish();
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment