Initial import of KREngine

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%404
This commit is contained in:
kearwood
2011-10-25 05:03:10 +00:00
parent 5937288f78
commit cece608881
86 changed files with 12190 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
//
// KRObjViewAppDelegate.h
// KRObjView
//
// Created by Mac on 11-04-29.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@class KRObjViewViewController;
@interface KRObjViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
KRObjViewViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet KRObjViewViewController *viewController;
@end

View File

@@ -0,0 +1,34 @@
//
// KRObjViewAppDelegate.m
// KRObjView
//
// Created by Mac on 11-04-29.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "KRObjViewAppDelegate.h"
#import "KRObjViewViewController.h"
@implementation KRObjViewAppDelegate
@synthesize window;
@synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the view controller's view to the window and display.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end

View File

@@ -0,0 +1,45 @@
//
// KRObjViewGLView.h
// KRObjView
//
// Created by Mac on 11-05-01.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <KREngine.h>
#import <KRVector3.h>
#import <KRScene.h>
@interface KRObjViewGLView : UIView {
/* The pixel dimensions of the backbuffer */
GLint backingWidth, backingHeight;
EAGLContext *context;
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
GLuint viewFramebuffer, viewRenderbuffer;
KREngine *renderEngine;
KRScene m_scene;
}
// OpenGL drawing
- (BOOL)createFramebuffers;
- (void)destroyFramebuffer;
- (void)setDisplayFramebuffer;
- (BOOL)presentFramebuffer;
- (KREngine *)getEngine;
- (KRScene *)getScene;
- (BOOL)loadObjects;
@end

View File

@@ -0,0 +1,217 @@
//
// KRObjViewGLView.m
// KRObjView
//
// Created by Mac on 11-05-01.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "KRObjViewGLView.h"
#import <OpenGLES/EAGLDrawable.h>
#import <QuartzCore/QuartzCore.h>
@implementation KRObjViewGLView
// Override the class method to return the OpenGL layer, as opposed to the normal CALayer
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Do OpenGL Core Animation layer setup
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
// Set scaling to account for Retina display
if ([self respondsToSelector:@selector(setContentScaleFactor:)])
{
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!context)
{
[self release];
return nil;
}
if (![EAGLContext setCurrentContext:context])
{
[self release];
return nil;
}
if (![self createFramebuffers])
{
[self release];
return nil;
}
// Initialize KREngine
renderEngine = [[KREngine alloc] initForWidth: backingWidth Height: backingHeight];
[self loadObjects];
}
return self;
}
- (void)dealloc {
if(renderEngine) {
[renderEngine release];
renderEngine = nil;
}
[super dealloc];
}
#pragma mark -
#pragma mark OpenGL drawing
- (BOOL)loadObjects
{
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSFileManager* fileManager = [NSFileManager defaultManager];
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
if([fileName hasSuffix: @".pvr"]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[renderEngine loadResource: path];
}
}
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
if([fileName hasSuffix: @".mtl"]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[renderEngine loadResource: path];
}
}
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
if([fileName hasSuffix: @".krobject"]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[renderEngine loadResource: path];
}
}
KRModelManager *pModelManager = [renderEngine getModelManager];
m_scene.addInstance(pModelManager->getModel("fachwerkhaus12"), KRMat4());
[renderEngine setNearZ: 25.0];
[renderEngine setFarZ: 5000.0];
/*
startPos 156.0 -55.0 -825.0
touchScale 95.0
nearZ 25.0
farZ 5000.0
*/
// [renderEngine setParameterValueWithName: @];
return TRUE;
}
- (BOOL)createFramebuffers
{
// ===== Create onscreen framebuffer object =====
glGenFramebuffers(1, &viewFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
// ----- Create color buffer for viewFramebuffer -----
glGenRenderbuffers(1, &viewRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
NSLog(@"Backing width: %d, height: %d", backingWidth, backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
NSLog(@"Failure with depth buffer generation");
return NO;
}
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
NSLog(@"Incomplete FBO: %d", status);
exit(1);
}
return TRUE;
}
- (void)destroyFramebuffer;
{
if (viewFramebuffer)
{
glDeleteFramebuffers(1, &viewFramebuffer);
viewFramebuffer = 0;
}
if (viewRenderbuffer)
{
glDeleteRenderbuffers(1, &viewRenderbuffer);
viewRenderbuffer = 0;
}
}
- (void)setDisplayFramebuffer;
{
if (context)
{
if (!viewFramebuffer)
{
[self createFramebuffers];
}
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
/*
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
*/
}
}
- (BOOL)presentFramebuffer;
{
BOOL success = FALSE;
if (context)
{
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
success = [context presentRenderbuffer:GL_RENDERBUFFER];
}
return success;
}
- (KREngine *)getEngine;
{
return renderEngine;
}
- (KRScene *)getScene;
{
return &m_scene;
}
#pragma mark -
#pragma mark Accessors
@end

View File

@@ -0,0 +1,54 @@
//
// KRObjViewViewController.h
// KRObjView
//
// Created by Mac on 11-04-29.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "KRObjViewGLView.h"
#import <KREngine.h>
#import <KRVector3.h>
#import <KRScene.h>
@interface KRObjViewViewController : UIViewController {
CALayer *overlayLayer;
KRObjViewGLView *glView;
float heading;
Vector3 camera_position;
double camera_pitch;
double camera_yaw;
double leftStickStartX;
double leftStickStartY;
double rightStickStartX;
double rightStickStartY;
double leftStickDeltaX;
double leftStickDeltaY;
double rightStickDeltaX;
double rightStickDeltaY;
double dLeftSlider;
double dRightSlider;
bool bUpdateParam;
bool bLoadedTestInstances;
int cParamDisplayFrames;
id displayLink;
}
@property (nonatomic, retain) IBOutlet CALayer *overlayLayer;
@property (readonly) KRObjViewGLView *glView;
// OpenGL ES 2.0 setup methods
- (void)drawView:(id)sender;
@end

View File

@@ -0,0 +1,257 @@
//
// KRObjViewViewController.m
// KRObjView
//
// Created by Mac on 11-04-29.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "KRObjViewViewController.h"
#import <KRMat4.h>
#import <KRModelManager.h>
@implementation KRObjViewViewController
@synthesize overlayLayer;
@synthesize glView;
// Handle Touch Events
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for(id touch in touches) {
CGPoint touchPoint = [touch locationInView:self.view];
if(!leftStickStartY && !rightStickStartY && touchPoint.y < CGRectGetMinY(self.view.frame) + CGRectGetHeight(self.view.frame) * 0.05) {
dRightSlider = (touchPoint.x - CGRectGetMinX(self.view.frame)) / CGRectGetWidth(self.view.frame);
cParamDisplayFrames = 30;
bUpdateParam = true;
} else if(!leftStickStartY && !rightStickStartY && touchPoint.y > CGRectGetMinY(self.view.frame) + CGRectGetHeight(self.view.frame) * 0.95) {
dLeftSlider = (touchPoint.x - CGRectGetMinX(self.view.frame)) / CGRectGetWidth(self.view.frame);
cParamDisplayFrames = 30;
} else if(touchPoint.y > CGRectGetMidY(self.view.frame)) {
leftStickStartX = touchPoint.x;
leftStickStartY = touchPoint.y;
leftStickDeltaX = 0.0f;
leftStickDeltaY = 0.0f;
// NSLog(@"Left Stick Pressed");
} else {
rightStickStartX = touchPoint.x;
rightStickStartY = touchPoint.y;
rightStickDeltaX = 0.0f;
rightStickDeltaY = 0.0f;
// NSLog(@"Right Stick Pressed");
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for(id touch in touches) {
CGPoint touchPoint = [touch locationInView:self.view];
if(!leftStickStartY && !rightStickStartY && touchPoint.y < CGRectGetMinY(self.view.frame) + CGRectGetHeight(self.view.frame) * 0.10) {
dRightSlider = (touchPoint.x - CGRectGetMinX(self.view.frame)) / CGRectGetWidth(self.view.frame);
cParamDisplayFrames = 30;
bUpdateParam = true;
} else if(!leftStickStartY && !rightStickStartY && touchPoint.y > CGRectGetMinY(self.view.frame) + CGRectGetHeight(self.view.frame) * 0.90) {
dLeftSlider = (touchPoint.x - CGRectGetMinX(self.view.frame)) / CGRectGetWidth(self.view.frame);
cParamDisplayFrames = 30;
} else if(touchPoint.y > CGRectGetMidY(self.view.frame)) {
if(leftStickStartX > 0.0f) { // Avoid interpreting touches sliding across center of screen
leftStickDeltaX = (leftStickStartX - touchPoint.x) / (CGRectGetWidth(self.view.frame) * 0.25);
leftStickDeltaY = (leftStickStartY - touchPoint.y) / (CGRectGetHeight(self.view.frame) * 0.25);
// clamp values
if(leftStickDeltaX < -1.0f) {
leftStickDeltaX = -1.0f;
} else if(leftStickDeltaX > 1.0f) {
leftStickDeltaX = 1.0f;
}
if(leftStickDeltaY < -1.0f) {
leftStickDeltaY = -1.0f;
} else if(leftStickDeltaY > 1.0f) {
leftStickDeltaY = 1.0f;
}
}
} else {
if(rightStickStartX > 0.0f) { // Avoid interpreting touches sliding across center of screen
rightStickDeltaX = (rightStickStartX - touchPoint.x) / (CGRectGetWidth(self.view.frame) * 0.25);
rightStickDeltaY = (rightStickStartY - touchPoint.y) / (CGRectGetHeight(self.view.frame) * 0.25);
// clamp values
if(rightStickDeltaX < -1.0f) {
rightStickDeltaX = -1.0f;
} else if(rightStickDeltaX > 1.0f) {
rightStickDeltaX = 1.0f;
}
if(rightStickDeltaY < -1.0f) {
rightStickDeltaY = -1.0f;
} else if(rightStickDeltaY > 1.0f) {
rightStickDeltaY = 1.0f;
}
}
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for(id touch in touches) {
CGPoint touchPoint = [touch locationInView:self.view];
if(touchPoint.y > CGRectGetMidY(self.view.frame)) {
leftStickStartX = 0.0f;
leftStickStartY = 0.0f;
leftStickDeltaX = 0.0f;
leftStickDeltaY = 0.0f;
} else {
rightStickStartX = 0.0f;
rightStickStartY = 0.0f;
rightStickDeltaX = 0.0f;
rightStickDeltaY = 0.0f;
}
}
}
-(void)loadView {
CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
UIView *primaryView = [[UIView alloc] initWithFrame:mainScreenFrame];
self.view = primaryView;
[primaryView release];
glView = [[KRObjViewGLView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, mainScreenFrame.size.width, mainScreenFrame.size.height)];
glView.multipleTouchEnabled = YES;
[self.view addSubview:glView];
[glView release];
camera_yaw = -4.0;
camera_pitch = 0.1;
leftStickStartX = 0.0f;
leftStickStartY = 0.0f;
rightStickStartX = 0.0f;
rightStickStartY = 0.0f;
leftStickDeltaX = 0.0f;
leftStickDeltaY = 0.0f;
rightStickDeltaX = 0.0f;
rightStickDeltaY = 0.0f;
bUpdateParam = false;
dRightSlider = 0.0f;
dLeftSlider = 0.0f;
bLoadedTestInstances = false;
cParamDisplayFrames = 0;
camera_position = Vector3(-850, -10, -700);
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView:)];
[displayLink setFrameInterval:1]; // Maximum 60fps
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
- (void)dealloc
{
[displayLink invalidate];
[super dealloc];
}
- (void)drawView:(id)sender
{
const GLfloat PI = 3.14159265;
const GLfloat d2r = PI * 2 / 360;
KREngine *engine = [glView getEngine];
int iParam = int(dLeftSlider * ([engine getParameterCount] + 1));
if(iParam > [engine getParameterCount]) {
iParam = [engine getParameterCount];
}
if(cParamDisplayFrames && iParam < [engine getParameterCount]) {
cParamDisplayFrames--;
char szText[256];
const char *szName = [[engine getParameterLabelWithIndex: iParam] UTF8String];
double dValue = [engine getParameterValueWithIndex: iParam];
switch([engine getParameterTypeWithIndex: iParam]) {
case KRENGINE_PARAMETER_INT:
sprintf(szText, "%s: %i", szName, (int)dValue);
break;
case KRENGINE_PARAMETER_BOOL:
sprintf(szText, "%s: %s", szName, dValue == 0.0 ? "false" : "true");
break;
case KRENGINE_PARAMETER_FLOAT:
sprintf(szText, "%s: %f", szName, dValue);
break;
}
NSString *debug_text = [[NSString alloc] initWithUTF8String:szText];
[engine setDebugText: debug_text];
} else {
[engine setDebugText: @""];
}
if(bUpdateParam) {
bUpdateParam = false;
if(iParam == [engine getParameterCount] && dRightSlider > 0.9) {
if(!bLoadedTestInstances) {
bLoadedTestInstances = true;
KRModelManager *pModelManager = [engine getModelManager];
KRScene *scene =[glView getScene];
srand ( time(NULL) );
for(int iHouse=1; iHouse < 12; iHouse++) {
for(int iInstance=0; iInstance < 20; iInstance++) {
char szName[100];
sprintf(szName, "fachwerkhaus%i", iHouse);
KRMat4 pos;
pos.rotate((double)rand() / (double)RAND_MAX * 6.282, Y_AXIS);
pos.translate((double)rand() / (double)RAND_MAX * 10000 - 5000, 0.0, (double)rand() / (double)RAND_MAX * 10000 - 5000);
scene->addInstance(pModelManager->getModel(szName), pos);
}
}
}
} else {
double dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
switch([engine getParameterTypeWithIndex: iParam]) {
case KRENGINE_PARAMETER_INT:
dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] + 0.5 - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
[engine setParameterValueWithIndex: iParam Value: dValue];
break;
case KRENGINE_PARAMETER_BOOL:
[engine setParameterValueWithIndex: iParam Value: 1.0 - dValue];
break;
case KRENGINE_PARAMETER_FLOAT:
[engine setParameterValueWithIndex: iParam Value: dValue];
break;
}
}
}
[glView setDisplayFramebuffer];
//double dScaleFactor = [engine getModelManager]->getFirstModel()->getMaxDimension() / 100.0f;
double dScaleFactor = 10.0f;
camera_position.z += (-cos(camera_pitch) * cos(camera_yaw) * leftStickDeltaX + -cos(camera_pitch) * cos(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
camera_position.x += (cos(camera_pitch) * sin(camera_yaw) * leftStickDeltaX + cos(camera_pitch) * sin(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
camera_position.y += sin(camera_pitch) * leftStickDeltaX * dScaleFactor;
camera_yaw += rightStickDeltaY * 4.0 * d2r;
camera_pitch += rightStickDeltaX * 4.0 * d2r;
[engine renderScene: [glView getScene] WithPosition:camera_position Yaw: camera_yaw Pitch: camera_pitch Roll:0.0f];
[glView presentFramebuffer];
}
@end

View File

@@ -0,0 +1,67 @@
//
// KREngine.h
// gldemo
//
// Created by Kearwood Gilbert on 10-09-16.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
// #import "KRTextureManager.h"
#import <map>
#import <string>
#import "KRMat4.h"
#import "KRModel.h"
#import "KRTextureManager.h"
#import "KRMaterialManager.h"
using std::map;
@interface KREngine : NSObject
{
@private
GLint backingWidth, backingHeight;
GLuint compositeFramebuffer, compositeDepthTexture, compositeColorTexture;
GLuint shadowFramebuffer, shadowDepthTexture;
// uniform index
enum {
KRENGINE_UNIFORM_MATERIAL_AMBIENT,
KRENGINE_UNIFORM_MATERIAL_DIFFUSE,
KRENGINE_UNIFORM_MATERIAL_SPECULAR,
KRENGINE_UNIFORM_MVP,
KRENGINE_UNIFORM_MODEL,
KRENGINE_UNIFORM_MODELIT, // Inverse Transform
KRENGINE_NUM_UNIFORMS
};
GLint m_uniforms[KRENGINE_NUM_UNIFORMS];
// attribute index
enum {
KRENGINE_ATTRIB_VERTEX,
KRENGINE_ATTRIB_NORMAL,
KRENGINE_ATTRIB_TANGENT,
KRENGINE_ATTRIB_TEXUV,
KRENGINE_NUM_ATTRIBUTES
};
GLuint m_objectShaderProgram;
GLuint m_postShaderProgram;
GLuint m_shadowShaderProgram;
std::map<std::string, KRModel *> m_models;
KRTextureManager *m_pTextureManager;
KRMaterialManager *m_pMaterialManager;
}
- (id)initForWidth: (GLuint)width Height: (GLuint)height;
- (void)renderWithModelMatrix: (KRMat4)modelMatrix;
- (BOOL)loadVertexShader:(NSString *)vertexShaderName fragmentShader:(NSString *)fragmentShaderName forProgram:(GLuint *)programPointer;
- (BOOL)loadResource:(NSString *)path;
@end

View File

@@ -0,0 +1,566 @@
//
// KREngine.mm
// gldemo
//
// Created by Kearwood Gilbert on 10-09-16.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#import "KREngine.h"
@interface KREngine (PrivateMethods)
//- (BOOL)loadObjects;
- (BOOL)loadShaders;
- (BOOL)createBuffers;
- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file;
- (BOOL)linkProgram:(GLuint)prog;
- (BOOL)validateProgram:(GLuint)prog;
- (void)renderPost;
- (BOOL)loadResource:(NSString *)path;
@end
@implementation KREngine
- (id)initForWidth: (GLuint)width Height: (GLuint)height
{
backingWidth = width;
backingHeight = height;
if ((self = [super init]))
{
m_pTextureManager = new KRTextureManager();
m_pMaterialManager = new KRMaterialManager(m_pTextureManager);
if (![self createBuffers] || ![self loadShaders]/* || ![self loadObjects] */)
{
[self release];
return nil;
}
}
return self;
}
- (BOOL)createBuffers
{
// ===== Create offscreen compositing framebuffer object =====
glGenFramebuffers(1, &compositeFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
// ----- Create texture color buffer for compositeFramebuffer -----
glGenTextures(1, &compositeColorTexture);
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, compositeColorTexture, 0);
// ----- Create Depth Texture for compositeFramebuffer -----
glGenTextures(1, &compositeDepthTexture);
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
// ===== Create offscreen shadow framebuffer object =====
glGenFramebuffers(1, &shadowFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, shadowFramebuffer);
// ----- Create Depth Texture for shadowFramebuffer -----
glGenTextures(1, &shadowDepthTexture);
glBindTexture(GL_TEXTURE_2D, shadowDepthTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowDepthTexture, 0);
return TRUE;
}
- (void)destroyBuffers
{
if (compositeDepthTexture) {
glDeleteTextures(1, &compositeDepthTexture);
compositeDepthTexture = 0;
}
if (compositeColorTexture) {
glDeleteTextures(1, &compositeColorTexture);
compositeColorTexture = 0;
}
if (compositeFramebuffer) {
glDeleteFramebuffers(1, &compositeFramebuffer);
compositeFramebuffer = 0;
}
if (shadowDepthTexture) {
glDeleteTextures(1, &shadowDepthTexture);
shadowDepthTexture = 0;
}
if (shadowFramebuffer) {
glDeleteFramebuffers(1, &shadowFramebuffer);
shadowFramebuffer = 0;
}
}
- (void)renderWithModelMatrix: (KRMat4)modelMatrix
{
/* An identity matrix we use to perform the equivalant of glLoadIdentity */
KRMat4 identitymatrix;
KRMat4 projectionmatrix; /* Our projection matrix starts with all 0s */
// KRMat4 modelmatrix; /* Our model matrix */
KRMat4 mvpmatrix; /* Our MVP matrix */
/* Create our projection matrix with a 45 degree field of view
* a width to height ratio of 1 and view from .1 to 800 infront of us */
projectionmatrix.perspective(45.0f, 1.3333, 0.01f, 800.0f);
// Replace the implementation of this method to do your own custom drawing
static std::map<std::string, KRModel *>::iterator model_itr;
model_itr = m_models.begin();
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Enable backface culling
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
// Enable alpha blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Use shader program
glUseProgram(m_objectShaderProgram);
// Sets the diffuseTexture variable to the first texture unit
glUniform1i(glGetUniformLocation(m_objectShaderProgram, "diffuseTexture"), 0);
// Sets the specularTexture variable to the second texture unit
glUniform1i(glGetUniformLocation(m_objectShaderProgram, "specularTexture"), 1);
// Sets the normalTexture variable to the third texture unit
glUniform1i(glGetUniformLocation(m_objectShaderProgram, "normalTexture"), 2);
// Validate program before drawing. This is a good check, but only really necessary in a debug build.
// DEBUG macro must be defined in your debug configurations if that's not already the case.
#if defined(DEBUG)
if (![self validateProgram:m_objectShaderProgram])
{
NSLog(@"Failed to validate program: %d", m_objectShaderProgram);
return;
}
#endif
// ----- Render Model -----
KRMat4 modelmatrix = identitymatrix;
// Load the identity matrix into modelmatrix. rotate the model, and move it back 3
KRModel *pModel = (*model_itr).second;
modelmatrix.translate(pModel->getMinX() - pModel->getMaxX(), pModel->getMinY() - pModel->getMaxY(), pModel->getMinZ() - pModel->getMaxZ());
modelmatrix.scale(1.0/pModel-> getMaxDimension());
modelmatrix.translate(0.15, 0.1, -0.4);
modelmatrix *= modelMatrix;
mvpmatrix = modelmatrix;
// multiply our modelmatrix and our projectionmatrix.
mvpmatrix *= projectionmatrix;
mvpmatrix.rotate(-90 * 0.0174532925199, Z_AXIS);
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MVP], 1, GL_FALSE, mvpmatrix.getPointer());
glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MODEL], 1, GL_FALSE, modelmatrix.getPointer());
glUniformMatrix3fv(m_uniforms[KRENGINE_UNIFORM_MODELIT], 1, GL_FALSE, modelmatrix.getPointer());
(*model_itr).second -> render(m_objectShaderProgram, (GLuint)KRENGINE_ATTRIB_VERTEX, (GLuint)KRENGINE_ATTRIB_NORMAL, (GLuint)KRENGINE_ATTRIB_TANGENT, (GLuint)KRENGINE_ATTRIB_TEXUV, m_pMaterialManager);
// 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.
/*
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];
*/
[self renderPost];
}
- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file
{
GLint status;
const GLchar *source;
source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String];
if (!source)
{
NSLog(@"Failed to load vertex shader");
return FALSE;
}
*shader = glCreateShader(type);
glShaderSource(*shader, 1, &source, NULL);
glCompileShader(*shader);
#if defined(DEBUG)
GLint logLength;
glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetShaderInfoLog(*shader, logLength, &logLength, log);
NSLog(@"Shader compile log:\n%s", log);
free(log);
}
#endif
glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
if (status == 0)
{
glDeleteShader(*shader);
return FALSE;
}
return TRUE;
}
- (BOOL)linkProgram:(GLuint)prog
{
GLint status;
glLinkProgram(prog);
#if defined(DEBUG)
GLint logLength;
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(prog, logLength, &logLength, log);
NSLog(@"Program link log:\n%s", log);
free(log);
}
#endif
glGetProgramiv(prog, GL_LINK_STATUS, &status);
if (status == 0)
return FALSE;
return TRUE;
}
- (BOOL)validateProgram:(GLuint)prog
{
GLint logLength, status;
glValidateProgram(prog);
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(prog, logLength, &logLength, log);
NSLog(@"Program validate log:\n%s", log);
free(log);
}
glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
if (status == 0)
return FALSE;
return TRUE;
}
- (BOOL)loadVertexShader:(NSString *)vertexShaderName fragmentShader:(NSString *)fragmentShaderName forProgram:(GLuint *)programPointer;
{
GLuint vertexShader, fragShader;
NSString *vertShaderPathname, *fragShaderPathname;
// Create shader program.
*programPointer = glCreateProgram();
// Create and compile vertex shader.
vertShaderPathname = [[NSBundle mainBundle] pathForResource:vertexShaderName ofType:@"vsh"];
if (![self compileShader:&vertexShader type:GL_VERTEX_SHADER file:vertShaderPathname])
{
NSLog(@"Failed to compile vertex shader");
return FALSE;
}
// Create and compile fragment shader.
fragShaderPathname = [[NSBundle mainBundle] pathForResource:fragmentShaderName ofType:@"fsh"];
if (![self compileShader:&fragShader type:GL_FRAGMENT_SHADER file:fragShaderPathname])
{
NSLog(@"Failed to compile fragment shader");
return FALSE;
}
// Attach vertex shader to program.
glAttachShader(*programPointer, vertexShader);
// Attach fragment shader to program.
glAttachShader(*programPointer, fragShader);
// Bind attribute locations.
// This needs to be done prior to linking.
glBindAttribLocation(*programPointer, KRENGINE_ATTRIB_VERTEX, "position");
glBindAttribLocation(*programPointer, KRENGINE_ATTRIB_TEXUV, "inputTextureCoordinate");
glBindAttribLocation(*programPointer, KRENGINE_ATTRIB_VERTEX, "myVertex");
glBindAttribLocation(*programPointer, KRENGINE_ATTRIB_NORMAL, "myNormal");
glBindAttribLocation(*programPointer, KRENGINE_ATTRIB_TANGENT, "myTangent");
glBindAttribLocation(*programPointer, KRENGINE_ATTRIB_TEXUV, "myUV");
// Link program.
if (![self linkProgram:*programPointer])
{
NSLog(@"Failed to link program: %d", *programPointer);
if (vertexShader)
{
glDeleteShader(vertexShader);
vertexShader = 0;
}
if (fragShader)
{
glDeleteShader(fragShader);
fragShader = 0;
}
if (*programPointer)
{
glDeleteProgram(*programPointer);
*programPointer = 0;
}
return FALSE;
}
// Release vertex and fragment shaders.
if (vertexShader)
{
glDeleteShader(vertexShader);
}
if (fragShader)
{
glDeleteShader(fragShader);
}
return TRUE;
}
- (BOOL)loadShaders
{
[self loadVertexShader:@"PostShader" fragmentShader:@"PostShader" forProgram:&m_postShaderProgram];
[self loadVertexShader:@"ShadowShader" fragmentShader:@"ShadowShader" forProgram:&m_shadowShaderProgram];
[self loadVertexShader:@"ObjectShader" fragmentShader:@"ObjectShader" forProgram:&m_objectShaderProgram];
// Get uniform locations
m_uniforms[KRENGINE_UNIFORM_MATERIAL_AMBIENT] = glGetUniformLocation(m_objectShaderProgram, "material_ambient");
m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_objectShaderProgram, "material_diffuse");
m_uniforms[KRENGINE_UNIFORM_MATERIAL_SPECULAR] = glGetUniformLocation(m_objectShaderProgram, "material_specular");
m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_objectShaderProgram, "myMVPMatrix");
m_uniforms[KRENGINE_UNIFORM_MODEL] = glGetUniformLocation(m_objectShaderProgram, "myModelView");
m_uniforms[KRENGINE_UNIFORM_MODELIT] = glGetUniformLocation(m_objectShaderProgram, "myModelViewIT");
return TRUE;
}
- (BOOL)loadResource:(NSString *)path
{
NSString *name = [[path lastPathComponent] stringByDeletingPathExtension];
if([path hasSuffix: @".pack"]) {
NSLog(@"object: %@", path);
m_models[[name UTF8String]] = new KRModel([path UTF8String], m_pMaterialManager);
} else if([path hasSuffix: @".pvr"]) {
NSLog(@"texture: %@", path);
m_pTextureManager->loadTexture([name UTF8String], [path UTF8String]);
} else if([path hasSuffix: @".mtl"]) {
NSLog(@"material: %@", path);
m_pMaterialManager->loadFile([path UTF8String]);
}
return TRUE;
}
/*
- (BOOL)loadObjects
{
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSFileManager* fileManager = [NSFileManager defaultManager];
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
if([fileName hasSuffix: @".pvr"]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[self loadResource: path];
}
}
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
if([fileName hasSuffix: @".mtl"]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[self loadResource: path];
}
}
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
if([fileName hasSuffix: @".pack"]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[self loadResource: path];
}
}
return TRUE;
}
*/
/*
NSArray *paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"pack" inDirectory:nil];
for (NSString *path in paths) {
[self loadResource: path];
}
NSArray *paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"pvr" inDirectory:nil];
for (NSString *path in paths) {
[self loadResource: path];
}
paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"mtl" inDirectory:nil];
for (NSString *path in paths) {
[self loadResource: path];
}
*/
- (void)dealloc
{
if (m_objectShaderProgram) {
glDeleteProgram(m_objectShaderProgram);
m_objectShaderProgram = 0;
}
for(std::map<std::string, KRModel *>::iterator itr=m_models.begin(); itr != m_models.end(); itr++) {
delete (*itr).second;
}
m_models.empty();
if(m_pTextureManager) {
delete m_pTextureManager;
m_pTextureManager = NULL;
}
if(m_pMaterialManager) {
delete m_pMaterialManager;
m_pMaterialManager = NULL;
}
[self destroyBuffers];
[super dealloc];
}
- (void)renderPost
{
glBindFramebuffer(GL_FRAMEBUFFER, 1); // renderFramebuffer
// Replace the implementation of this method to do your own custom drawing.
static const GLfloat squareVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
};
static const GLfloat textureVertices[] = {
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
};
/*
static const GLfloat textureVertices[] = {
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f,
};
*/
glDisable(GL_DEPTH_TEST);
glUseProgram(m_postShaderProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "depthFrame"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1);
/*
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "videoFrame"), 2);
*/
// Update attribute values.
glVertexAttribPointer(KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
glEnableVertexAttribArray(KRENGINE_ATTRIB_VERTEX);
glVertexAttribPointer(KRENGINE_ATTRIB_TEXUV, 2, GL_FLOAT, 0, 0, textureVertices);
glEnableVertexAttribArray(KRENGINE_ATTRIB_TEXUV);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
/*
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, 0);
*/
}
@end

View File

@@ -0,0 +1,133 @@
//
// KRMat4.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-09-21.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "KRMat4.h"
KRMat4::KRMat4() {
// Default constructor - Initialize with an identity matrix
static const GLfloat IDENTITY_MATRIX[] = {
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
memcpy(m_mat, IDENTITY_MATRIX, sizeof(GLfloat) * 16);
}
KRMat4::~KRMat4() {
}
GLfloat *KRMat4::getPointer() {
return m_mat;
}
// Copy constructor
KRMat4::KRMat4(const KRMat4 &m) {
memcpy(m_mat, m.m_mat, sizeof(GLfloat) * 16);
}
KRMat4& KRMat4::operator=(const KRMat4 &m) {
if(this != &m) { // Prevent self-assignment.
memcpy(m_mat, m.m_mat, sizeof(GLfloat) * 16);
}
return *this;
}
// Overload compound multiply operator
KRMat4& KRMat4::operator*=(const KRMat4 &m) {
GLfloat temp[16];
int x,y;
for (x=0; x < 4; x++)
{
for(y=0; y < 4; y++)
{
temp[y + (x*4)] = (m_mat[x*4] * m.m_mat[y]) +
(m_mat[(x*4)+1] * m.m_mat[y+4]) +
(m_mat[(x*4)+2] * m.m_mat[y+8]) +
(m_mat[(x*4)+3] * m.m_mat[y+12]);
}
}
memcpy(m_mat, temp, sizeof(GLfloat) << 4);
return *this;
}
// Overload multiply operator
KRMat4& KRMat4::operator*(const KRMat4 &m) {
KRMat4 result = *this;
result *= m;
return result;
}
/* Generate a perspective view matrix using a field of view angle fov,
* window aspect ratio, near and far clipping planes */
void KRMat4::perspective(GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz) {
GLfloat range;
range = tan(fov * 0.00872664625) * nearz; /* 0.00872664625 = PI/360 */
memset(m_mat, 0, sizeof(GLfloat) * 16);
m_mat[0] = (2 * nearz) / ((range * aspect) - (-range * aspect));
m_mat[5] = (2 * nearz) / (2 * range);
m_mat[10] = -(farz + nearz) / (farz - nearz);
m_mat[11] = -1;
m_mat[14] = -(2 * farz * nearz) / (farz - nearz);
}
/* Perform translation operations on a matrix */
void KRMat4::translate(GLfloat x, GLfloat y, GLfloat z) {
KRMat4 newMatrix; // Create new identity matrix
newMatrix.m_mat[12] = x;
newMatrix.m_mat[13] = y;
newMatrix.m_mat[14] = z;
*this *= newMatrix;
}
/* Rotate a matrix by an angle on a X, Y, or Z axis */
void KRMat4::rotate(GLfloat angle, AXIS axis) {
// const GLfloat d2r = 0.0174532925199; /* PI / 180 */
const int cos1[3] = { 5, 0, 0 };
const int cos2[3] = { 10, 10, 5 };
const int sin1[3] = { 6, 2, 1 };
const int sin2[3] = { 9, 8, 4 };
KRMat4 newMatrix; // Create new identity matrix
newMatrix.m_mat[cos1[axis]] = cos(angle);
newMatrix.m_mat[sin1[axis]] = -sin(angle);
newMatrix.m_mat[sin2[axis]] = -newMatrix.m_mat[sin1[axis]];
newMatrix.m_mat[cos2[axis]] = newMatrix.m_mat[cos1[axis]];
*this *= newMatrix;
}
void KRMat4::scale(GLfloat x, GLfloat y, GLfloat z) {
KRMat4 newMatrix; // Create new identity matrix
newMatrix.m_mat[0] = x;
newMatrix.m_mat[5] = y;
newMatrix.m_mat[10] = z;
*this *= newMatrix;
}
void KRMat4::scale(GLfloat s) {
scale(s,s,s);
}

View File

@@ -0,0 +1,69 @@
//
// KRMat4.h
// gldemo
//
// Created by Kearwood Gilbert on 10-09-21.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#ifndef KRMAT4_I
#define KRMAT4_I
#define EMPTY_MATRIX4 { 0.0, 0.0, 0.0, 0.0,\
0.0, 0.0, 0.0, 0.0,\
0.0, 0.0, 0.0, 0.0,\
0.0, 0.0, 0.0, 0.0 }
#define IDENTITY_MATRIX4 { 1.0, 0.0, 0.0, 0.0,\
0.0, 1.0, 0.0, 0.0,\
0.0, 0.0, 1.0, 0.0,\
0.0, 0.0, 0.0, 1.0 }
typedef enum {
X_AXIS,
Y_AXIS,
Z_AXIS
} AXIS;
class KRMat4 {
GLfloat m_mat[16];
public:
// Default constructor - Creates an identity matrix
KRMat4();
// Destructor
~KRMat4();
// Copy constructor
KRMat4(const KRMat4 &m);
// Overload assignment operator
KRMat4& operator=(const KRMat4 &m);
// Overload compound multiply operator
KRMat4& operator*=(const KRMat4 &m);
// Overload multiply operator
KRMat4& operator*(const KRMat4 &m);
GLfloat *getPointer();
void perspective(GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz);
void translate(GLfloat x, GLfloat y, GLfloat z);
void scale(GLfloat x, GLfloat y, GLfloat z);
void scale(GLfloat s);
void rotate(GLfloat angle, AXIS axis);
};
#endif // KRMAT4_I

View File

@@ -0,0 +1,148 @@
//
// KRMaterial.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-10-24.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#include "KRMaterial.h"
KRMaterial::KRMaterial() {
m_pAmbientMap = NULL;
m_pDiffuseMap = NULL;
m_pSpecularMap = NULL;
m_pNormalMap = NULL;
m_ka_r = (GLfloat)0.0f;
m_ka_g = (GLfloat)0.0f;
m_ka_b = (GLfloat)0.0f;
m_kd_r = (GLfloat)1.0f;
m_kd_g = (GLfloat)1.0f;
m_kd_b = (GLfloat)1.0f;
m_ks_r = (GLfloat)1.0f;
m_ks_g = (GLfloat)1.0f;
m_ks_b = (GLfloat)1.0f;
}
KRMaterial::~KRMaterial() {
}
void KRMaterial::setAmbientMap(KRTexture *pTexture) {
m_pAmbientMap = pTexture;
}
void KRMaterial::setDiffuseMap(KRTexture *pTexture) {
m_pDiffuseMap = pTexture;
}
void KRMaterial::setSpecularMap(KRTexture *pTexture) {
m_pSpecularMap = pTexture;
}
void KRMaterial::setNormalMap(KRTexture *pTexture) {
m_pNormalMap = pTexture;
}
void KRMaterial::setAmbient(GLfloat r, GLfloat g, GLfloat b) {
m_ka_r = r;
m_ka_g = g;
m_ka_b = b;
}
void KRMaterial::setDiffuse(GLfloat r, GLfloat g, GLfloat b) {
m_kd_r = r;
m_kd_g = g;
m_kd_b = b;
}
void KRMaterial::setSpecular(GLfloat r, GLfloat g, GLfloat b) {
m_ks_r = r;
m_ks_g = g;
m_ks_b = b;
}
void KRMaterial::bind(GLuint program) {
GLuint uniform_material_ambient = glGetUniformLocation(program, "material_ambient");
GLuint uniform_material_diffuse = glGetUniformLocation(program, "material_diffuse");
GLuint uniform_material_specular = glGetUniformLocation(program, "material_specular");
glUniform3f(
uniform_material_ambient,
m_ka_r, // iMaterial % 2 ? (GLfloat)0.9f : (GLfloat)0.5f,
m_ka_g, // iMaterial % 4 ? (GLfloat)0.9f : (GLfloat)0.5f,
m_ka_b // iMaterial % 8 ? (GLfloat)0.9f : (GLfloat)0.5f,
);
glUniform3f(
uniform_material_diffuse,
m_kd_r + 1.0f, // 1.0 added so there will not be complete darkness
m_kd_g + 1.0f, // 1.0 added so there will not be complete darkness
m_kd_b + 1.0f // 1.0 added so there will not be complete darkness
);
glUniform3f(
uniform_material_specular,
m_ks_r, // iMaterial % 2 ? (GLfloat)0.9f : (GLfloat)0.5f,
m_ks_g, // iMaterial % 4 ? (GLfloat)0.9f : (GLfloat)0.5f,
m_ks_b // iMaterial % 8 ? (GLfloat)0.9f : (GLfloat)0.5f,
);
int iTextureName = 0;
if(m_pDiffuseMap != NULL) {
iTextureName = m_pDiffuseMap->getName();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
iTextureName = 0;
if(m_pSpecularMap != NULL) {
iTextureName = m_pSpecularMap->getName();
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
iTextureName = 0;
if(m_pNormalMap != NULL) {
iTextureName = m_pNormalMap->getName();
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
/*
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
*/
/*
if (_anisotropySupported)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, _anisotropyTexParam);
*/
/*
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
*/
}

View File

@@ -0,0 +1,46 @@
//
// KRMaterial.h
// gldemo
//
// Created by Kearwood Gilbert on 10-10-24.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <stdint.h>
#import <list>
using std::list;
#ifndef KRMATERIAL_H
#define KRMATRIAL_H
#import "KRTexture.h"
class KRMaterial {
public:
KRMaterial();
~KRMaterial();
void setAmbientMap(KRTexture *pTexture);
void setDiffuseMap(KRTexture *pTexture);
void setSpecularMap(KRTexture *pTexture);
void setNormalMap(KRTexture *pTexture);
void setAmbient(GLfloat r, GLfloat g, GLfloat b);
void setDiffuse(GLfloat r, GLfloat g, GLfloat b);
void setSpecular(GLfloat r, GLfloat g, GLfloat b);
void bind(GLuint program);
private:
KRTexture *m_pAmbientMap; // mtl map_Ka value
KRTexture *m_pDiffuseMap; // mtl map_Kd value
KRTexture *m_pSpecularMap; // mtl map_Ks value
KRTexture *m_pNormalMap; // mtl map_Normal value
GLfloat m_ka_r, m_ka_g, m_ka_b; // Ambient rgb
GLfloat m_kd_r, m_kd_g, m_kd_b; // Diffuse rgb
GLfloat m_ks_r, m_ks_g, m_ks_b; // Specular rgb
};
#endif

View File

@@ -0,0 +1,185 @@
//
// KRMaterialManager.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-10-24.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#include "KRMaterialManager.h"
#import <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
KRMaterialManager::KRMaterialManager(KRTextureManager *pTextureManager) {
m_pTextureManager = pTextureManager;
}
KRMaterialManager::~KRMaterialManager() {
}
KRMaterial *KRMaterialManager::getMaterial(const char *szName) {
map<std::string, KRMaterial *>::iterator itr = m_materials.find(szName);
if(itr == m_materials.end()) {
// Not found
return NULL;
} else {
return (*itr).second;
}
}
bool KRMaterialManager::loadFile(const char *szPath) {
bool bSuccess = false;
int fdFile = 0;
int fileSize = 0;
void *pFile = NULL;
KRMaterial *pMaterial = NULL;
char szSymbol[16][64];
struct stat statbuf;
fdFile = open(szPath, O_RDONLY);
if(fdFile >= 0) {
if(fstat(fdFile, &statbuf) >= 0) {
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdFile, 0)) == (caddr_t) -1) {
} else {
fileSize = statbuf.st_size;
char *pScan = (char *)pFile;
char *pEnd = (char *)pFile + fileSize;
while(pScan < pEnd) {
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
}
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
if(strcmp(szSymbol[0], "newmtl") == 0 && cSymbols >= 2) {
pMaterial = new KRMaterial();
m_materials[szSymbol[1]] = pMaterial;
} if(pMaterial != NULL) {
if(strcmp(szSymbol[0], "Ka") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setAmbient(r, r, r);
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setAmbient(r, g, b);
}
} else if(strcmp(szSymbol[0], "Kd") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setDiffuse(r, r, r);
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setDiffuse(r, g, b);
}
} else if(strcmp(szSymbol[0], "Ks") == 0) {
char *pScan2 = szSymbol[1];
double r = strtof(pScan2, &pScan2);
if(cSymbols == 2) {
pMaterial->setSpecular(r, r, r);
} else if(cSymbols == 4) {
pScan2 = szSymbol[2];
double g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3];
double b = strtof(pScan2, &pScan2);
pMaterial->setSpecular(r, g, b);
}
} else if(strncmp(szSymbol[0], "map", 3) == 0) {
// Truncate file extension
char *pScan2 = szSymbol[1];
char *pLastPeriod = NULL;
while(*pScan2 != '\0') {
if(*pScan2 == '.') {
pLastPeriod = pScan2;
}
pScan2++;
}
if(pLastPeriod) {
*pLastPeriod = '\0';
}
KRTexture *pTexture = m_pTextureManager->getTexture(szSymbol[1]);
if(pTexture) {
if(strcmp(szSymbol[0], "map_Ka") == 0) {
pMaterial->setAmbientMap(pTexture);
} else if(strcmp(szSymbol[0], "map_Kd") == 0) {
pMaterial->setDiffuseMap(pTexture);
} else if(strcmp(szSymbol[0], "map_Ks") == 0) {
pMaterial->setSpecularMap(pTexture);
} else if(strcmp(szSymbol[0], "map_Normal") == 0) {
pMaterial->setNormalMap(pTexture);
}
}
}
}
}
}
bSuccess = true;
}
}
}
if(pFile != NULL) {
munmap(pFile, fileSize);
}
if(fdFile != 0) {
close(fdFile);
}
/*
KRMaterial *pMaterial = new KRMaterial();
if(!pMaterial->loadFromFile(szPath)) {
delete pMaterial;
return NULL;
}
m_materials[szName] = pMaterial;
*/
return bSuccess;
}

View File

@@ -0,0 +1,32 @@
//
// KRMaterialManager.h
// gldemo
//
// Created by Kearwood Gilbert on 10-10-24.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#ifndef KRMATERIALMANAGER_H
#define KRMATERIALMANAGER_H
#include "KRMaterial.h"
#include "KRTextureManager.h"
#include <map>
using std::map;
class KRMaterialManager {
public:
KRMaterialManager(KRTextureManager *pTextureManager);
~KRMaterialManager();
bool loadFile(const char *szPath);
KRMaterial *getMaterial(const char *szName);
private:
map<std::string, KRMaterial *> m_materials;
KRTextureManager *m_pTextureManager;
};
#endif

View File

@@ -0,0 +1,615 @@
//
// KRModel.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-09-22.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#import <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include "KRModel.h"
#include "KRVector3.h"
#define MAX_VBO_SIZE 65535
// MAX_VBO_SIZE must be divisible by 3 so triangles aren't split across VBO objects...
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
KRModel::KRModel(std::string path, KRMaterialManager *pMaterialManager) {
m_fdPackFile = 0;
m_pPackFile = NULL;
m_iPackFileSize = 0;
m_cBuffers = 0;
m_pBuffers = NULL;
// loadWavefront(path, pMaterialManager);
loadPack(path, pMaterialManager);
}
void KRModel::loadPack(std::string path, KRMaterialManager *pMaterialManager) {
struct stat statbuf;
m_fdPackFile = open(path.c_str(), O_RDONLY);
if(m_fdPackFile >= 0) {
if(fstat(m_fdPackFile, &statbuf) >= 0) {
if ((m_pPackFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, m_fdPackFile, 0)) == (caddr_t) -1) {
} else {
m_iPackFileSize = statbuf.st_size;
pack_header *pHeader = (pack_header *)m_pPackFile;
m_minx = pHeader->minx;
m_miny = pHeader->miny;
m_minz = pHeader->minz;
m_maxx = pHeader->maxx;
m_maxy = pHeader->maxy;
m_maxz = pHeader->maxz;
pack_material *pPackMaterials = (pack_material *)(pHeader+1);
for(int iMaterial=0; iMaterial < pHeader->material_count; iMaterial++) {
pack_material *pPackMaterial = pPackMaterials + iMaterial;
Material *pMaterial = new Material();
pMaterial->start_vertex = pPackMaterial->start_vertex;
pMaterial->vertex_count = pPackMaterial->vertex_count;
pMaterial->pMaterial = pMaterialManager->getMaterial(pPackMaterial->szName);
m_materials.push_back(pMaterial);
}
m_pVertexData = (VertexData *)(pPackMaterials + pHeader->material_count);
m_cBuffers = (pHeader->vertex_count + MAX_VBO_SIZE - 1) / MAX_VBO_SIZE;
m_pBuffers = new GLuint[m_cBuffers];
glGenBuffers(m_cBuffers, m_pBuffers);
for(GLsizei iBuffer=0; iBuffer < m_cBuffers; iBuffer++) {
// if(iBuffer < 30) {
GLsizei cVertexes = iBuffer < m_cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffers[iBuffer]);
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * cVertexes, m_pVertexData + iBuffer * MAX_VBO_SIZE, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// }
}
}
}
}
}
void KRModel::loadWavefront(std::string path, KRMaterialManager *pMaterialManager) {
const char *szPath = path.c_str();
int fdFile = 0;
int fileSize = 0;
void *pFile = NULL;
char szSymbol[16][64];
std::vector<KRMaterial *> materials;
Vertex3D *pVertices = NULL;
Vector3D *pNormals = NULL;
TexCoord *pTexCoords = NULL;
int *pFaces = NULL;
struct stat statbuf;
fdFile = open(szPath, O_RDONLY);
if(fdFile >= 0) {
if(fstat(fdFile, &statbuf) >= 0) {
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdFile, 0)) == (caddr_t) -1) {
} else {
fileSize = statbuf.st_size;
// Pass 1 - Get counts
int cVertices = 0;
int cNormals = 0;
int cTexCoords = 0;
int cVertexData = 0;
cVertices = 0;
int cFaces = 1;
GLint cMaterialFaceStart = 1;
// ---------
char *pScan = (char *)pFile;
char *pEnd = (char *)pFile + fileSize;
while(pScan < pEnd) {
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
}
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
if(strcmp(szSymbol[0], "v") == 0) {
// Vertex (v)
cVertices++;
} else if(strcmp(szSymbol[0], "vt") == 0) {
// Vertex Texture UV Coordinate (vt)
cTexCoords++;
} else if(strcmp(szSymbol[0], "vn") == 0) {
// Vertex Normal (vn)
cNormals++;
} else if(strcmp(szSymbol[0], "f") == 0) {
// Face (f)
int cFaceVertexes = (cSymbols - 3) * 3; // 3 vertexes per triangle. Triangles have 4 symbols. Quads have 5 symbols and generate two triangles.
cVertexData += cFaceVertexes;
cFaces += cFaceVertexes * 3 + 1; // Allocate space for count of vertices, Vertex Index, Texture Coordinate Index, and Normal Index
} else if(strcmp(szSymbol[0], "usemtl") == 0) {
// Use Material (usemtl)
if(cMaterialFaceStart - cFaces > 0) {
cFaces++;
}
materials.push_back(pMaterialManager->getMaterial(szSymbol[1]));
}
}
}
// Pass 2 - Populate vertexes and faces
Vertex3D *pVertices = (Vertex3D *)malloc(sizeof(Vertex3D) * cVertices);
Vector3D *pNormals = (Vector3D *)malloc(sizeof(Vector3D) *cNormals);
TexCoord *pTexCoords = (TexCoord *)malloc(sizeof(TexCoord) * cTexCoords);
int *pFaces = (int *)malloc(sizeof(int *) * (cFaces + 1));
Vertex3D *pVertice = pVertices;
Vector3D *pNormal = pNormals;
TexCoord *pTexCoord = pTexCoords;
int *pFace = pFaces;
int *pMaterialFaces = pFace++;
*pMaterialFaces = 0;
std::vector<KRMaterial *>::iterator material_itr = materials.begin();
// --------
pScan = (char *)pFile;
while(pScan < pEnd) {
// Scan through whitespace
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t' || *pScan == '\r' || *pScan == '\n')) {
pScan++;
}
if(*pScan == '#') {
// Line is a comment line
// Scan to the end of the line
while(pScan < pEnd && *pScan != '\r' && *pScan != '\n') {
pScan++;
}
} else {
int cSymbols = 0;
while(pScan < pEnd && *pScan != '\n' && *pScan != '\r') {
char *pDest = szSymbol[cSymbols++];
while(pScan < pEnd && *pScan != ' ' && *pScan != '\n' && *pScan != '\r') {
*pDest++ = *pScan++;
}
*pDest = '\0';
// Scan through whitespace, but don't advance to next line
while(pScan < pEnd && (*pScan == ' ' || *pScan == '\t')) {
pScan++;
}
}
if(strcmp(szSymbol[0], "v") == 0) {
// Vertex (v)
char *pChar = szSymbol[1];
pVertice -> x = strtof(pChar, &pChar);
pChar = szSymbol[2];
pVertice -> y = strtof(pChar, &pChar);
pChar = szSymbol[3];
pVertice -> z = strtof(pChar, &pChar);
pVertice++;
} else if(strcmp(szSymbol[0], "vt") == 0) {
// Vertex Texture UV Coordinate (vt)
char *pChar = szSymbol[1];
pTexCoord -> u = strtof(pChar, &pChar);
pChar = szSymbol[2];
pTexCoord -> v = strtof(pChar, &pChar);
pTexCoord++;
} else if(strcmp(szSymbol[0], "vn") == 0) {
// Vertex Normal (vn)
char *pChar = szSymbol[1];
pNormal -> x = strtof(pChar, &pChar);
pChar = szSymbol[2];
pNormal -> y = strtof(pChar, &pChar);
pChar = szSymbol[3];
pNormal -> z = strtof(pChar, &pChar);
pNormal++;
} else if(strcmp(szSymbol[0], "f") == 0) {
// Face (f)
GLint cFaceVertices = cSymbols - 1;
*pFace++ = cFaceVertices;
for(int iSymbol=1; iSymbol < cSymbols; iSymbol++) {
char *pChar = szSymbol[iSymbol];
if(*pChar == '.' || (*pChar >= '0' && *pChar <= '9')) {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Vertex Index
if(*pChar == '/') {
pChar++;
if(*pChar == '/') {
*pFace++ = -1;
} else {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Texture Coordinate Index
}
} else {
*pFace++ = -1;
}
if(*pChar == '/') {
pChar++;
if(*pChar == '/') {
*pFace++ = -1;
} else {
*pFace++ = strtol(pChar, &pChar, 10) - 1; // Normal Index
}
} else {
*pFace++ = -1;
}
while(*pChar == '/') {
pChar++;
strtol(pChar, &pChar, 10);
}
}
}
} else if(strcmp(szSymbol[0], "usemtl") == 0) {
// Use Material (usemtl)
if(pFace - pMaterialFaces > 1) {
*pMaterialFaces = pFace - pMaterialFaces - 1;
pMaterialFaces = pFace++;
}
}
}
}
*pMaterialFaces = pFace - pMaterialFaces - 1;
*pFace++ = 0;
m_pVertexData = (VertexData *)malloc(sizeof(VertexData) * cVertexData);
VertexData *pData = m_pVertexData;
int iVertex = 0;
Material *pMaterial = new Material();
pMaterial->start_vertex = iVertex;
pMaterial->vertex_count = 0;
if(material_itr < materials.end()) {
pMaterial->pMaterial = *material_itr++;
} else {
pMaterial->pMaterial = NULL;
}
m_materials.push_back(pMaterial);
pFace = pFaces;
while(*pFace != 0 && iVertex < cVertexData) {
pMaterial->start_vertex = iVertex;
int *pMaterialEndFace = pFace + *pFace++;
while(pFace < pMaterialEndFace) {
int cFaceVertexes = *pFace;
VertexData *pFirstFaceVertex = NULL;
VertexData *pPrevFaceVertex = NULL;
for(int iFaceVertex=0; iFaceVertex < cFaceVertexes; iFaceVertex++) {
if(iFaceVertex > 2) {
// There have already been 3 vertices. Now we need to split the quad into a second triangle composed of the 1st, 3rd, and 4th vertices
memcpy(pData++, pFirstFaceVertex, sizeof(VertexData));
memcpy(pData++, pPrevFaceVertex, sizeof(VertexData));
iVertex+=2;
}
Vertex3D *pVertex = pVertices + pFace[iFaceVertex*3+1];
if(iFaceVertex==0) {
pFirstFaceVertex = pData;
}
pPrevFaceVertex = pData;
pData->vertex.x = pVertex -> x;
pData->vertex.y = pVertex -> y;
pData->vertex.z = pVertex -> z;
if(pFace[iFaceVertex*3+2] >= 0) {
TexCoord *pTexCoord = pTexCoords + pFace[iFaceVertex*3+2];
pData->texcoord.u = pTexCoord -> u;
pData->texcoord.v = pTexCoord -> v;
} else {
pData->texcoord.u = 0;
pData->texcoord.v = 0;
}
if(pFace[iFaceVertex*3+3] >= 0){
Vector3D *pNormal = pNormals + pFace[iFaceVertex*3+3];
pData->normal.x = pNormal -> x;
pData->normal.y = pNormal -> y;
pData->normal.z = pNormal -> z;
} else {
pData->normal.x = 0;
pData->normal.y = 0;
pData->normal.z = 0;
}
pData++;
iVertex++;
}
pFace += cFaceVertexes * 3 + 1;
}
pMaterial->vertex_count = iVertex - pMaterial->start_vertex;
if(*pFace != 0) {
pMaterial = new Material();
pMaterial->start_vertex = iVertex;
pMaterial->vertex_count = 0;
if(material_itr < materials.end()) {
pMaterial->pMaterial = *material_itr++;
} else {
pMaterial->pMaterial = NULL;
}
m_materials.push_back(pMaterial);
}
}
}
}
}
m_minx = 0.0;
m_miny = 0.0;
m_minz = 0.0;
m_maxx = 0.0;
m_maxy = 0.0;
m_maxz = 0.0;
// Calculate surface normals and tangents
// http://www.terathon.com/code/tangent.html
// http://www.fabiensanglard.net/bumpMapping/index.php
for(std::vector<Material *>::iterator itr = m_materials.begin(); itr != m_materials.end(); itr++) {
VertexData *pStart = m_pVertexData + (*itr)->start_vertex;
VertexData *pEnd = pStart + (*itr)->vertex_count;
for(VertexData *pVertex = pStart; pVertex < pEnd; pVertex+=3) {
if(pVertex->vertex.x < m_minx) m_minx = pVertex->vertex.x;
if(pVertex->vertex.x > m_maxx) m_maxx = pVertex->vertex.x;
if(pVertex->vertex.y < m_miny) m_miny = pVertex->vertex.y;
if(pVertex->vertex.y > m_maxy) m_maxy = pVertex->vertex.y;
if(pVertex->vertex.z < m_minz) m_minz = pVertex->vertex.z;
if(pVertex->vertex.z > m_maxz) m_maxz = pVertex->vertex.z;
}
for(VertexData *pVertex = pStart; pVertex < pEnd; pVertex+=3) {
Vector3 p1(pVertex[0].vertex.x, pVertex[0].vertex.y, pVertex[0].vertex.z);
Vector3 p2(pVertex[1].vertex.x, pVertex[1].vertex.y, pVertex[1].vertex.z);
Vector3 p3(pVertex[2].vertex.x, pVertex[2].vertex.y, pVertex[2].vertex.z);
Vector3 v1 = p2 - p1;
Vector3 v2 = p3 - p1;
// -- Calculate normal --
if(pVertex->normal.x == 0 && pVertex->normal.y == 0 && pVertex->normal.z == 0) {
Vector3 normal = v1.cross( v2 );
normal.normalize();
pVertex[0].normal.x = normal.x;
pVertex[0].normal.y = normal.y;
pVertex[0].normal.z = normal.z;
pVertex[1].normal.x = normal.x;
pVertex[1].normal.y = normal.y;
pVertex[1].normal.z = normal.z;
pVertex[2].normal.x = normal.x;
pVertex[2].normal.y = normal.y;
pVertex[2].normal.z = normal.z;
}
// -- Calculate tangent --
TexCoord st1; // = pVertex[2].texcoord;
TexCoord st2; // = pVertex[1].texcoord;
st1.u = pVertex[1].texcoord.u - pVertex[0].texcoord.u;
st1.v = pVertex[1].texcoord.v - pVertex[0].texcoord.v;
st2.u = pVertex[2].texcoord.u - pVertex[0].texcoord.u;
st2.v = pVertex[2].texcoord.v - pVertex[0].texcoord.v;
double coef = 1/ (st1.u * st2.v - st2.u * st1.v);
pVertex[0].tangent.x = coef * ((v1.x * st2.v) + (v2.x * -st1.v));
pVertex[0].tangent.y = coef * ((v1.y * st2.v) + (v2.y * -st1.v));
pVertex[0].tangent.z = coef * ((v1.z * st2.v) + (v2.z * -st1.v));
Vector3 tangent(
coef * ((v1.x * st2.v) + (v2.x * -st1.v)),
coef * ((v1.y * st2.v) + (v2.y * -st1.v)),
coef * ((v1.z * st2.v) + (v2.z * -st1.v))
);
tangent.normalize();
pVertex[0].tangent.x = tangent.x;
pVertex[0].tangent.y = tangent.y;
pVertex[0].tangent.z = tangent.z;
pVertex[1].tangent.x = tangent.x;
pVertex[1].tangent.y = tangent.y;
pVertex[1].tangent.z = tangent.z;
pVertex[2].tangent.x = tangent.x;
pVertex[2].tangent.y = tangent.y;
pVertex[2].tangent.z = tangent.z;
}
}
if(pFile != NULL) {
munmap(pFile, fileSize);
}
if(fdFile != 0) {
close(fdFile);
}
if(pVertices) {
free(pVertices);
}
if(pNormals) {
free(pNormals);
}
if(pTexCoords) {
free(pTexCoords);
}
if(pFaces) {
free(pFaces);
}
}
KRModel::~KRModel() {
if(m_pPackFile != NULL) {
munmap(m_pPackFile, m_iPackFileSize);
}
if(m_fdPackFile) {
close(m_fdPackFile);
} else {
// If we didn't load a packed file, then the data was calculated at run time and malloc'ed
if(m_pVertexData != NULL) {
free(m_pVertexData);
}
}
if(m_pBuffers != NULL) {
glDeleteBuffers(m_cBuffers, m_pBuffers);
delete m_pBuffers;
}
}
void KRModel::render(GLuint program, GLuint iVertexAttrib, GLuint iNormalAttrib, GLuint iTangentAttrib, GLuint iTexCoordAttrib, KRMaterialManager *pMaterialManager) {
for(std::vector<Material *>::iterator itr = m_materials.begin(); itr != m_materials.end(); itr++) {
KRMaterial *pMaterial = (*itr)->pMaterial;
if(pMaterial != NULL) {
pMaterial->bind(program);
} else {
pMaterial = new KRMaterial();
pMaterial->bind(program);
delete pMaterial;
}
int iVertex = (*itr)->start_vertex;
int iBuffer = iVertex / MAX_VBO_SIZE;
iVertex = iVertex % MAX_VBO_SIZE;
int cVertexes = (*itr)->vertex_count;
while(cVertexes > 0) {
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffers[iBuffer]);
glVertexAttribPointer(iVertexAttrib, 3, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(0));
glEnableVertexAttribArray(iVertexAttrib);
glVertexAttribPointer(iNormalAttrib, 3, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(sizeof(Vertex3D)));
glEnableVertexAttribArray(iNormalAttrib);
glVertexAttribPointer(iTangentAttrib, 3, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(sizeof(Vertex3D) + sizeof(Vector3D)));
glEnableVertexAttribArray(iTangentAttrib);
glVertexAttribPointer(iTexCoordAttrib, 2, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(sizeof(Vertex3D) + sizeof(Vector3D) * 2));
glEnableVertexAttribArray(iTexCoordAttrib);
if(iVertex + cVertexes >= MAX_VBO_SIZE) {
glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex));
cVertexes -= (MAX_VBO_SIZE - iVertex);
iVertex = 0;
iBuffer++;
} else {
glDrawArrays(GL_TRIANGLES, iVertex, cVertexes);
cVertexes = 0;
}
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
GLfloat KRModel::getMaxDimension() {
GLfloat m = 0.0;
if(m_maxx - m_minx > m) m = m_maxx - m_minx;
if(m_maxy - m_miny > m) m = m_maxy - m_miny;
if(m_maxz - m_minz > m) m = m_maxz - m_minz;
return m;
}
GLfloat KRModel::getMinX() {
return m_minx;
}
GLfloat KRModel::getMaxX() {
return m_maxx;
}
GLfloat KRModel::getMinY() {
return m_miny;
}
GLfloat KRModel::getMaxY() {
return m_maxy;
}
GLfloat KRModel::getMinZ() {
return m_minz;
}
GLfloat KRModel::getMaxZ() {
return m_maxz;
}

View File

@@ -0,0 +1,97 @@
//
// KRModel.h
// gldemo
//
// Created by Kearwood Gilbert on 10-09-22.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <stdint.h>
#import <vector>
using std::vector;
#ifndef KRMODEL_I
#define KRMODEL_I
#import "KRMaterialManager.h"
class KRModel {
public:
KRModel(std::string path, KRMaterialManager *pMaterialManager);
~KRModel();
void render(GLuint program, GLuint iVertexAttrib, GLuint iNormalAttrib, GLuint iTangentAttrib, GLuint iTexCoordAttrib, KRMaterialManager *pMaterialManager);
GLfloat getMaxDimension();
GLfloat getMinX();
GLfloat getMaxX();
GLfloat getMinY();
GLfloat getMaxY();
GLfloat getMinZ();
GLfloat getMaxZ();
private:
void loadWavefront(std::string path, KRMaterialManager *pMaterialManager);
void loadPack(std::string path, KRMaterialManager *pMaterialManager);
int m_fdPackFile;
void *m_pPackFile;
int m_iPackFileSize;
typedef struct {
char szTag[16];
float minx, miny, minz, maxx, maxy, maxz;
int32_t vertex_count;
int32_t material_count;
} pack_header;
typedef struct {
int32_t start_vertex;
int32_t vertex_count;
char szName[64];
} pack_material;
typedef struct {
GLfloat x;
GLfloat y;
GLfloat z;
} Vertex3D, Vector3D;
typedef struct {
GLfloat u;
GLfloat v;
} TexCoord;
typedef struct {
Vertex3D vertex;
Vector3D normal;
Vector3D tangent;
TexCoord texcoord;
} VertexData;
VertexData *m_pVertexData;
typedef struct {
GLint start_vertex;
GLsizei vertex_count;
KRMaterial *pMaterial;
} Material;
GLsizei m_cBuffers;
GLuint *m_pBuffers;
vector<Material *> m_materials;
GLfloat m_minx, m_miny, m_minz, m_maxx, m_maxy, m_maxz;
};
#endif // KRMODEL_I

View File

@@ -0,0 +1,9 @@
//
// KRModelManager.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-12-31.
// Copyright 2010 Kearwood Software. All rights reserved.
//
#include "KRModelManager.h"

View File

@@ -0,0 +1,7 @@
//
// KRModelManager.h
// gldemo
//
// Created by Kearwood Gilbert on 10-12-31.
// Copyright 2010 Kearwood Software. All rights reserved.
//

View File

@@ -0,0 +1,206 @@
//
// KRTexture.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-10-23.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#include "KRTexture.h"
#import <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#import <stdint.h>
#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff
static char gPVRTexIdentifier[5] = "PVR!";
enum
{
kPVRTextureFlagTypePVRTC_2 = 24,
kPVRTextureFlagTypePVRTC_4
};
typedef struct _PVRTexHeader
{
uint32_t headerLength;
uint32_t height;
uint32_t width;
uint32_t numMipmaps;
uint32_t flags;
uint32_t dataLength;
uint32_t bpp;
uint32_t bitmaskRed;
uint32_t bitmaskGreen;
uint32_t bitmaskBlue;
uint32_t bitmaskAlpha;
uint32_t pvrTag;
uint32_t numSurfs;
} PVRTexHeader;
KRTexture::KRTexture() {
m_iName = 0;
m_fdFile = 0;
m_pFile = NULL;
m_fileSize = 0;
}
KRTexture::~KRTexture() {
if(m_iName != 0) {
glDeleteTextures(1, &m_iName);
}
if(m_pFile != NULL) {
munmap(m_pFile, m_fileSize);
}
if(m_fdFile != 0) {
close(m_fdFile);
}
}
bool KRTexture::loadFromFile(const char *szFile) {
struct stat statbuf;
m_fdFile = open(szFile, O_RDONLY);
if(m_fdFile < 0) {
return false;
} else {
if(fstat(m_fdFile,&statbuf) < 0) {
return false;
} else {
void *pFile;
if ((pFile = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, m_fdFile, 0))
== (caddr_t) -1) {
return false;
} else {
m_fileSize = statbuf.st_size;
m_pFile = pFile;
PVRTexHeader *header = (PVRTexHeader *)pFile;
uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK;
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
} else if(formatFlags == kPVRTextureFlagTypePVRTC_2) {
m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
}
uint32_t pvrTag = header->pvrTag;
if (gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) ||
gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) ||
gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) ||
gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff))
{
return false;
}
m_iWidth = header->width; // Note: call __builtin_bswap32 when needed to switch endianness
m_iHeight = header->height;
m_bHasAlpha = header->bitmaskAlpha;
uint8_t *bytes = ((uint8_t *)pFile) + sizeof(PVRTexHeader);
uint32_t dataLength = header->dataLength, dataOffset = 0, dataSize = 0;
uint32_t width = m_iWidth, height = m_iHeight, bpp = 4;
uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0;
// Calculate the data size for each texture level and respect the minimum number of blocks
while(dataOffset < dataLength) {
if (formatFlags == kPVRTextureFlagTypePVRTC_4) {
blockSize = 4 * 4; // Pixel by pixel block size for 4bpp
widthBlocks = width / 4;
heightBlocks = height / 4;
bpp = 4;
} else {
blockSize = 8 * 4; // Pixel by pixel block size for 2bpp
widthBlocks = width / 8;
heightBlocks = height / 4;
bpp = 2;
}
// Clamp to minimum number of blocks
if (widthBlocks < 2) {
widthBlocks = 2;
}
if (heightBlocks < 2) {
heightBlocks = 2;
}
dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8);
dataBlockStruct newBlock;
newBlock.start = bytes+dataOffset;
newBlock.length = dataSize;
m_blocks.push_back(newBlock);
dataOffset += dataSize;
width = width >> 1;
if(width < 1) {
width = 1;
}
height = height >> 1;
if(height < 1) {
height = 1;
}
}
return true;
}
}
}
}
bool KRTexture::createGLTexture() {
int width = m_iWidth;
int height = m_iHeight;
GLenum err;
if (m_blocks.size() > 0)
{
if (m_iName != 0) {
glDeleteTextures(1, &m_iName);
}
glGenTextures(1, &m_iName);
glBindTexture(GL_TEXTURE_2D, m_iName);
}
if (m_blocks.size() > 1) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
int i=0;
for(std::list<dataBlockStruct>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
dataBlockStruct block = *itr;
glCompressedTexImage2D(GL_TEXTURE_2D, i, m_internalFormat, width, height, 0, block.length, block.start);
err = glGetError();
if (err != GL_NO_ERROR) {
return false;
}
width = width >> 1;
if(width < 1) {
width = 1;
}
height = height >> 1;
if(height < 1) {
height = 1;
}
i++;
}
return true;
}
GLuint KRTexture::getName() {
if(m_iName == 0) {
createGLTexture();
}
return m_iName;
}

View File

@@ -0,0 +1,47 @@
//
// KRTexture.h
// gldemo
//
// Created by Kearwood Gilbert on 10-10-23.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#import <stdint.h>
#import <list>
using std::list;
#ifndef KRTEXTURE_H
#define KRTEXTURE_H
class KRTexture {
public:
KRTexture();
~KRTexture();
bool loadFromFile(const char *szFile);
bool createGLTexture();
GLuint getName();
private:
GLuint m_iName;
uint32_t m_iWidth;
uint32_t m_iHeight;
GLenum m_internalFormat;
bool m_bHasAlpha;
struct dataBlockStruct {
void *start;
uint32_t length;
};
list<dataBlockStruct> m_blocks;
int m_fdFile;
int m_fileSize;
void *m_pFile;
};
#endif

View File

@@ -0,0 +1,66 @@
//
// KRTextureManager.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-10-14.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#include "KRTextureManager.h"
#include <string.h>
KRTextureManager::KRTextureManager() {
}
KRTextureManager::~KRTextureManager() {
for(map<std::string, KRTexture *>::iterator itr = m_textures.begin(); itr != m_textures.end(); ++itr){
delete (*itr).second;
}
}
KRTexture *KRTextureManager::loadTexture(const char *szName, const char *szPath) {
KRTexture *pTexture = new KRTexture();
if(!pTexture->loadFromFile(szPath)) {
delete pTexture;
return NULL;
}
if(!pTexture->createGLTexture()) {
delete pTexture;
return NULL;
}
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower);
m_textures[lowerName] = pTexture;
return pTexture;
}
GLuint KRTextureManager::getTextureName(const char *szName) {
KRTexture *pTexture = getTexture(szName);
if(pTexture) {
return pTexture->getName();
} else {
return NULL;
}
}
KRTexture *KRTextureManager::getTexture(const char *szName) {
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower);
map<std::string, KRTexture *>::iterator itr = m_textures.find(lowerName);
if(itr == m_textures.end()) {
// Not found
return NULL;
} else {
return (*itr).second;
}
}

View File

@@ -0,0 +1,30 @@
//
// KRTextureManager.h
// gldemo
//
// Created by Kearwood Gilbert on 10-10-14.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#ifndef KRTEXTUREMANAGER_H
#define KRTEXTUREMANAGER_H
#include "KRTexture.h"
#include <map>
using std::map;
class KRTextureManager {
public:
KRTextureManager();
~KRTextureManager();
KRTexture *loadTexture(const char *szName, const char *szPath);
GLuint getTextureName(const char *szName);
KRTexture *getTexture(const char *szFile);
private:
map<std::string, KRTexture *> m_textures;
};
#endif

View File

@@ -0,0 +1,76 @@
//
// KRVector3.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-12-31.
// Copyright 2010 Kearwood Software. All rights reserved.
//
#include "KRVector3.h"
//default constructor
Vector3::Vector3(float X = 0, float Y = 0, float Z = 0)
{
x = X;
y = Y;
z = Z;
}
Vector3::~Vector3()
{
}
//calculate and return the magnitude of this vector
float Vector3::GetMagnitude()
{
return sqrtf(x * x + y * y + z * z);
}
//multiply this vector by a scalar
Vector3 Vector3::operator*(float num) const
{
return Vector3(x * num, y * num, z * num);
}
//pass in a vector, pass in a scalar, return the product
/*
Vector3 Vector3::operator*(float num, Vector3 const &vec)
{
return Vector3(vec.x * num, vec.y * num, vec.z * num);
}
*/
//add two vectors
Vector3 Vector3::operator+(const Vector3 &vec) const
{
return Vector3(x + vec.x, y + vec.y, z + vec.z);
}
//subtract two vectors
Vector3 Vector3::operator-(const Vector3 &vec) const
{
return Vector3(x - vec.x, y - vec.y, z - vec.z);
}
//normalize this vector
void Vector3::normalize()
{
float magnitude = sqrtf(x * x + y * y + z * z);
x /= magnitude;
y /= magnitude;
z /= magnitude;
}
//calculate and return dot product
float Vector3::dot(const Vector3 &vec) const
{
return x * vec.x + y * vec.y + z * vec.z;
}
//calculate and return cross product
Vector3 Vector3::cross(const Vector3 &vec) const
{
return Vector3(y * vec.z - z * vec.y,
z * vec.x - x * vec.z,
x * vec.y - y * vec.x);
}

View File

@@ -0,0 +1,49 @@
//
// KRVector3.h
// gldemo
//
// Created by Kearwood Gilbert on 10-12-31.
// Copyright 2010 Kearwood Software. All rights reserved.
//
#ifndef KRVECTOR3
#define KRVECTOR3
#include <math.h>
class Vector3
{
public:
float x, y, z;
//default constructor
Vector3(float X, float Y, float Z);
~Vector3();
//calculate and return the magnitude of this vector
float GetMagnitude();
//multiply this vector by a scalar
Vector3 operator*(float num) const;
//pass in a vector, pass in a scalar, return the product
//friend Vector3 operator*(float num, Vector3 const &vec);
//add two vectors
Vector3 operator+(const Vector3 &vec) const;
//subtract two vectors
Vector3 operator-(const Vector3 &vec) const;
//normalize this vector
void normalize();
//calculate and return dot product
float dot(const Vector3 &vec) const;
//calculate and return cross product
Vector3 cross(const Vector3 &vec) const;
};
#endif

View File

@@ -0,0 +1,168 @@
//
// Shader.fsh
// gldemo
//
// Based on http://www.fabiensanglard.net/bumpMapping/index.php
/*
// -- Per vertex lighting
uniform sampler2D diffuseTexture, specularTexture, normalTexture;
varying mediump vec2 texCoord;
varying mediump vec3 diffuse;
varying mediump vec3 specular;
void main (void)
{
mediump vec3 texColour = vec3(texture2D(diffuseTexture, texCoord));
mediump vec3 specColor = vec3(texture2D(specularTexture, texCoord));
mediump vec3 normalVal = vec3(texture2D(normalTexture, texCoord));
//mediump vec3 colour = (texColour * diffuse) + specular;
mediump vec3 colour = (texColour * diffuse) + (specColor * specular);
gl_FragColor = vec4(colour, 1.0);
}
*/
/*
// -- Per Pixel lighting, test 1 --
uniform sampler2D diffuseTexture, specularTexture, normalTexture;
uniform mediump vec3 material_ambient, material_diffuse, material_specular;
varying mediump vec2 texCoord;
varying mediump vec3 normal;
varying mediump vec3 ePos;
const mediump float shininess = 4.0;
const mediump vec3 LightPos = vec3(20.0, 00.0, 10.0);
const mediump vec3 LightCol = vec3(2.0,2.0,2.0);
//directional light function //
// spFlg flag using specular or not.
// nrml nrml vector in the eye coordinate.
// ePos vertex position in the eye coordinate.
void DirectionalLight(inout mediump vec3 diffuse, inout mediump vec3 specular, in mediump int spFlg, in mediump vec3 nrml, in mediump vec3 ePos){
// calculate the light direction vector.
mediump vec3 lightDir = normalize(LightPos);
// calculate the half vector between eye position and light position.
mediump vec3 halfV = normalize(-ePos + LightPos);
// calculate diffuse light intensity.
mediump float dVP = max(dot(nrml,lightDir), 0.0);
// calculate approximated specular light base intensity.
mediump float dHV = max(dot(nrml,halfV),0.0);
// if the diffuse is not zero and spFlg is On,
// calculate specular light intensity with shininess,
// or turn off the specular light.
mediump float pf;
if (dVP>.0 && spFlg==1) pf = pow(dHV, shininess);
else pf = 0.0;
diffuse += dVP*LightCol;
specular += pf*LightCol;
}
void main (void)
{
mediump vec3 texColour = vec3(texture2D(diffuseTexture, texCoord));
mediump vec3 specColor = vec3(texture2D(specularTexture, texCoord));
mediump vec3 normalVal = vec3(texture2D(normalTexture, texCoord));
// initalize light intensity parameter.
mediump vec3 diffuse = vec3(0.75);
mediump vec3 specular = vec3(0.0);
DirectionalLight(diffuse, specular, 1, normalize(normal + normalVal), ePos);
specular *= material_specular;
diffuse = diffuse * material_diffuse + material_ambient;
//mediump vec3 colour = (texColour * diffuse) + specular;
mediump vec3 colour = (texColour * diffuse) + (specColor * specular);
gl_FragColor = vec4(colour, 1.0);
}
*/
/*
// -- Per Pixel lighting, test 2 --
uniform sampler2D diffuseTexture, specularTexture, normalTexture;
varying mediump vec2 texCoord;
varying mediump vec3 lightVec;
varying mediump vec3 halfVec;
//varying mediump vec3 eyeVec;
uniform mediump vec3 material_ambient, material_diffuse, material_specular;
void main()
{
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,texCoord).rgb - 1.0);
mediump float lamberFactor= max (dot (lightVec, normal), 0.0);
gl_FragColor = vec4(0.0);
if (lamberFactor > 0.0)
{
// compute diffuse lighting
mediump vec4 diffuseMaterial = texture2D(diffuseTexture, texCoord);
mediump vec4 diffuseLight = vec4(material_diffuse, 1.0) + 1.0; // 1.0 added so there will not be complete darkness
// compute specular lighting
mediump vec4 specularLight = texture2D(specularTexture, texCoord); // Specular value comes from a texture
mediump float shininess = pow (max (dot (halfVec, normal), 0.0), 2.0);
gl_FragColor = diffuseMaterial * diffuseLight * lamberFactor ;
gl_FragColor += vec4(material_specular, 1.0) * specularLight * shininess;
}
// compute ambient
gl_FragColor += vec4(material_ambient, 1.0);;
}
*/
// -- Per Pixel lighting, test 3 --
uniform sampler2D diffuseTexture, specularTexture, normalTexture;
varying mediump vec2 texCoord;
varying mediump vec3 lightVec;
varying mediump vec3 halfVec;
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
void main()
{
// compute diffuse lighting
mediump vec4 diffuseMaterial = texture2D(diffuseTexture, texCoord);
/*
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,texCoord).rgb - 1.0);
mediump float lamberFactor= max (dot (lightVec, normal), 0.0);
// Add ambient light and alpha component from diffuse texture map
gl_FragColor = vec4(material_ambient, diffuseMaterial.w);
// compute specular lighting
mediump vec3 specularLight = vec3(texture2D(specularTexture, texCoord)); // Specular value comes from a texture
mediump float shininess = pow (max (dot (halfVec, normal), 0.0), 2.0);
// Add diffuse light
gl_FragColor += vec4(vec3(diffuseMaterial) * material_diffuse * lamberFactor, 0.0);
// Add specular light
gl_FragColor += vec4(material_specular * specularLight * shininess, 0.0);
*/
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
gl_FragColor = diffuseMaterial;
}

View File

@@ -0,0 +1,171 @@
//
// Shader.vsh
// gldemo
//
// Created by Kearwood Gilbert on 10-09-16.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
/*
// -- Per vertex lighting
attribute highp vec3 myVertex, myNormal;
attribute mediump vec2 myUV;
uniform mediump mat4 myMVPMatrix, myModelView; // mvpmatrix is the result of multiplying the model, view, and projection matrices
uniform mediump mat3 myModelViewIT;
uniform mediump vec3 material_ambient, material_diffuse, material_specular;
varying mediump vec2 texCoord;
varying mediump vec3 diffuse, specular;
varying mediump vec3 normal;
const mediump float shininess = 4.0;
const mediump float cutoff = 0.975, exp = 100.0;
const mediump vec3 LightPos = vec3(20.0, 00.0, 10.0);
const mediump vec3 LightCol = vec3(2.0,2.0,2.0);
//directional light function //
// spFlg flag using specular or not.
// nrml nrml vector in the eye coordinate.
// ePos vertex position in the eye coordinate.
void DirectionalLight(in mediump int spFlg, in mediump vec3 nrml, in mediump vec3 ePos){
// calculate the light direction vector.
mediump vec3 lightDir = normalize(LightPos);
// calculate the half vector between eye position and light position.
mediump vec3 halfV = normalize(-ePos + LightPos);
// calculate diffuse light intensity.
mediump float dVP = max(dot(nrml,lightDir), 0.0);
// calculate approximated specular light base intensity.
mediump float dHV = max(dot(nrml,halfV),0.0);
// if the diffuse is not zero and spFlg is On,
// calculate specular light intensity with shininess,
// or turn off the specular light.
mediump float pf;
if (dVP>.0 && spFlg==1) pf = pow(dHV, shininess);
else pf = 0.0;
diffuse += dVP*LightCol;
specular += pf*LightCol;
}
// main function //
void main(void){
// transform the normal vector from the model coordinate to the eye coordinate.
normal = normalize(myModelViewIT * myNormal);
// calculate the vertex position in the eye coordinate.
highp vec3 ePos = vec3(myModelView * vec4(myVertex,1.0));
// initalize light intensity parameter.
//diffuse = material_ambient;
diffuse = vec3(0.75);
specular = vec3(0.0);
DirectionalLight(1, normal, ePos);
specular *= material_specular;
diffuse = diffuse * material_diffuse + material_ambient;
// Transform position
gl_Position = myMVPMatrix * vec4(myVertex,1.0);
// Pass UV co-ordinates
texCoord = myUV.st;
}
*/
/*
// -- Per Pixel lighting, test 1 --
attribute highp vec3 myVertex, myNormal, myTangent;
attribute mediump vec2 myUV;
uniform mediump mat4 myMVPMatrix, myModelView; // mvpmatrix is the result of multiplying the model, view, and projection matrices
uniform mediump mat3 myModelViewIT;
uniform mediump vec3 material_ambient, material_diffuse, material_specular;
varying mediump vec2 texCoord;
varying mediump vec3 normal;
varying mediump vec3 ePos;
// main function //
void main(void){
// Transform position
gl_Position = myMVPMatrix * vec4(myVertex,1.0);
// Pass UV co-ordinates
texCoord = myUV.st;
// transform the normal vector from the model coordinate to the eye coordinate.
normal = normalize(myModelViewIT * myNormal);
// calculate the vertex position in the eye coordinate.
ePos = vec3(myModelView * vec4(myVertex,1.0));
//mat_ambient = material_ambient;
//mat_diffuse = material_diffuse;
//mat_specular = material_specular;
}
*/
// -- Per Pixel lighting, test 2 --
const mediump vec3 LightPos = vec3(40, 20.0, -90.0);
attribute highp vec3 myVertex, myNormal;
attribute highp vec3 myTangent;
attribute mediump vec2 myUV;
uniform highp mat4 myMVPMatrix, myModelView; // mvpmatrix is the result of multiplying the model, view, and projection matrices
uniform highp mat3 myModelViewIT;
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
varying mediump vec2 texCoord;
/*
varying mediump vec3 lightVec;
varying mediump vec3 halfVec;
*/
//varying mediump vec3 eyeVec;
void main()
{
// Transform position
gl_Position = myMVPMatrix * vec4(myVertex,1.0);
// Pass UV co-ordinates
texCoord = myUV.st;
/*
// Building the matrix Eye Space -> Tangent Space
vec3 n = normalize(vec3(myModelView * vec4(myNormal, 1.0)));
vec3 t = normalize(vec3(myModelView * vec4(myTangent, 1.0)));
vec3 b = cross(n, t);
vec3 vertexPosition = vec3(myMVPMatrix * vec4(myVertex, 1.0));
vec3 lightDir = normalize(LightPos - vertexPosition);
// transform light and half angle vectors by tangent basis
vec3 v;
v.x = dot(lightDir, t);
v.y = dot(lightDir, b);
v.z = dot(lightDir, n);
lightVec = normalize(v);
// v.x = dot(vertexPosition, t);
// v.y = dot(vertexPosition, b);
// v.z = dot(vertexPosition, n);
// eyeVec = normalize(v);
vertexPosition = normalize(vertexPosition);
// Normalize the halfVector to pass it to the fragment shader
vec3 halfVector = normalize((vertexPosition + lightDir) / 2.0);
v.x = dot (halfVector, t);
v.y = dot (halfVector, b);
v.z = dot (halfVector, n);
halfVec = normalize (v);
*/
}

View File

@@ -0,0 +1,150 @@
#define DOF_QUALITY 0
#define ENABLE_VIDEO_BG 0
#define PIXEL_SHIFT_1 0.001
#define PIXEL_SHIFT_2 0.002
#define PIXEL_SHIFT_3 0.003
#define PIXEL_SHIFT_4 0.004
varying mediump vec2 textureCoordinate;
precision lowp float;
#if ENABLE_VIDEO_BG == 0
uniform lowp sampler2D videoFrame;
#endif
uniform lowp sampler2D renderFrame;
uniform lowp sampler2D depthFrame;
void main()
{
lowp vec4 renderColor = texture2D(renderFrame, textureCoordinate);
mediump float depth = texture2D(depthFrame, textureCoordinate).r;
mediump vec4 pixelColor = renderColor;
#if DOF_QUALITY == 2
// Render high quality circle of confusion
// __XXX__
// _XXXXX_
// _XXXXX_
// _XXXXX_
// __XXX__
mediump float cf1 = PIXEL_SHIFT_1;
mediump float cf2 = PIXEL_SHIFT_2;
mediump float bx1 = textureCoordinate.s + cf1;
mediump float bx2 = textureCoordinate.s + cf2;
mediump float bxm1 = textureCoordinate.s - cf1;
mediump float bxm2 = textureCoordinate.s - cf2;
mediump float by1 = textureCoordinate.t + cf1;
mediump float by2 = textureCoordinate.t + cf2;
mediump float bym1 = textureCoordinate.t - cf1;
mediump float bym2 = textureCoordinate.t - cf2;
pixelColor += texture2D(renderFrame, vec2(bx1, textureCoordinate.t));
pixelColor += texture2D(renderFrame, vec2(bxm1, textureCoordinate.t));
pixelColor += texture2D(renderFrame, vec2(bx2, textureCoordinate.t));
pixelColor += texture2D(renderFrame, vec2(bxm2, textureCoordinate.t));
pixelColor += texture2D(renderFrame, vec2(textureCoordinate.s, by1));
pixelColor += texture2D(renderFrame, vec2(bx1, by1));
pixelColor += texture2D(renderFrame, vec2(bxm1, by1));
pixelColor += texture2D(renderFrame, vec2(bx2, by1));
pixelColor += texture2D(renderFrame, vec2(bxm2, by1));
pixelColor += texture2D(renderFrame, vec2(textureCoordinate.s, by2));
pixelColor += texture2D(renderFrame, vec2(bx1, by2));
pixelColor += texture2D(renderFrame, vec2(bxm1, by2));
pixelColor += texture2D(renderFrame, vec2(textureCoordinate.s,bym1));
pixelColor += texture2D(renderFrame, vec2(bx1,bym1));
pixelColor += texture2D(renderFrame, vec2(bxm1,bym1));
pixelColor += texture2D(renderFrame, vec2(bx2,bym1));
pixelColor += texture2D(renderFrame, vec2(bxm2,bym1));
pixelColor += texture2D(renderFrame, vec2(bx1, bym2));
pixelColor += texture2D(renderFrame, vec2(bx1, bym2));
pixelColor += texture2D(renderFrame, vec2(bxm1, bym2));
pixelColor /= 21.0;
#endif
// DOF_QUALITY == 2
#if DOF_QUALITY == 1
// Render low quality circle of confusion
// ___X___
// __XXX__
// _XXXXX_
// __XXX__
// ___X___
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(0, -PIXEL_SHIFT_2));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(-PIXEL_SHIFT_1, -PIXEL_SHIFT_1));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(0, -PIXEL_SHIFT_1));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(+PIXEL_SHIFT_1, -PIXEL_SHIFT_1));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(-PIXEL_SHIFT_2, 0));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(-PIXEL_SHIFT_1, 0));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(+PIXEL_SHIFT_1, 0));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(+PIXEL_SHIFT_2, 0));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(-PIXEL_SHIFT_1, -PIXEL_SHIFT_1));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(0, -PIXEL_SHIFT_1));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(+PIXEL_SHIFT_1, -PIXEL_SHIFT_1));
pixelColor += texture2D(renderFrame, textureCoordinate + vec2(0, -PIXEL_SHIFT_2));
pixelColor /= 13.0;
#endif
// DOF_QUALITY == 1
#if DOF_QUALITY > 0
mediump float focusDepth = texture2D(depthFrame, vec2(0.5, 0.5)).r;
mediump float blurAmount = clamp((depth - focusDepth) * 10.0, 0.0, 1.0);
pixelColor = pixelColor * blurAmount + renderColor * (1.0 - blurAmount);
#endif
// ---- DEPTH_OF_FIELD END ----
// ---- NIGHT_TIME START ----
// Un-comment to enable night time / flash effect
// pixelColor *= 1.0 - clamp((depth - 0.7) * 2.0, 0.0, 1.0);
// ---- NIGHT_TIME END ----
// ---- VIDEO_BG START ----
/*
// Overlay video background
if(depth == 1.0) {
//FILTER COLOR BY CALCULATING PER PIXEL DOT PRODUCT
pixelColor = vec4(dot(vec3(texture2D(videoFrame, textureCoordinate)), vec3(.222, .707, .071)));
}
*/
// ---- VIDEO_BG END ----
// ---- VIGNETTE START ----
// Render vignette effect
// pixelColor *= 1.0 - clamp((distance(textureCoordinate, vec2(0.5, 0.5)) - 0.4), 0.0, 1.0);
// ---- VIGNETTE END ----
gl_FragColor = pixelColor;
//PASSTHROUGH STATEMENT
// gl_FragColor = texture2D(depthFrame, textureCoordinate);
//gl_FragColor = vec4(vec3(blurAmount), 1.0);
}

View File

@@ -0,0 +1,10 @@
attribute vec4 position;
attribute lowp vec4 inputTextureCoordinate;
varying mediump vec2 textureCoordinate;
void main()
{
gl_Position = position;
textureCoordinate = inputTextureCoordinate.xy;
}

View File

@@ -0,0 +1,35 @@
// -- Per Pixel lighting, test 3 --
uniform sampler2D diffuseTexture, specularTexture, normalTexture;
varying mediump vec2 texCoord;
varying mediump vec3 lightVec;
varying mediump vec3 halfVec;
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
void main()
{
// compute diffuse lighting
mediump vec4 diffuseMaterial = texture2D(diffuseTexture, texCoord);
/*
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,texCoord).rgb - 1.0);
mediump float lamberFactor= max (dot (lightVec, normal), 0.0);
// Add ambient light and alpha component from diffuse texture map
gl_FragColor = vec4(material_ambient, diffuseMaterial.w);
// compute specular lighting
mediump vec3 specularLight = vec3(texture2D(specularTexture, texCoord)); // Specular value comes from a texture
mediump float shininess = pow (max (dot (halfVec, normal), 0.0), 2.0);
// Add diffuse light
gl_FragColor += vec4(vec3(diffuseMaterial) * material_diffuse * lamberFactor, 0.0);
// Add specular light
gl_FragColor += vec4(material_specular * specularLight * shininess, 0.0);
*/
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
gl_FragColor = diffuseMaterial;
}

View File

@@ -0,0 +1,58 @@
const mediump vec3 LightPos = vec3(40, 20.0, -90.0);
attribute highp vec3 myVertex, myNormal;
attribute highp vec3 myTangent;
attribute mediump vec2 myUV;
uniform highp mat4 myMVPMatrix, myModelView; // mvpmatrix is the result of multiplying the model, view, and projection matrices
uniform highp mat3 myModelViewIT;
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
varying mediump vec2 texCoord;
/*
varying mediump vec3 lightVec;
varying mediump vec3 halfVec;
*/
//varying mediump vec3 eyeVec;
void main()
{
// Transform position
gl_Position = myMVPMatrix * vec4(myVertex,1.0);
// Pass UV co-ordinates
texCoord = myUV.st;
/*
// Building the matrix Eye Space -> Tangent Space
vec3 n = normalize(vec3(myModelView * vec4(myNormal, 1.0)));
vec3 t = normalize(vec3(myModelView * vec4(myTangent, 1.0)));
vec3 b = cross(n, t);
vec3 vertexPosition = vec3(myMVPMatrix * vec4(myVertex, 1.0));
vec3 lightDir = normalize(LightPos - vertexPosition);
// transform light and half angle vectors by tangent basis
vec3 v;
v.x = dot(lightDir, t);
v.y = dot(lightDir, b);
v.z = dot(lightDir, n);
lightVec = normalize(v);
// v.x = dot(vertexPosition, t);
// v.y = dot(vertexPosition, b);
// v.z = dot(vertexPosition, n);
// eyeVec = normalize(v);
vertexPosition = normalize(vertexPosition);
// Normalize the halfVector to pass it to the fragment shader
vec3 halfVector = normalize((vertexPosition + lightDir) / 2.0);
v.x = dot (halfVector, t);
v.y = dot (halfVector, b);
v.z = dot (halfVector, n);
halfVec = normalize (v);
*/
}

View File

@@ -0,0 +1,38 @@
<?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>English</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>UIFileSharingEnabled</key>
<true/>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.kearwood.${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>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
<key>NSMainNibFile~ipad</key>
<string>MainWindow-iPad</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
</dict>
</plist>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,349 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
1063FBAC136BA13F00EE555B /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1063FBAB136BA13F00EE555B /* CoreMedia.framework */; };
1063FBAE136BA13F00EE555B /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1063FBAD136BA13F00EE555B /* CoreVideo.framework */; };
1063FBB0136BA13F00EE555B /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1063FBAF136BA13F00EE555B /* OpenGLES.framework */; };
1063FBB2136BA13F00EE555B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1063FBB1136BA13F00EE555B /* QuartzCore.framework */; };
1063FC77136D6A1B00EE555B /* KRObjViewGLView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1063FC76136D6A1B00EE555B /* KRObjViewGLView.mm */; };
1D3623260D0F684500981E51 /* KRObjViewAppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* KRObjViewAppDelegate.mm */; };
1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
288765A50DF7441C002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765A40DF7441C002DB57D /* CoreGraphics.framework */; };
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; };
28D7ACF80DDB3853001CB0EB /* KRObjViewViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* KRObjViewViewController.mm */; };
E43A7A6E13CA2BA2000A565E /* libKREngine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E43A7A6D13CA2BA2000A565E /* libKREngine.a */; };
E46FED2D13C9A49F009F5814 /* ShadowShader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2113C9A488009F5814 /* ShadowShader.vsh */; };
E46FED2E13C9A49F009F5814 /* ShadowShader.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2213C9A488009F5814 /* ShadowShader.fsh */; };
E46FED2F13C9A49F009F5814 /* PostShader.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2313C9A488009F5814 /* PostShader.fsh */; };
E46FED3013C9A49F009F5814 /* ObjectShader.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2413C9A488009F5814 /* ObjectShader.fsh */; };
E46FED3113C9A49F009F5814 /* ObjectShader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2513C9A488009F5814 /* ObjectShader.vsh */; };
E46FED3213C9A49F009F5814 /* PostShader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2613C9A488009F5814 /* PostShader.vsh */; };
E49EB29C13806C5D00A4E727 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
1063FBAB136BA13F00EE555B /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
1063FBAD136BA13F00EE555B /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; };
1063FBAF136BA13F00EE555B /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
1063FBB1136BA13F00EE555B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
1063FC75136D6A1B00EE555B /* KRObjViewGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRObjViewGLView.h; sourceTree = "<group>"; };
1063FC76136D6A1B00EE555B /* KRObjViewGLView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KRObjViewGLView.mm; sourceTree = "<group>"; };
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1D3623240D0F684500981E51 /* KRObjViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRObjViewAppDelegate.h; sourceTree = "<group>"; };
1D3623250D0F684500981E51 /* KRObjViewAppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KRObjViewAppDelegate.mm; sourceTree = "<group>"; };
1D6058910D05DD3D006BFB54 /* KRObjView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KRObjView.app; sourceTree = BUILT_PRODUCTS_DIR; };
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
288765A40DF7441C002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
28AD733E0D9D9553002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
28D7ACF60DDB3853001CB0EB /* KRObjViewViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRObjViewViewController.h; sourceTree = "<group>"; };
28D7ACF70DDB3853001CB0EB /* KRObjViewViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KRObjViewViewController.mm; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* KRObjView_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRObjView_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* KRObjView-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "KRObjView-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
E43A7A6D13CA2BA2000A565E /* libKREngine.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libKREngine.a; sourceTree = BUILT_PRODUCTS_DIR; };
E46FED2113C9A488009F5814 /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.vsh; path = ../KREngine/KREngine/Shaders/ShadowShader.vsh; sourceTree = "<group>"; };
E46FED2213C9A488009F5814 /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = ../KREngine/KREngine/Shaders/ShadowShader.fsh; sourceTree = "<group>"; };
E46FED2313C9A488009F5814 /* PostShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.fsh; path = ../KREngine/KREngine/Shaders/PostShader.fsh; sourceTree = "<group>"; };
E46FED2413C9A488009F5814 /* ObjectShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ObjectShader.fsh; path = ../KREngine/KREngine/Shaders/ObjectShader.fsh; sourceTree = "<group>"; };
E46FED2513C9A488009F5814 /* ObjectShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ObjectShader.vsh; path = ../KREngine/KREngine/Shaders/ObjectShader.vsh; sourceTree = "<group>"; };
E46FED2613C9A488009F5814 /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = ../KREngine/KREngine/Shaders/PostShader.vsh; sourceTree = "<group>"; };
E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
1D60588F0D05DD3D006BFB54 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E43A7A6E13CA2BA2000A565E /* libKREngine.a in Frameworks */,
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765A50DF7441C002DB57D /* CoreGraphics.framework in Frameworks */,
1063FBAC136BA13F00EE555B /* CoreMedia.framework in Frameworks */,
1063FBAE136BA13F00EE555B /* CoreVideo.framework in Frameworks */,
1063FBB0136BA13F00EE555B /* OpenGLES.framework in Frameworks */,
1063FBB2136BA13F00EE555B /* QuartzCore.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
1D3623240D0F684500981E51 /* KRObjViewAppDelegate.h */,
1D3623250D0F684500981E51 /* KRObjViewAppDelegate.mm */,
28D7ACF60DDB3853001CB0EB /* KRObjViewViewController.h */,
28D7ACF70DDB3853001CB0EB /* KRObjViewViewController.mm */,
1063FC75136D6A1B00EE555B /* KRObjViewGLView.h */,
1063FC76136D6A1B00EE555B /* KRObjViewGLView.mm */,
);
path = Classes;
sourceTree = "<group>";
};
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
1D6058910D05DD3D006BFB54 /* KRObjView.app */,
);
name = Products;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
E43A7A6D13CA2BA2000A565E /* libKREngine.a */,
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
E49EB29A13806C5B00A4E727 /* iPad */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
name = CustomTemplate;
sourceTree = "<group>";
};
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
32CA4F630368D1EE00C91783 /* KRObjView_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
);
name = "Other Sources";
sourceTree = "<group>";
};
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
E400687C1373AB6400B3D28B /* Assets */,
28AD733E0D9D9553002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* KRObjView-Info.plist */,
);
name = Resources;
sourceTree = "<group>";
};
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,
1D30AB110D05D00D00671497 /* Foundation.framework */,
288765A40DF7441C002DB57D /* CoreGraphics.framework */,
1063FBAB136BA13F00EE555B /* CoreMedia.framework */,
1063FBAD136BA13F00EE555B /* CoreVideo.framework */,
1063FBAF136BA13F00EE555B /* OpenGLES.framework */,
1063FBB1136BA13F00EE555B /* QuartzCore.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
E400687C1373AB6400B3D28B /* Assets */ = {
isa = PBXGroup;
children = (
E46FED2013C9A472009F5814 /* Shaders */,
);
name = Assets;
sourceTree = "<group>";
};
E46FED2013C9A472009F5814 /* Shaders */ = {
isa = PBXGroup;
children = (
E46FED2113C9A488009F5814 /* ShadowShader.vsh */,
E46FED2213C9A488009F5814 /* ShadowShader.fsh */,
E46FED2313C9A488009F5814 /* PostShader.fsh */,
E46FED2413C9A488009F5814 /* ObjectShader.fsh */,
E46FED2513C9A488009F5814 /* ObjectShader.vsh */,
E46FED2613C9A488009F5814 /* PostShader.vsh */,
);
name = Shaders;
sourceTree = "<group>";
};
E49EB29A13806C5B00A4E727 /* iPad */ = {
isa = PBXGroup;
children = (
E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */,
);
name = iPad;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
1D6058900D05DD3D006BFB54 /* KRObjView */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "KRObjView" */;
buildPhases = (
1D60588D0D05DD3D006BFB54 /* Resources */,
1D60588E0D05DD3D006BFB54 /* Sources */,
1D60588F0D05DD3D006BFB54 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = KRObjView;
productName = AVCapTest;
productReference = 1D6058910D05DD3D006BFB54 /* KRObjView.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "KRObjView" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Japanese,
French,
German,
en,
);
mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
projectDirPath = "";
projectRoot = "";
targets = (
1D6058900D05DD3D006BFB54 /* KRObjView */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
1D60588D0D05DD3D006BFB54 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E46FED2D13C9A49F009F5814 /* ShadowShader.vsh in Resources */,
E46FED2E13C9A49F009F5814 /* ShadowShader.fsh in Resources */,
E46FED2F13C9A49F009F5814 /* PostShader.fsh in Resources */,
E46FED3013C9A49F009F5814 /* ObjectShader.fsh in Resources */,
E46FED3113C9A49F009F5814 /* ObjectShader.vsh in Resources */,
E46FED3213C9A49F009F5814 /* PostShader.vsh in Resources */,
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
E49EB29C13806C5D00A4E727 /* MainWindow-iPad.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
1D60588E0D05DD3D006BFB54 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1D3623260D0F684500981E51 /* KRObjViewAppDelegate.mm in Sources */,
28D7ACF80DDB3853001CB0EB /* KRObjViewViewController.mm in Sources */,
1063FC77136D6A1B00EE555B /* KRObjViewGLView.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
1D6058940D05DD3E006BFB54 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = KRObjView_Prefix.pch;
"HEADER_SEARCH_PATHS[arch=*]" = /Users/kearwood/Documents/dev/svn/sarofax/tools/krengine/trunk/KREngine/KREngine/Classes;
INFOPLIST_FILE = "KRObjView-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)\"",
);
PRODUCT_NAME = KRObjView;
TARGETED_DEVICE_FAMILY = "1,2";
USER_HEADER_SEARCH_PATHS = "/Users/applemac/circa1948/circa1948_circa1948/tools/krengine/**";
};
name = Debug;
};
1D6058950D05DD3E006BFB54 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = KRObjView_Prefix.pch;
"HEADER_SEARCH_PATHS[arch=*]" = /Users/kearwood/Documents/dev/svn/sarofax/tools/krengine/trunk/KREngine/KREngine/Classes;
INFOPLIST_FILE = "KRObjView-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)\"",
);
PRODUCT_NAME = KRObjView;
TARGETED_DEVICE_FAMILY = "1,2";
USER_HEADER_SEARCH_PATHS = "/Users/applemac/circa1948/circa1948_circa1948/tools/krengine/**";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = iphoneos;
};
name = Debug;
};
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
SDKROOT = iphoneos;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "KRObjView" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1D6058940D05DD3E006BFB54 /* Debug */,
1D6058950D05DD3E006BFB54 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "KRObjView" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
C01FCF5008A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:KRObjView.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'KRObjView' target in the 'KRObjView' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif

262
objview/MainWindow.xib Normal file
View File

@@ -0,0 +1,262 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1024</int>
<string key="IBDocument.SystemVersion">10K540</string>
<string key="IBDocument.InterfaceBuilderVersion">1305</string>
<string key="IBDocument.AppKitVersion">1038.36</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">300</string>
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>IBUICustomObject</string>
<string>IBUIWindow</string>
<string>IBUIViewController</string>
<string>IBProxyObject</string>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys" id="0">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<reference key="dict.values" ref="0"/>
</object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBProxyObject" id="841351856">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBProxyObject" id="427554174">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUICustomObject" id="664661524">
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIViewController" id="943309135">
<string key="IBUINibName">KRObjViewViewController</string>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="IBUIInterfaceOrientation">1</int>
<int key="interfaceOrientation">1</int>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
</object>
<object class="IBUIWindow" id="117978783">
<nil key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<string key="NSFrameSize">{320, 480}</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIResizesToFullScreen">YES</bool>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="841351856"/>
<reference key="destination" ref="664661524"/>
</object>
<int key="connectionID">4</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">viewController</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="943309135"/>
</object>
<int key="connectionID">11</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">window</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="117978783"/>
</object>
<int key="connectionID">14</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBObjectRecord">
<int key="objectID">0</int>
<reference key="object" ref="0"/>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="841351856"/>
<reference key="parent" ref="0"/>
<string key="objectName">File's Owner</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">3</int>
<reference key="object" ref="664661524"/>
<reference key="parent" ref="0"/>
<string key="objectName">KRObjView App Delegate</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">-2</int>
<reference key="object" ref="427554174"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">10</int>
<reference key="object" ref="943309135"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">12</int>
<reference key="object" ref="117978783"/>
<reference key="parent" ref="0"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.CustomClassName</string>
<string>-2.CustomClassName</string>
<string>10.CustomClassName</string>
<string>10.IBEditorWindowLastContentRect</string>
<string>10.IBPluginDependency</string>
<string>12.IBEditorWindowLastContentRect</string>
<string>12.IBPluginDependency</string>
<string>3.CustomClassName</string>
<string>3.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIApplication</string>
<string>UIResponder</string>
<string>KRObjViewViewController</string>
<string>{{234, 376}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>{{525, 346}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>KRObjViewAppDelegate</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0"/>
<reference key="dict.values" ref="0"/>
</object>
<nil key="activeLocalization"/>
<object class="NSMutableDictionary" key="localizations">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0"/>
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">15</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">KRObjViewAppDelegate</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="outlets">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>viewController</string>
<string>window</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>KRObjViewViewController</string>
<string>UIWindow</string>
</object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>viewController</string>
<string>window</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
<string key="name">viewController</string>
<string key="candidateClassName">KRObjViewViewController</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">window</string>
<string key="candidateClassName">UIWindow</string>
</object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/KRObjViewAppDelegate.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">KRObjViewViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">overlayLayer</string>
<string key="NS.object.0">CALayer</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">overlayLayer</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">overlayLayer</string>
<string key="candidateClassName">CALayer</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/KRObjViewViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">CALayer</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/CALayer.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<integer value="1024" key="NS.object.0"/>
</object>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
<integer value="3100" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">300</string>
</data>
</archive>

View File

@@ -0,0 +1,274 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1056</int>
<string key="IBDocument.SystemVersion">10J869</string>
<string key="IBDocument.InterfaceBuilderVersion">1305</string>
<string key="IBDocument.AppKitVersion">1038.35</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">300</string>
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>IBUICustomObject</string>
<string>IBUIWindow</string>
<string>IBUIViewController</string>
<string>IBProxyObject</string>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys" id="0">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<reference key="dict.values" ref="0"/>
</object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBProxyObject" id="841351856">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<object class="IBProxyObject" id="427554174">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<object class="IBUICustomObject" id="664661524">
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<object class="IBUIViewController" id="943309135">
<string key="IBUINibName">KRObjViewViewController</string>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics" id="252857993">
<int key="IBUIStatusBarStyle">2</int>
</object>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="IBUIInterfaceOrientation">1</int>
<int key="interfaceOrientation">1</int>
</object>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<bool key="IBUIHorizontal">NO</bool>
</object>
<object class="IBUIWindow" id="117978783">
<nil key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<string key="NSFrameSize">{768, 1024}</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<reference key="IBUISimulatedStatusBarMetrics" ref="252857993"/>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<bool key="IBUIResizesToFullScreen">YES</bool>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="841351856"/>
<reference key="destination" ref="664661524"/>
</object>
<int key="connectionID">4</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">viewController</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="943309135"/>
</object>
<int key="connectionID">11</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">window</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="117978783"/>
</object>
<int key="connectionID">14</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBObjectRecord">
<int key="objectID">0</int>
<reference key="object" ref="0"/>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="841351856"/>
<reference key="parent" ref="0"/>
<string key="objectName">File's Owner</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">3</int>
<reference key="object" ref="664661524"/>
<reference key="parent" ref="0"/>
<string key="objectName">KRObjView App Delegate</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">-2</int>
<reference key="object" ref="427554174"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">10</int>
<reference key="object" ref="943309135"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">12</int>
<reference key="object" ref="117978783"/>
<reference key="parent" ref="0"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.CustomClassName</string>
<string>-2.CustomClassName</string>
<string>10.CustomClassName</string>
<string>10.IBEditorWindowLastContentRect</string>
<string>10.IBLastUsedUIStatusBarStylesToTargetRuntimesMap</string>
<string>10.IBPluginDependency</string>
<string>12.IBEditorWindowLastContentRect</string>
<string>12.IBLastUsedUIStatusBarStylesToTargetRuntimesMap</string>
<string>12.IBPluginDependency</string>
<string>3.CustomClassName</string>
<string>3.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIApplication</string>
<string>UIResponder</string>
<string>KRObjViewViewController</string>
<string>{{234, 376}, {320, 480}}</string>
<object class="NSMutableDictionary">
<string key="NS.key.0">IBCocoaTouchFramework</string>
<integer value="0" key="NS.object.0"/>
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>{{525, 346}, {320, 480}}</string>
<object class="NSMutableDictionary">
<string key="NS.key.0">IBCocoaTouchFramework</string>
<integer value="0" key="NS.object.0"/>
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>KRObjViewAppDelegate</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0"/>
<reference key="dict.values" ref="0"/>
</object>
<nil key="activeLocalization"/>
<object class="NSMutableDictionary" key="localizations">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0"/>
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">15</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">KRObjViewAppDelegate</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="outlets">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>viewController</string>
<string>window</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>KRObjViewViewController</string>
<string>UIWindow</string>
</object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>viewController</string>
<string>window</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
<string key="name">viewController</string>
<string key="candidateClassName">KRObjViewViewController</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">window</string>
<string key="candidateClassName">UIWindow</string>
</object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/KRObjViewAppDelegate.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">KRObjViewViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">overlayLayer</string>
<string key="NS.object.0">CALayer</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">overlayLayer</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">overlayLayer</string>
<string key="candidateClassName">CALayer</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/KRObjViewViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">CALayer</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/CALayer.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<integer value="1056" key="NS.object.0"/>
</object>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
<integer value="3100" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">300</string>
</data>
</archive>

17
objview/main.m Normal file
View File

@@ -0,0 +1,17 @@
//
// main.m
// KRObjView
//
// Created by Mac on 11-04-29.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}