Skip to content
Browse files

First Commit

  • Loading branch information...
0 parents commit d388af5052285d64b3b793d305b79a278b5ed521 @pppoe committed
305 GLRenderLargeImage.xcodeproj/project.pbxproj
@@ -0,0 +1,305 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 4609FFBC147CF92100464E4C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4609FFBB147CF92100464E4C /* UIKit.framework */; };
+ 4609FFBE147CF92100464E4C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4609FFBD147CF92100464E4C /* Foundation.framework */; };
+ 4609FFC0147CF92100464E4C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4609FFBF147CF92100464E4C /* CoreGraphics.framework */; };
+ 4609FFC6147CF92100464E4C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4609FFC4147CF92100464E4C /* InfoPlist.strings */; };
+ 4609FFC8147CF92100464E4C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4609FFC7147CF92100464E4C /* main.m */; };
+ 4609FFCC147CF92100464E4C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4609FFCB147CF92100464E4C /* AppDelegate.m */; };
+ 4609FFD7147CF97400464E4C /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4609FFD6147CF97400464E4C /* OpenGLES.framework */; };
+ 4609FFD9147CF98600464E4C /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4609FFD8147CF98600464E4C /* QuartzCore.framework */; };
+ 46610E01147E346B001ACD72 /* MPGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 46610DFF147E346B001ACD72 /* MPGLView.m */; };
+ 46610E05147E3487001ACD72 /* GLImageViewer.m in Sources */ = {isa = PBXBuildFile; fileRef = 46610E04147E3487001ACD72 /* GLImageViewer.m */; };
+ 46E96220147DE8750003B0AC /* pic.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 46E9621F147DE8750003B0AC /* pic.jpg */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 4609FFB7147CF92100464E4C /* GLRenderLargeImage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GLRenderLargeImage.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 4609FFBB147CF92100464E4C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+ 4609FFBD147CF92100464E4C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 4609FFBF147CF92100464E4C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
+ 4609FFC3147CF92100464E4C /* GLRenderLargeImage-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GLRenderLargeImage-Info.plist"; sourceTree = "<group>"; };
+ 4609FFC5147CF92100464E4C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ 4609FFC7147CF92100464E4C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 4609FFC9147CF92100464E4C /* GLRenderLargeImage-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GLRenderLargeImage-Prefix.pch"; sourceTree = "<group>"; };
+ 4609FFCA147CF92100464E4C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+ 4609FFCB147CF92100464E4C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ 4609FFD6147CF97400464E4C /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
+ 4609FFD8147CF98600464E4C /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ 46610DFE147E346B001ACD72 /* MPGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPGLView.h; sourceTree = "<group>"; };
+ 46610DFF147E346B001ACD72 /* MPGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPGLView.m; sourceTree = "<group>"; };
+ 46610E03147E3487001ACD72 /* GLImageViewer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLImageViewer.h; sourceTree = "<group>"; };
+ 46610E04147E3487001ACD72 /* GLImageViewer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLImageViewer.m; sourceTree = "<group>"; };
+ 46E9621F147DE8750003B0AC /* pic.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = pic.jpg; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 4609FFB4147CF92100464E4C /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 4609FFD9147CF98600464E4C /* QuartzCore.framework in Frameworks */,
+ 4609FFD7147CF97400464E4C /* OpenGLES.framework in Frameworks */,
+ 4609FFBC147CF92100464E4C /* UIKit.framework in Frameworks */,
+ 4609FFBE147CF92100464E4C /* Foundation.framework in Frameworks */,
+ 4609FFC0147CF92100464E4C /* CoreGraphics.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 4609FFAC147CF92000464E4C = {
+ isa = PBXGroup;
+ children = (
+ 46610E02147E3473001ACD72 /* Demo */,
+ 46610DFB147E346B001ACD72 /* MPGLView */,
+ 4609FFC1147CF92100464E4C /* GLRenderLargeImage */,
+ 4609FFBA147CF92100464E4C /* Frameworks */,
+ 4609FFB8147CF92100464E4C /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ 4609FFB8147CF92100464E4C /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 4609FFB7147CF92100464E4C /* GLRenderLargeImage.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 4609FFBA147CF92100464E4C /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 4609FFD8147CF98600464E4C /* QuartzCore.framework */,
+ 4609FFD6147CF97400464E4C /* OpenGLES.framework */,
+ 4609FFBB147CF92100464E4C /* UIKit.framework */,
+ 4609FFBD147CF92100464E4C /* Foundation.framework */,
+ 4609FFBF147CF92100464E4C /* CoreGraphics.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 4609FFC1147CF92100464E4C /* GLRenderLargeImage */ = {
+ isa = PBXGroup;
+ children = (
+ 4609FFCA147CF92100464E4C /* AppDelegate.h */,
+ 4609FFCB147CF92100464E4C /* AppDelegate.m */,
+ 4609FFC2147CF92100464E4C /* Supporting Files */,
+ );
+ path = GLRenderLargeImage;
+ sourceTree = "<group>";
+ };
+ 4609FFC2147CF92100464E4C /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 4609FFC3147CF92100464E4C /* GLRenderLargeImage-Info.plist */,
+ 4609FFC4147CF92100464E4C /* InfoPlist.strings */,
+ 4609FFC7147CF92100464E4C /* main.m */,
+ 4609FFC9147CF92100464E4C /* GLRenderLargeImage-Prefix.pch */,
+ 46E9621F147DE8750003B0AC /* pic.jpg */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ 46610DFB147E346B001ACD72 /* MPGLView */ = {
+ isa = PBXGroup;
+ children = (
+ 46610DFE147E346B001ACD72 /* MPGLView.h */,
+ 46610DFF147E346B001ACD72 /* MPGLView.m */,
+ );
+ name = MPGLView;
+ path = GLRenderLargeImage/MPGLView;
+ sourceTree = "<group>";
+ };
+ 46610E02147E3473001ACD72 /* Demo */ = {
+ isa = PBXGroup;
+ children = (
+ 46610E03147E3487001ACD72 /* GLImageViewer.h */,
+ 46610E04147E3487001ACD72 /* GLImageViewer.m */,
+ );
+ name = Demo;
+ path = GLRenderLargeImage/Demo;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 4609FFB6147CF92100464E4C /* GLRenderLargeImage */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 4609FFCF147CF92100464E4C /* Build configuration list for PBXNativeTarget "GLRenderLargeImage" */;
+ buildPhases = (
+ 4609FFB3147CF92100464E4C /* Sources */,
+ 4609FFB4147CF92100464E4C /* Frameworks */,
+ 4609FFB5147CF92100464E4C /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = GLRenderLargeImage;
+ productName = GLRenderLargeImage;
+ productReference = 4609FFB7147CF92100464E4C /* GLRenderLargeImage.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 4609FFAE147CF92100464E4C /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0420;
+ ORGANIZATIONNAME = DEV;
+ };
+ buildConfigurationList = 4609FFB1147CF92100464E4C /* Build configuration list for PBXProject "GLRenderLargeImage" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 4609FFAC147CF92000464E4C;
+ productRefGroup = 4609FFB8147CF92100464E4C /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 4609FFB6147CF92100464E4C /* GLRenderLargeImage */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 4609FFB5147CF92100464E4C /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 4609FFC6147CF92100464E4C /* InfoPlist.strings in Resources */,
+ 46E96220147DE8750003B0AC /* pic.jpg in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 4609FFB3147CF92100464E4C /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 4609FFC8147CF92100464E4C /* main.m in Sources */,
+ 4609FFCC147CF92100464E4C /* AppDelegate.m in Sources */,
+ 46610E01147E346B001ACD72 /* MPGLView.m in Sources */,
+ 46610E05147E3487001ACD72 /* GLImageViewer.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ 4609FFC4147CF92100464E4C /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 4609FFC5147CF92100464E4C /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 4609FFCD147CF92100464E4C /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ SDKROOT = iphoneos;
+ };
+ name = Debug;
+ };
+ 4609FFCE147CF92100464E4C /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
+ SDKROOT = iphoneos;
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ 4609FFD0147CF92100464E4C /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "GLRenderLargeImage/GLRenderLargeImage-Prefix.pch";
+ INFOPLIST_FILE = "GLRenderLargeImage/GLRenderLargeImage-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Debug;
+ };
+ 4609FFD1147CF92100464E4C /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "GLRenderLargeImage/GLRenderLargeImage-Prefix.pch";
+ INFOPLIST_FILE = "GLRenderLargeImage/GLRenderLargeImage-Info.plist";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 4609FFB1147CF92100464E4C /* Build configuration list for PBXProject "GLRenderLargeImage" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 4609FFCD147CF92100464E4C /* Debug */,
+ 4609FFCE147CF92100464E4C /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 4609FFCF147CF92100464E4C /* Build configuration list for PBXNativeTarget "GLRenderLargeImage" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 4609FFD0147CF92100464E4C /* Debug */,
+ 4609FFD1147CF92100464E4C /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 4609FFAE147CF92100464E4C /* Project object */;
+}
15 GLRenderLargeImage/AppDelegate.h
@@ -0,0 +1,15 @@
+//
+// AppDelegate.h
+// GLRenderLargeImage
+//
+// Created by Haoxiang Li on 11/23/11.
+// Copyright (c) 2011 DEV. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@end
77 GLRenderLargeImage/AppDelegate.m
@@ -0,0 +1,77 @@
+//
+// AppDelegate.m
+// GLRenderLargeImage
+//
+// Created by Haoxiang Li on 11/23/11.
+// Copyright (c) 2011 DEV. All rights reserved.
+//
+
+#import "AppDelegate.h"
+#import "GLImageViewer.h"
+
+@implementation AppDelegate
+
+@synthesize window = _window;
+
+- (void)dealloc
+{
+ [_window release];
+ [super dealloc];
+}
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
+ // Override point for customization after application launch.
+ self.window.backgroundColor = [UIColor whiteColor];
+ [self.window makeKeyAndVisible];
+
+ GLImageViewer *viewer = [[GLImageViewer alloc] initWithGLFrame:CGRectMake(0, 44, 320, 400)];
+ [viewer showImageNamed:@"pic.jpg"];
+ viewer.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.3f];
+ [self.window addSubview:viewer];
+ [viewer release];
+
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ /*
+ Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+ */
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application
+{
+ /*
+ Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+ */
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application
+{
+ /*
+ Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+ */
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ /*
+ Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+ */
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ /*
+ Called when the application is about to terminate.
+ Save data if appropriate.
+ See also applicationDidEnterBackground:.
+ */
+}
+
+@end
17 GLRenderLargeImage/Demo/GLImageViewer.h
@@ -0,0 +1,17 @@
+//
+// GLImageViewer.h
+// GLRenderLargeImage
+//
+// Created by Haoxiang Li on 11/24/11.
+// Copyright (c) 2011 DEV. All rights reserved.
+//
+
+#import "MPGLView.h"
+
+@interface GLImageViewer : MPGLView {
+ GLuint texture;
+}
+
+- (void)showImageNamed:(NSString *)imageNamed;
+
+@end
90 GLRenderLargeImage/Demo/GLImageViewer.m
@@ -0,0 +1,90 @@
+//
+// GLImageViewer.m
+// GLRenderLargeImage
+//
+// Created by Haoxiang Li on 11/24/11.
+// Copyright (c) 2011 DEV. All rights reserved.
+//
+
+#import "GLImageViewer.h"
+
+@implementation GLImageViewer
+
+- (void)showImageNamed:(NSString *)imageNamed {
+ UIImage *image = [UIImage imageNamed:imageNamed];
+ texture = [MPGLView textureFromImage:image
+ withGLSize:[MPGLView textureSizeForImage:image]];
+ [self renderRect:self.bounds];
+}
+
+//< Render Content, OpenGL Actions here
+- (void)drawViewInRect:(CGRect)rect {
+
+// glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+// glClear(GL_COLOR_BUFFER_BIT);
+//
+// glEnableClientState(GL_VERTEX_ARRAY);
+// glColor4f(0x24/255.0f, 0x24/255.0f, 0x24/255.0f, 1.0f);
+//
+// GLfloat minTextAreaY = 20.0f;
+// GLfloat maxTextAreaY = 40;
+//
+// GLfloat currentX = 10;
+// int lineCount = 2;
+// GLfloat points[lineCount*4];
+// for (int i = 0; i < lineCount * 4; i += 4)
+// {
+// //< Start Point
+// points[i] = currentX;
+// points[i+1] = minTextAreaY;
+//
+// //< End Point
+// points[i+2] = currentX;
+// points[i+3] = maxTextAreaY;
+//
+//// points[i+1] -= mBackingHeight;
+//// points[i+3] -= mBackingHeight;
+//// points[i+1] *= -1;
+//// points[i+3] *= -1;
+// currentX += 10;
+// }
+// glVertexPointer(2, GL_FLOAT, 0, points);
+// glDrawArrays(GL_LINES, 0, lineCount*2);
+// glDisableClientState(GL_VERTEX_ARRAY);
+
+ //[self bindTexture:texture];
+
+ glEnable(GL_TEXTURE_2D);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ const GLfloat texCoords[] = {
+ 0, 1,
+ 1, 1,
+ 0, 0,
+ 1, 0
+ };
+
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ const GLfloat points[] = {
+ CGRectGetMinX(rect), -CGRectGetMinY(rect),
+ CGRectGetMaxX(rect), -(CGRectGetMinY(rect) - mBackingHeight),
+ CGRectGetMinX(rect), -(CGRectGetMaxY(rect) - mBackingHeight),
+ CGRectGetMaxX(rect), -(CGRectGetMaxY(rect) - mBackingHeight),
+ };
+
+ glVertexPointer(2, GL_FLOAT, 0, points);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisable(GL_TEXTURE_2D);
+
+ glFlush();
+}
+
+@end
40 GLRenderLargeImage/GLRenderLargeImage-Info.plist
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFiles</key>
+ <array/>
+ <key>CFBundleIdentifier</key>
+ <string>dev.mrpppoe.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>armv7</string>
+ </array>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
14 GLRenderLargeImage/GLRenderLargeImage-Prefix.pch
@@ -0,0 +1,14 @@
+//
+// Prefix header for all source files of the 'GLRenderLargeImage' target in the 'GLRenderLargeImage' project
+//
+
+#import <Availability.h>
+
+#ifndef __IPHONE_3_0
+#warning "This project uses features only available in iOS SDK 3.0 and later."
+#endif
+
+#ifdef __OBJC__
+ #import <UIKit/UIKit.h>
+ #import <Foundation/Foundation.h>
+#endif
68 GLRenderLargeImage/MPGLView/MPGLView.h
@@ -0,0 +1,68 @@
+//
+// MPGLView.h
+// GLRenderLargeImage
+//
+// Created by Haoxiang Li on 11/24/11.
+// Copyright (c) 2011 DEV. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <OpenGLES/ES1/gl.h>
+#import <OpenGLES/ES1/glext.h>
+
+@class EAGLContext;
+
+@interface MPGLView : UIView {
+ GLint mBackingWidth;
+ GLint mBackingHeight;
+
+ EAGLContext *mGLContext;
+
+ GLuint mViewRenderbuffer;
+ GLuint mViewFramebuffer;
+ GLuint mDepthRenderbuffer;
+
+ BOOL mViewHasSetup;
+
+ CGRect mVisiblePartRect;
+}
+
+//< An OpenGL View should have width/height which has factor of 32
+- (id)initWithGLFrame:(CGRect)frame;
+
+//< To Render the specified Rect
+- (void)renderRect:(CGRect)rect;
+
+////////////////////////////////////////////////////////////////////
+/**< Can only be invoked inside drawViewInRect in the Inheritance */
+////////////////////////////////////////////////////////////////////
+
+//< Bind Texture, the partRect is used to calculate the coordinates
+- (void)bindTexture:(GLuint)texture withPartRect:(CGRect)rect withinImageSize:(CGSize)imageSize;
+- (void)bindTexture:(GLuint)texture;
+
+////////////////////////////////////////////////////////////////////
+/**< Override Point */
+////////////////////////////////////////////////////////////////////
+
+//< Setup Context, Bind and Present Buffers, Render Content
+- (void)drawView;
+
+//< Render Content, OpenGL Actions here
+- (void)drawViewInRect:(CGRect)rect;
+
+////////////////////////////////////////////////////////////////////
+/**< Utilities */
+////////////////////////////////////////////////////////////////////
+
+//< Draw Image in the glSize to texture, glSize width/height is power of 2
++ (GLuint)textureFromImage:(UIImage *)image withGLSize:(CGSize)glSize;
+
+//< return glSize, width/height is power of 2
++ (CGSize)textureSizeForImage:(UIImage *)image;
+
+//< Centerize the Image as Texture
++ (CGRect)textureRectForImage:(UIImage *)image;
+
+
+@end
275 GLRenderLargeImage/MPGLView/MPGLView.m
@@ -0,0 +1,275 @@
+//
+// MPGLView.m
+// GLRenderLargeImage
+//
+// Created by Haoxiang Li on 11/24/11.
+// Copyright (c) 2011 DEV. All rights reserved.
+//
+
+#import "MPGLView.h"
+#import <OpenGLES/EAGL.h>
+#import <OpenGLES/EAGLDrawable.h>
+#import <QuartzCore/QuartzCore.h>
+
+@interface MPGLView ()
+
+- (void)setupGLES;
+
+- (BOOL)createFramebuffer;
+- (void)destroyFramebuffer;
+
+@end
+
+@implementation MPGLView
+
++ (Class) layerClass
+{
+ return [CAEAGLLayer class];
+}
+
+- (void)awakeFromNib {
+ [super awakeFromNib];
+ [self setupGLES];
+}
+
+- (id)initWithFrame:(CGRect)frame
+{
+ if((self = [super initWithFrame:frame]))
+ {
+ [self setupGLES];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+
+ if([EAGLContext currentContext] == mGLContext)
+ {
+ [EAGLContext setCurrentContext:nil];
+ }
+
+ [mGLContext release], mGLContext = nil;
+
+ [self destroyFramebuffer];
+ [super dealloc];
+}
+
+- (void)layoutSubviews {
+ [super layoutSubviews];
+
+ [EAGLContext setCurrentContext:mGLContext];
+ [self destroyFramebuffer];
+ [self createFramebuffer];
+}
+
+#pragma mark - Public Methods
+- (id)initWithGLFrame:(CGRect)frame {
+ frame.size.width = round(frame.size.width/32.0f) * 32.0f;
+ frame.size.height = round(frame.size.height/32.0f) * 32.0f;
+ return [self initWithFrame:frame];
+}
+
+//< To Render the specified Rect
+- (void)renderRect:(CGRect)rect {
+ mVisiblePartRect = rect;
+ [self drawView];
+}
+
+/**< Can only be invoked inside drawViewInRect in the Inheritance */
+
+//< Bind Texture, the partRect is used to calculate the coordinates
+- (void)bindTexture:(GLuint)texture withPartRect:(CGRect)rect withinImageSize:(CGSize)imageSize {
+
+ //< texture rect should be inside the image bounds
+ CGRect textureRect = CGRectIntersection(rect, CGRectMake(0, 0, imageSize.width, imageSize.height));
+ if (CGRectIsNull(textureRect) || (fabs(imageSize.width) < 1e-6) || (fabs(imageSize.height) < 1e-6))
+ {
+ return;
+ }
+
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ const GLfloat texCoords[] = {
+ CGRectGetMinX(textureRect)/imageSize.width, CGRectGetMaxY(textureRect)/imageSize.height,
+ CGRectGetMaxX(textureRect)/imageSize.width, CGRectGetMaxY(textureRect)/imageSize.height,
+ CGRectGetMinX(textureRect)/imageSize.width, CGRectGetMinY(textureRect)/imageSize.height,
+ CGRectGetMaxX(textureRect)/imageSize.width, CGRectGetMinY(textureRect)/imageSize.height
+ };
+
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisable(GL_TEXTURE_2D);
+}
+
+- (void)bindTexture:(GLuint)texture {
+ [self bindTexture:texture
+ withPartRect:CGRectMake(0, 0, 1, 1)
+ withinImageSize:CGSizeMake(1, 1)];
+}
+
+/**< Override Point */
+
+//< Setup Context, Bind and Present Buffers, Render Content
+- (void)drawView
+{
+ [EAGLContext setCurrentContext:mGLContext];
+
+ glBindFramebufferOES(GL_FRAMEBUFFER_OES, mViewFramebuffer);
+
+ if (!mViewHasSetup)
+ {
+ CGSize size = CGSizeMake(self.bounds.size.width, self.bounds.size.height);
+ glViewport(0, 0, size.width, size.height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrthof(0, size.width, 0, size.height, -1024, 1024);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
+
+ mViewHasSetup = YES;
+ }
+
+ [self drawViewInRect:mVisiblePartRect];
+
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, mViewRenderbuffer);
+ [mGLContext presentRenderbuffer:GL_RENDERBUFFER_OES];
+
+ GLenum err = glGetError();
+ if(err)
+ {
+ NSLog(@"%x error", err);
+ }
+}
+
+//< Render Content, OpenGL Actions here
+- (void)drawViewInRect:(CGRect)rect {
+
+}
+
+/**< Utilities */
+
+//< Draw Image in the glSize to texture, glSize width/height is power of 2
++ (GLuint)textureFromImage:(UIImage *)image withGLSize:(CGSize)glSize {
+ GLuint texture;
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
+
+ GLuint width = glSize.width;
+ GLuint height = glSize.height;
+
+ void *imageData = malloc(height * width * 4);
+
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGContextRef bitMapcontext = CGBitmapContextCreate(imageData, width, height,
+ 8, 4 * width,
+ colorSpace,
+ kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );
+
+ CGColorSpaceRelease(colorSpace);
+ CGContextClearRect(bitMapcontext, CGRectMake( 0, 0, width, height));
+ UIGraphicsPushContext(bitMapcontext);
+ [image drawInRect:CGRectMake((width - image.size.width)/2.0f,
+ (height - image.size.height)/2.0f,
+ image.size.width, image.size.height)];
+ UIGraphicsPopContext();
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
+
+ CGContextRelease(bitMapcontext);
+ free(imageData);
+
+ return texture;
+}
+
+//< return glSize, width/height is power of 2
++ (CGSize)textureSizeForImage:(UIImage *)image {
+ CGSize size = image.size;
+ return CGSizeMake(pow(2, ceil(log2(size.width))), pow(2, ceil(log2(size.height))));
+}
+
+//< Centerize the Image as Texture
++ (CGRect)textureRectForImage:(UIImage *)image {
+ CGSize size = image.size;
+ CGSize glSize = [self textureSizeForImage:image];
+ return CGRectMake((glSize.width - size.width)/2.0f,
+ (glSize.height - size.height)/2.0f,
+ size.width, size.height);
+}
+
+#pragma mark - Private Methods
+
+- (void)setupGLES
+{
+ mVisiblePartRect = self.bounds;
+
+ CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer;
+ eaglLayer.opaque = NO;
+ eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
+ kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
+ nil];
+
+ // Create our EAGLContext, and if successful make it current and create our framebuffer.
+ mGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
+ if(!mGLContext || ![EAGLContext setCurrentContext:mGLContext] || ![self createFramebuffer])
+ {
+ [self release], self = nil;
+ return;
+ }
+
+ mViewHasSetup = NO;
+}
+
+- (BOOL)createFramebuffer
+{
+ glGenFramebuffersOES(1, &mViewFramebuffer);
+ glGenRenderbuffersOES(1, &mViewRenderbuffer);
+
+ glBindFramebufferOES(GL_FRAMEBUFFER_OES, mViewFramebuffer);
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, mViewRenderbuffer);
+
+ [mGLContext renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
+ GL_COLOR_ATTACHMENT0_OES,
+ GL_RENDERBUFFER_OES, mViewRenderbuffer);
+
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &mBackingWidth);
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &mBackingHeight);
+
+ 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)destroyFramebuffer
+{
+ glDeleteFramebuffersOES(1, &mViewFramebuffer), mViewFramebuffer = 0;
+ glDeleteRenderbuffersOES(1, &mViewRenderbuffer), mViewRenderbuffer = 0;
+
+ if(mDepthRenderbuffer)
+ {
+ glDeleteRenderbuffersOES(1, &mDepthRenderbuffer), mDepthRenderbuffer = 0;
+ }
+}
+
+@end
2 GLRenderLargeImage/en.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
18 GLRenderLargeImage/main.m
@@ -0,0 +1,18 @@
+//
+// main.m
+// GLRenderLargeImage
+//
+// Created by Haoxiang Li on 11/23/11.
+// Copyright (c) 2011 DEV. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+#import "AppDelegate.h"
+
+int main(int argc, char *argv[])
+{
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+}
BIN GLRenderLargeImage/pic.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d388af5

Please sign in to comment.
Something went wrong with that request. Please try again.