Changeset 739
- Timestamp:
- Mar 13, 2011, 1:58:53 AM (11 years ago)
- Location:
- trunk/monsterz/ios
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/monsterz/ios/classes/EAGLView.h
r731 r739 1 1 // 2 // EAGLView.h 3 // Monsterz 2 // Monsterz 4 3 // 5 // Created by user on 05.03.11. 6 // Copyright 2011 __MyCompanyName__. All rights reserved. 4 // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the Do What The Fuck You Want To 7 // Public License, Version 2, as published by Sam Hocevar. See 8 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 7 9 // 8 10 … … 14 16 #import <OpenGLES/ES2/glext.h> 15 17 16 // This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. 17 // The view content is basically an EAGL surface you render your OpenGL scene into. 18 // Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. 18 // This class wraps the CAEAGLLayer from CoreAnimation into a convenient 19 // UIView subclass. The view content is basically an EAGL surface you 20 // render your OpenGL scene into. Note that setting the view non-opaque 21 // will only work if the EAGL surface has an alpha channel. 19 22 @interface EAGLView : UIView 20 23 { 21 24 @private 22 25 EAGLContext *context; 23 26 24 27 // The pixel dimensions of the CAEAGLLayer. 25 28 GLint framebufferWidth; 26 29 GLint framebufferHeight; 27 28 // The OpenGL ES names for the framebuffer and renderbuffer used to render to this view. 30 31 // The OpenGL ES names for the framebuffer and renderbuffer used to 32 // render to this view. 29 33 GLuint defaultFramebuffer, colorRenderbuffer; 30 34 } … … 36 40 37 41 @end 42 -
trunk/monsterz/ios/classes/EAGLView.m
r731 r739 1 1 // 2 // EAGLView.m 3 // Monsterz 2 // Monsterz 4 3 // 5 // Created by user on 05.03.11. 6 // Copyright 2011 __MyCompanyName__. All rights reserved. 4 // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the Do What The Fuck You Want To 7 // Public License, Version 2, as published by Sam Hocevar. See 8 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 7 9 // 8 10 … … 26 28 } 27 29 28 //The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:. 30 // The EAGL view is stored in the nib file. When it's unarchived it's sent 31 // -initWithCoder:. 29 32 - (id)initWithCoder:(NSCoder*)coder 30 33 { 31 34 self = [super initWithCoder:coder]; 32 35 if (self) 33 36 { 34 37 CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; 35 38 36 39 eaglLayer.opaque = TRUE; 37 40 eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: … … 40 43 nil]; 41 44 } 42 45 43 46 return self; 44 47 } … … 46 49 - (void)dealloc 47 50 { 48 [self deleteFramebuffer]; 51 [self deleteFramebuffer]; 49 52 [context release]; 50 51 53 [super dealloc]; 52 54 } … … 62 64 { 63 65 [self deleteFramebuffer]; 64 65 66 [context release]; 66 67 context = [newContext retain]; 67 68 68 [EAGLContext setCurrentContext:nil]; 69 69 } … … 75 75 { 76 76 [EAGLContext setCurrentContext:context]; 77 77 78 78 // Create default framebuffer object. 79 79 glGenFramebuffers(1, &defaultFramebuffer); 80 80 glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); 81 81 82 82 // Create color render buffer and allocate backing store. 83 83 glGenRenderbuffers(1, &colorRenderbuffer); … … 86 86 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth); 87 87 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight); 88 88 89 89 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer); 90 90 91 91 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 92 92 NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); … … 99 99 { 100 100 [EAGLContext setCurrentContext:context]; 101 101 102 102 if (defaultFramebuffer) 103 103 { … … 105 105 defaultFramebuffer = 0; 106 106 } 107 107 108 108 if (colorRenderbuffer) 109 109 { … … 119 119 { 120 120 [EAGLContext setCurrentContext:context]; 121 121 122 122 if (!defaultFramebuffer) 123 123 [self createFramebuffer]; 124 124 125 125 glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); 126 127 126 glViewport(0, 0, framebufferWidth, framebufferHeight); 128 127 } … … 132 131 { 133 132 BOOL success = FALSE; 134 133 135 134 if (context) 136 135 { 137 136 [EAGLContext setCurrentContext:context]; 138 139 137 glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer); 140 141 138 success = [context presentRenderbuffer:GL_RENDERBUFFER]; 142 139 } 143 140 144 141 return success; 145 142 } … … 147 144 - (void)layoutSubviews 148 145 { 149 // The framebuffer will be re-created at the beginning of the next setFramebuffer method call. 146 // The framebuffer will be re-created at the beginning of the next 147 // setFramebuffer method call. 150 148 [self deleteFramebuffer]; 151 149 } 152 150 153 151 @end 152 -
trunk/monsterz/ios/classes/MonsterzAppDelegate.h
r731 r739 1 1 // 2 // MonsterzAppDelegate.h 3 // Monsterz 2 // Monsterz 4 3 // 5 // Created by user on 05.03.11. 6 // Copyright 2011 __MyCompanyName__. All rights reserved. 4 // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the Do What The Fuck You Want To 7 // Public License, Version 2, as published by Sam Hocevar. See 8 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 7 9 // 8 10 … … 11 13 @class MonsterzViewController; 12 14 13 @interface MonsterzAppDelegate : NSObject <UIApplicationDelegate> { 15 @interface MonsterzAppDelegate : NSObject <UIApplicationDelegate> 16 { 14 17 UIWindow *window; 15 18 MonsterzViewController *viewController; -
trunk/monsterz/ios/classes/MonsterzAppDelegate.m
r731 r739 1 1 // 2 // MonsterzAppDelegate.m 3 // Monsterz 2 // Monsterz 4 3 // 5 // Created by user on 05.03.11. 6 // Copyright 2011 __MyCompanyName__. All rights reserved. 4 // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the Do What The Fuck You Want To 7 // Public License, Version 2, as published by Sam Hocevar. See 8 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 7 9 // 8 10 … … 50 52 [viewController release]; 51 53 [window release]; 52 53 54 [super dealloc]; 54 55 } 55 56 56 57 @end 58 -
trunk/monsterz/ios/classes/MonsterzViewController.h
r731 r739 1 1 // 2 // MonsterzViewController.h 3 // Monsterz 2 // Monsterz 4 3 // 5 // Created by user on 05.03.11. 6 // Copyright 2011 __MyCompanyName__. All rights reserved. 4 // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the Do What The Fuck You Want To 7 // Public License, Version 2, as published by Sam Hocevar. See 8 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 7 9 // 8 10 … … 19 21 { 20 22 EAGLContext *context; 21 23 22 24 BOOL animating; 23 25 NSInteger animationFrameInterval; … … 32 34 33 35 @end 36 -
trunk/monsterz/ios/classes/MonsterzViewController.mm
r731 r739 1 1 // 2 // MonsterzViewController.m 3 // Monsterz 2 // Monsterz 4 3 // 5 // Created by user on 05.03.11. 6 // Copyright 2011 __MyCompanyName__. All rights reserved. 4 // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the Do What The Fuck You Want To 7 // Public License, Version 2, as published by Sam Hocevar. See 8 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 7 9 // 8 10 … … 31 33 - (void)awakeFromNib 32 34 { 33 34 35 36 37 38 35 Ticker::Setup(30.0f); 36 Video::Setup(320, 480); 37 38 new Interface(); 39 new DebugFps(20, 20); 40 39 41 EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1]; 40 42 if (!aContext) … … 42 44 else if (![EAGLContext setCurrentContext:aContext]) 43 45 NSLog(@"Failed to set ES context current"); 44 45 46 47 46 47 self.context = aContext; 48 [aContext release]; 49 48 50 [(EAGLView *)self.view setContext:context]; 49 51 [(EAGLView *)self.view setFramebuffer]; 50 52 51 53 animating = FALSE; 52 54 animationFrameInterval = 1; … … 59 61 if ([EAGLContext currentContext] == context) 60 62 [EAGLContext setCurrentContext:nil]; 61 63 62 64 [context release]; 63 64 65 [super dealloc]; 65 66 } … … 68 69 { 69 70 [self startAnimation]; 70 71 71 [super viewWillAppear:animated]; 72 72 } … … 75 75 { 76 76 [self stopAnimation]; 77 78 77 [super viewWillDisappear:animated]; 79 78 } … … 81 80 - (void)viewDidUnload 82 81 { 83 82 [super viewDidUnload]; 84 83 85 84 // Tear down context. 86 85 if ([EAGLContext currentContext] == context) 87 86 [EAGLContext setCurrentContext:nil]; 88 self.context = nil; 87 self.context = nil; 89 88 } 90 89 … … 96 95 - (void)setAnimationFrameInterval:(NSInteger)frameInterval 97 96 { 98 /* 99 Frame interval defines how many display frames must pass between each time the display link fires. 100 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. 101 */ 97 /* Frame interval defines how many display frames must pass between each 98 * time the display link fires. The display link will only fire 30 times 99 * a second when the frame internal is two on a display that refreshes 100 * 60 times a second. The default frame interval setting of one will 101 * fire 60 times a second when the display refreshes at 60 times a 102 * second. A frame interval setting of less than one results in undefined 103 * behavior. */ 102 104 if (frameInterval >= 1) 103 105 { 104 106 animationFrameInterval = frameInterval; 105 107 106 108 if (animating) 107 109 { … … 120 122 [aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 121 123 self.displayLink = aDisplayLink; 122 124 123 125 animating = TRUE; 124 126 } … … 138 140 { 139 141 [(EAGLView *)self.view setFramebuffer]; 140 141 Ticker::ClampFps(); 142 Ticker::TickGame(); 143 Ticker::TickDraw(); 144 142 Ticker::ClampFps(); 143 Ticker::TickGame(); 144 Ticker::TickDraw(); 145 145 [(EAGLView *)self.view presentFramebuffer]; 146 146 } … … 150 150 // Releases the view if it doesn't have a superview. 151 151 [super didReceiveMemoryWarning]; 152 153 152 // Release any cached data, images, etc. that aren't in use. 154 153 } 155 154 156 155 @end 156 -
trunk/monsterz/ios/main.m
r731 r739 1 1 // 2 // main.m 3 // Monsterz 2 // Monsterz 4 3 // 5 // Created by user on 05.03.11. 6 // Copyright 2011 __MyCompanyName__. All rights reserved. 4 // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the Do What The Fuck You Want To 7 // Public License, Version 2, as published by Sam Hocevar. See 8 // http://sam.zoy.org/projects/COPYING.WTFPL for more details. 7 9 // 8 10 9 11 #import <UIKit/UIKit.h> 10 12 11 int main(int argc, char *argv[]) {12 13 int main(int argc, char *argv[]) 14 { 13 15 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 16 int retVal = UIApplicationMain(argc, argv, nil, nil);
Note: See TracChangeset
for help on using the changeset viewer.