-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base features implemented, work on windows and iPhone
- Loading branch information
unknown
authored and
unknown
committed
Jan 5, 2010
0 parents
commit 2eefda6
Showing
129 changed files
with
14,822 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// EAGLView.h | ||
// sample | ||
// | ||
// Created by alexey on 1/4/10. | ||
// Copyright __MyCompanyName__ 2010. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
#import "ESRenderer.h" | ||
|
||
// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. | ||
// The view content is basically an EAGL surface you render your OpenGL scene into. | ||
// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. | ||
@interface EAGLView : UIView | ||
{ | ||
@private | ||
id <ESRenderer> renderer; | ||
|
||
BOOL animating; | ||
BOOL displayLinkSupported; | ||
NSInteger animationFrameInterval; | ||
// Use of the CADisplayLink class is the preferred method for controlling your animation timing. | ||
// CADisplayLink will link to the main display and fire every vsync when added to a given run-loop. | ||
// The NSTimer class is used only as fallback when running on a pre 3.1 device where CADisplayLink | ||
// isn't available. | ||
id displayLink; | ||
NSTimer *animationTimer; | ||
} | ||
|
||
@property (readonly, nonatomic, getter=isAnimating) BOOL animating; | ||
@property (nonatomic) NSInteger animationFrameInterval; | ||
|
||
- (void) startAnimation; | ||
- (void) stopAnimation; | ||
- (void) drawView:(id)sender; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// | ||
// EAGLView.m | ||
// sample | ||
// | ||
// Created by alexey on 1/4/10. | ||
// Copyright __MyCompanyName__ 2010. All rights reserved. | ||
// | ||
|
||
#import "EAGLView.h" | ||
|
||
#import "ES1Renderer.h" | ||
#import "ES2Renderer.h" | ||
|
||
@implementation EAGLView | ||
|
||
@synthesize animating; | ||
@dynamic animationFrameInterval; | ||
|
||
// You must implement this method | ||
+ (Class) layerClass | ||
{ | ||
return [CAEAGLLayer class]; | ||
} | ||
|
||
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder: | ||
- (id) initWithCoder:(NSCoder*)coder | ||
{ | ||
if ((self = [super initWithCoder:coder])) | ||
{ | ||
// Get the layer | ||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; | ||
|
||
eaglLayer.opaque = TRUE; | ||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: | ||
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; | ||
|
||
//renderer = [[ES2Renderer alloc] init]; | ||
|
||
if (!renderer) | ||
{ | ||
renderer = [[ES1Renderer alloc] init]; | ||
|
||
if (!renderer) | ||
{ | ||
[self release]; | ||
return nil; | ||
} | ||
} | ||
|
||
animating = FALSE; | ||
displayLinkSupported = FALSE; | ||
animationFrameInterval = 1; | ||
displayLink = nil; | ||
animationTimer = nil; | ||
|
||
// A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer | ||
// class is used as fallback when it isn't available. | ||
NSString *reqSysVer = @"3.1"; | ||
NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; | ||
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) | ||
displayLinkSupported = TRUE; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void) drawView:(id)sender | ||
{ | ||
[renderer render]; | ||
} | ||
|
||
- (void) layoutSubviews | ||
{ | ||
[renderer resizeFromLayer:(CAEAGLLayer*)self.layer]; | ||
[self drawView:nil]; | ||
} | ||
|
||
- (NSInteger) animationFrameInterval | ||
{ | ||
return animationFrameInterval; | ||
} | ||
|
||
- (void) setAnimationFrameInterval:(NSInteger)frameInterval | ||
{ | ||
// Frame interval defines how many display frames must pass between each time the | ||
// display link fires. The display link will only fire 30 times a second when the | ||
// frame internal is two on a display that refreshes 60 times a second. The default | ||
// frame interval setting of one will fire 60 times a second when the display refreshes | ||
// at 60 times a second. A frame interval setting of less than one results in undefined | ||
// behavior. | ||
if (frameInterval >= 1) | ||
{ | ||
animationFrameInterval = frameInterval; | ||
|
||
if (animating) | ||
{ | ||
[self stopAnimation]; | ||
[self startAnimation]; | ||
} | ||
} | ||
} | ||
|
||
- (void) startAnimation | ||
{ | ||
if (!animating) | ||
{ | ||
if (displayLinkSupported) | ||
{ | ||
// CADisplayLink is API new to iPhone SDK 3.1. Compiling against earlier versions will result in a warning, but can be dismissed | ||
// if the system version runtime check for CADisplayLink exists in -initWithCoder:. The runtime check ensures this code will | ||
// not be called in system versions earlier than 3.1. | ||
|
||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(drawView:)]; | ||
[displayLink setFrameInterval:animationFrameInterval]; | ||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; | ||
} | ||
else | ||
animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * animationFrameInterval) target:self selector:@selector(drawView:) userInfo:nil repeats:TRUE]; | ||
|
||
animating = TRUE; | ||
} | ||
} | ||
|
||
- (void)stopAnimation | ||
{ | ||
if (animating) | ||
{ | ||
if (displayLinkSupported) | ||
{ | ||
[displayLink invalidate]; | ||
displayLink = nil; | ||
} | ||
else | ||
{ | ||
[animationTimer invalidate]; | ||
animationTimer = nil; | ||
} | ||
|
||
animating = FALSE; | ||
} | ||
} | ||
|
||
- (void) dealloc | ||
{ | ||
[renderer release]; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ES1Renderer.h | ||
// sample | ||
// | ||
// Created by alexey on 1/4/10. | ||
// Copyright __MyCompanyName__ 2010. All rights reserved. | ||
// | ||
|
||
#import "ESRenderer.h" | ||
|
||
#import <OpenGLES/ES1/gl.h> | ||
#import <OpenGLES/ES1/glext.h> | ||
|
||
@interface ES1Renderer : NSObject <ESRenderer> | ||
{ | ||
@private | ||
EAGLContext *context; | ||
|
||
// The pixel dimensions of the CAEAGLLayer | ||
GLint backingWidth; | ||
GLint backingHeight; | ||
|
||
// The OpenGL names for the framebuffer and renderbuffer used to render to this view | ||
GLuint defaultFramebuffer, colorRenderbuffer; | ||
} | ||
|
||
- (void) render; | ||
- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// | ||
// ES1Renderer.m | ||
// sample | ||
// | ||
// Created by alexey on 1/4/10. | ||
// Copyright __MyCompanyName__ 2010. All rights reserved. | ||
// | ||
|
||
#import "ES1Renderer.h" | ||
#import "SEMain.h" | ||
|
||
#define DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0 * 3.14f) | ||
#include <cmath> | ||
|
||
@implementation ES1Renderer | ||
|
||
// Create an ES 1.1 context | ||
- (id) init | ||
{ | ||
if (self = [super init]) | ||
{ | ||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; | ||
|
||
if (!context || ![EAGLContext setCurrentContext:context]) | ||
{ | ||
[self release]; | ||
return nil; | ||
} | ||
|
||
// Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer | ||
glGenFramebuffersOES(1, &defaultFramebuffer); | ||
glGenRenderbuffersOES(1, &colorRenderbuffer); | ||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); | ||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); | ||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer); | ||
|
||
glViewport(0, 0, 320, 480); | ||
|
||
glMatrixMode(GL_PROJECTION); | ||
glLoadIdentity(); | ||
|
||
const GLfloat zNear = 0.1; | ||
GLfloat zFar = 100.0; | ||
GLfloat fieldOfView = 60.0; | ||
GLfloat size; | ||
GLfloat window_width = 320; | ||
GLfloat window_height = 480; | ||
|
||
//glEnable(GL_DEPTH_TEST); | ||
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0); | ||
glFrustumf(-size, size, -size / (window_width / window_height), size / (window_width / window_height), zNear, zFar); | ||
glMatrixMode(GL_MODELVIEW); | ||
|
||
SEPath currentPath; | ||
SEPath::CurrentDirectory(¤tPath); | ||
currentPath.AppendName("objects"); | ||
|
||
SELoader loader; | ||
loader.Load( ¤tPath ); | ||
|
||
BREAKPOINTPLACE; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void) render | ||
{ | ||
// Replace the implementation of this method to do your own custom drawing | ||
|
||
static const GLfloat squareVertices[] = { | ||
-0.5f, -0.33f, | ||
0.5f, -0.33f, | ||
-0.5f, 0.33f, | ||
0.5f, 0.33f, | ||
}; | ||
|
||
static const GLubyte squareColors[] = { | ||
255, 255, 0, 255, | ||
0, 255, 255, 255, | ||
0, 0, 0, 0, | ||
255, 0, 255, 255, | ||
}; | ||
|
||
static float transY = 0.0f; | ||
|
||
// This application only creates a single context which is already set current at this point. | ||
// This call is redundant, but needed if dealing with multiple contexts. | ||
[EAGLContext setCurrentContext:context]; | ||
|
||
// This application only creates a single default framebuffer which is already bound at this point. | ||
// This call is redundant, but needed if dealing with multiple framebuffers. | ||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer); | ||
|
||
glLoadIdentity(); | ||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
|
||
static float angle = 0; | ||
angle += 0.1f; | ||
|
||
glTranslatef(0,0,-5); | ||
glRotatef(angle,1,1,0); | ||
|
||
SEMeshPtr mesh = SEObjectStore::sharedInstance()->GetMesh("Cube"); | ||
mesh->Draw(); | ||
|
||
glRotatef(-angle,1,1,0); | ||
glTranslatef(0,0,5); | ||
|
||
/* | ||
glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f); | ||
transY += 0.075f; | ||
glVertexPointer(2, GL_FLOAT, 0, squareVertices); | ||
glEnableClientState(GL_VERTEX_ARRAY); | ||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors); | ||
glEnableClientState(GL_COLOR_ARRAY); | ||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | ||
*/ | ||
|
||
// This application only creates a single color renderbuffer which is already bound at this point. | ||
// This call is redundant, but needed if dealing with multiple renderbuffers. | ||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); | ||
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; | ||
} | ||
|
||
- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer | ||
{ | ||
// Allocate color buffer backing based on the current layer size | ||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer); | ||
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer]; | ||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); | ||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); | ||
|
||
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) | ||
{ | ||
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES)); | ||
return NO; | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
- (void) dealloc | ||
{ | ||
// Tear down GL | ||
if (defaultFramebuffer) | ||
{ | ||
glDeleteFramebuffersOES(1, &defaultFramebuffer); | ||
defaultFramebuffer = 0; | ||
} | ||
|
||
if (colorRenderbuffer) | ||
{ | ||
glDeleteRenderbuffersOES(1, &colorRenderbuffer); | ||
colorRenderbuffer = 0; | ||
} | ||
|
||
// Tear down context | ||
if ([EAGLContext currentContext] == context) | ||
[EAGLContext setCurrentContext:nil]; | ||
|
||
[context release]; | ||
context = nil; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
@end |
Oops, something went wrong.