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,380 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
E414BAE21435557300A668C4 /* KRInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRInstance.h */; };
E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRInstance.cpp */; };
E414BAE7143557D200A668C4 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; };
E414BAE91435585A00A668C4 /* KRScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE81435585A00A668C4 /* KRScene.cpp */; };
E414BAEB14355E5500A668C4 /* KRBoundingVolume.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAEA14355E5500A668C4 /* KRBoundingVolume.h */; };
E414BAED14355EFF00A668C4 /* KRBoundingVolume.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */; };
E47C25A213F4F65A00FF4370 /* KRShaderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A113F4F65A00FF4370 /* KRShaderManager.h */; };
E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A413F4F66F00FF4370 /* KRShader.h */; };
E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */; };
E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A813F4F6DD00FF4370 /* KRShader.cpp */; };
E48B3CBD14393DF5000C50E2 /* KRCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = E48B3CBC14393DF5000C50E2 /* KRCamera.h */; };
E48B3CC014393E30000C50E2 /* KRCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */; };
E491016513C99B9E0098455B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E491016413C99B9E0098455B /* Foundation.framework */; };
E491018713C99BDC0098455B /* KREngine.mm in Sources */ = {isa = PBXBuildFile; fileRef = E491016F13C99BDC0098455B /* KREngine.mm */; };
E491018A13C99BDC0098455B /* KREngine.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017213C99BDC0098455B /* KREngine.h */; settings = {ATTRIBUTES = (Public, ); }; };
E491018E13C99BDC0098455B /* KRMat4.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017613C99BDC0098455B /* KRMat4.h */; settings = {ATTRIBUTES = (Public, ); }; };
E491018F13C99BDC0098455B /* KRMat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017713C99BDC0098455B /* KRMat4.cpp */; };
E491019113C99BDC0098455B /* KRModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017913C99BDC0098455B /* KRModel.cpp */; };
E491019213C99BDC0098455B /* KRModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017A13C99BDC0098455B /* KRModel.h */; settings = {ATTRIBUTES = (Public, ); }; };
E491019313C99BDC0098455B /* KRMaterialManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017B13C99BDC0098455B /* KRMaterialManager.cpp */; };
E491019413C99BDC0098455B /* KRMaterial.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017C13C99BDC0098455B /* KRMaterial.cpp */; };
E491019513C99BDC0098455B /* KRMaterial.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017D13C99BDC0098455B /* KRMaterial.h */; settings = {ATTRIBUTES = (Private, ); }; };
E491019613C99BDC0098455B /* KRVector3.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017E13C99BDC0098455B /* KRVector3.h */; settings = {ATTRIBUTES = (Public, ); }; };
E491019713C99BDC0098455B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017F13C99BDC0098455B /* KRVector3.cpp */; };
E491019813C99BDC0098455B /* KRTextureManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018013C99BDC0098455B /* KRTextureManager.cpp */; };
E491019913C99BDC0098455B /* KRTexture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture.cpp */; };
E491019A13C99BDC0098455B /* KRModelManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRModelManager.cpp */; };
E491019B13C99BDC0098455B /* KRModelManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018313C99BDC0098455B /* KRModelManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
E491019C13C99BDC0098455B /* KRMaterialManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018413C99BDC0098455B /* KRMaterialManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018513C99BDC0098455B /* KRTextureManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
E491019E13C99BDC0098455B /* KRTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture.h */; settings = {ATTRIBUTES = (Private, ); }; };
E49101A013C99BF50098455B /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E491019F13C99BF50098455B /* OpenGLES.framework */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
E4AE8AB913CA2D77007E86AF /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.apple.compilers.proxy.script;
fileType = pattern.proxy;
isEditable = 1;
outputFiles = (
);
script = "";
};
/* End PBXBuildRule section */
/* Begin PBXFileReference section */
E414BAE11435557300A668C4 /* KRInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRInstance.h; path = Classes/KRInstance.h; sourceTree = "<group>"; };
E414BAE41435558800A668C4 /* KRInstance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRInstance.cpp; path = Classes/KRInstance.cpp; sourceTree = "<group>"; };
E414BAE6143557D200A668C4 /* KRScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRScene.h; path = Classes/KRScene.h; sourceTree = "<group>"; };
E414BAE81435585A00A668C4 /* KRScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRScene.cpp; path = Classes/KRScene.cpp; sourceTree = "<group>"; };
E414BAEA14355E5500A668C4 /* KRBoundingVolume.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRBoundingVolume.h; path = Classes/KRBoundingVolume.h; sourceTree = "<group>"; };
E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRBoundingVolume.cpp; path = Classes/KRBoundingVolume.cpp; sourceTree = "<group>"; };
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.vsh; path = Shaders/ShadowShader.vsh; sourceTree = "<group>"; };
E45772F213C9A13C0037BEEA /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = Shaders/ShadowShader.fsh; sourceTree = "<group>"; };
E45772F313C9A13C0037BEEA /* PostShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.fsh; path = Shaders/PostShader.fsh; sourceTree = "<group>"; };
E45772F413C9A13C0037BEEA /* ObjectShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ObjectShader.fsh; path = Shaders/ObjectShader.fsh; sourceTree = "<group>"; };
E45772F513C9A13C0037BEEA /* ObjectShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ObjectShader.vsh; path = Shaders/ObjectShader.vsh; sourceTree = "<group>"; };
E45772F613C9A13C0037BEEA /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = Shaders/PostShader.vsh; sourceTree = "<group>"; };
E47C25A113F4F65A00FF4370 /* KRShaderManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRShaderManager.h; path = Classes/KRShaderManager.h; sourceTree = "<group>"; };
E47C25A413F4F66F00FF4370 /* KRShader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRShader.h; path = Classes/KRShader.h; sourceTree = "<group>"; };
E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRShaderManager.cpp; path = Classes/KRShaderManager.cpp; sourceTree = "<group>"; };
E47C25A813F4F6DD00FF4370 /* KRShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRShader.cpp; path = Classes/KRShader.cpp; sourceTree = "<group>"; };
E48B3CBC14393DF5000C50E2 /* KRCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRCamera.h; path = Classes/KRCamera.h; sourceTree = "<group>"; };
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRCamera.cpp; path = Classes/KRCamera.cpp; sourceTree = "<group>"; };
E491016113C99B9E0098455B /* libKREngine.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libKREngine.a; sourceTree = BUILT_PRODUCTS_DIR; };
E491016413C99B9E0098455B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
E491016813C99B9E0098455B /* KREngine-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KREngine-Prefix.pch"; sourceTree = "<group>"; };
E491016F13C99BDC0098455B /* KREngine.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = KREngine.mm; path = Classes/KREngine.mm; sourceTree = "<group>"; };
E491017213C99BDC0098455B /* KREngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KREngine.h; path = Classes/KREngine.h; sourceTree = "<group>"; };
E491017613C99BDC0098455B /* KRMat4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRMat4.h; path = Classes/KRMat4.h; sourceTree = "<group>"; };
E491017713C99BDC0098455B /* KRMat4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRMat4.cpp; path = Classes/KRMat4.cpp; sourceTree = "<group>"; };
E491017913C99BDC0098455B /* KRModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRModel.cpp; path = Classes/KRModel.cpp; sourceTree = "<group>"; };
E491017A13C99BDC0098455B /* KRModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRModel.h; path = Classes/KRModel.h; sourceTree = "<group>"; };
E491017B13C99BDC0098455B /* KRMaterialManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRMaterialManager.cpp; path = Classes/KRMaterialManager.cpp; sourceTree = "<group>"; };
E491017C13C99BDC0098455B /* KRMaterial.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRMaterial.cpp; path = Classes/KRMaterial.cpp; sourceTree = "<group>"; };
E491017D13C99BDC0098455B /* KRMaterial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRMaterial.h; path = Classes/KRMaterial.h; sourceTree = "<group>"; };
E491017E13C99BDC0098455B /* KRVector3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRVector3.h; path = Classes/KRVector3.h; sourceTree = "<group>"; };
E491017F13C99BDC0098455B /* KRVector3.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRVector3.cpp; path = Classes/KRVector3.cpp; sourceTree = "<group>"; };
E491018013C99BDC0098455B /* KRTextureManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTextureManager.cpp; path = Classes/KRTextureManager.cpp; sourceTree = "<group>"; };
E491018113C99BDC0098455B /* KRTexture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTexture.cpp; path = Classes/KRTexture.cpp; sourceTree = "<group>"; };
E491018213C99BDC0098455B /* KRModelManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRModelManager.cpp; path = Classes/KRModelManager.cpp; sourceTree = "<group>"; };
E491018313C99BDC0098455B /* KRModelManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRModelManager.h; path = Classes/KRModelManager.h; sourceTree = "<group>"; };
E491018413C99BDC0098455B /* KRMaterialManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRMaterialManager.h; path = Classes/KRMaterialManager.h; sourceTree = "<group>"; };
E491018513C99BDC0098455B /* KRTextureManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTextureManager.h; path = Classes/KRTextureManager.h; sourceTree = "<group>"; };
E491018613C99BDC0098455B /* KRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTexture.h; path = Classes/KRTexture.h; sourceTree = "<group>"; };
E491019F13C99BF50098455B /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
E491015E13C99B9E0098455B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E49101A013C99BF50098455B /* OpenGLES.framework in Frameworks */,
E491016513C99B9E0098455B /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
E45772E313C99F160037BEEA /* Shaders */ = {
isa = PBXGroup;
children = (
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */,
E45772F213C9A13C0037BEEA /* ShadowShader.fsh */,
E45772F513C9A13C0037BEEA /* ObjectShader.vsh */,
E45772F313C9A13C0037BEEA /* PostShader.fsh */,
E45772F413C9A13C0037BEEA /* ObjectShader.fsh */,
E45772F613C9A13C0037BEEA /* PostShader.vsh */,
);
name = Shaders;
sourceTree = "<group>";
};
E491015613C99B9D0098455B = {
isa = PBXGroup;
children = (
E491016613C99B9E0098455B /* KREngine */,
E491016313C99B9E0098455B /* Frameworks */,
E491016213C99B9E0098455B /* Products */,
);
sourceTree = "<group>";
};
E491016213C99B9E0098455B /* Products */ = {
isa = PBXGroup;
children = (
E491016113C99B9E0098455B /* libKREngine.a */,
);
name = Products;
sourceTree = "<group>";
};
E491016313C99B9E0098455B /* Frameworks */ = {
isa = PBXGroup;
children = (
E491019F13C99BF50098455B /* OpenGLES.framework */,
E491016413C99B9E0098455B /* Foundation.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
E491016613C99B9E0098455B /* KREngine */ = {
isa = PBXGroup;
children = (
E45772E313C99F160037BEEA /* Shaders */,
E491016E13C99BAE0098455B /* Classes */,
E491016713C99B9E0098455B /* Supporting Files */,
);
path = KREngine;
sourceTree = "<group>";
};
E491016713C99B9E0098455B /* Supporting Files */ = {
isa = PBXGroup;
children = (
E491016813C99B9E0098455B /* KREngine-Prefix.pch */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
E491016E13C99BAE0098455B /* Classes */ = {
isa = PBXGroup;
children = (
E491016F13C99BDC0098455B /* KREngine.mm */,
E491017213C99BDC0098455B /* KREngine.h */,
E491017613C99BDC0098455B /* KRMat4.h */,
E491017713C99BDC0098455B /* KRMat4.cpp */,
E491017913C99BDC0098455B /* KRModel.cpp */,
E491017A13C99BDC0098455B /* KRModel.h */,
E491017B13C99BDC0098455B /* KRMaterialManager.cpp */,
E491017C13C99BDC0098455B /* KRMaterial.cpp */,
E491017D13C99BDC0098455B /* KRMaterial.h */,
E491017E13C99BDC0098455B /* KRVector3.h */,
E491017F13C99BDC0098455B /* KRVector3.cpp */,
E491018013C99BDC0098455B /* KRTextureManager.cpp */,
E491018113C99BDC0098455B /* KRTexture.cpp */,
E491018213C99BDC0098455B /* KRModelManager.cpp */,
E491018313C99BDC0098455B /* KRModelManager.h */,
E491018413C99BDC0098455B /* KRMaterialManager.h */,
E491018513C99BDC0098455B /* KRTextureManager.h */,
E491018613C99BDC0098455B /* KRTexture.h */,
E47C25A113F4F65A00FF4370 /* KRShaderManager.h */,
E47C25A413F4F66F00FF4370 /* KRShader.h */,
E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */,
E47C25A813F4F6DD00FF4370 /* KRShader.cpp */,
E414BAE11435557300A668C4 /* KRInstance.h */,
E414BAE41435558800A668C4 /* KRInstance.cpp */,
E414BAE6143557D200A668C4 /* KRScene.h */,
E414BAE81435585A00A668C4 /* KRScene.cpp */,
E414BAEA14355E5500A668C4 /* KRBoundingVolume.h */,
E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */,
E48B3CBC14393DF5000C50E2 /* KRCamera.h */,
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */,
);
name = Classes;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
E491015F13C99B9E0098455B /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
E491018A13C99BDC0098455B /* KREngine.h in Headers */,
E491018E13C99BDC0098455B /* KRMat4.h in Headers */,
E491019B13C99BDC0098455B /* KRModelManager.h in Headers */,
E491019213C99BDC0098455B /* KRModel.h in Headers */,
E491019613C99BDC0098455B /* KRVector3.h in Headers */,
E491019513C99BDC0098455B /* KRMaterial.h in Headers */,
E491019C13C99BDC0098455B /* KRMaterialManager.h in Headers */,
E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */,
E491019E13C99BDC0098455B /* KRTexture.h in Headers */,
E47C25A213F4F65A00FF4370 /* KRShaderManager.h in Headers */,
E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */,
E414BAE21435557300A668C4 /* KRInstance.h in Headers */,
E414BAE7143557D200A668C4 /* KRScene.h in Headers */,
E414BAEB14355E5500A668C4 /* KRBoundingVolume.h in Headers */,
E48B3CBD14393DF5000C50E2 /* KRCamera.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
E491016013C99B9E0098455B /* KREngine */ = {
isa = PBXNativeTarget;
buildConfigurationList = E491016B13C99B9E0098455B /* Build configuration list for PBXNativeTarget "KREngine" */;
buildPhases = (
E491015D13C99B9E0098455B /* Sources */,
E491015E13C99B9E0098455B /* Frameworks */,
E491015F13C99B9E0098455B /* Headers */,
);
buildRules = (
E4AE8AB913CA2D77007E86AF /* PBXBuildRule */,
);
dependencies = (
);
name = KREngine;
productName = KREngine;
productReference = E491016113C99B9E0098455B /* libKREngine.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
E491015813C99B9D0098455B /* Project object */ = {
isa = PBXProject;
attributes = {
ORGANIZATIONNAME = "Kearwood Software";
};
buildConfigurationList = E491015B13C99B9D0098455B /* Build configuration list for PBXProject "KREngine" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = E491015613C99B9D0098455B;
productRefGroup = E491016213C99B9E0098455B /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
E491016013C99B9E0098455B /* KREngine */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
E491015D13C99B9E0098455B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E491018713C99BDC0098455B /* KREngine.mm in Sources */,
E491018F13C99BDC0098455B /* KRMat4.cpp in Sources */,
E491019113C99BDC0098455B /* KRModel.cpp in Sources */,
E491019313C99BDC0098455B /* KRMaterialManager.cpp in Sources */,
E491019413C99BDC0098455B /* KRMaterial.cpp in Sources */,
E491019713C99BDC0098455B /* KRVector3.cpp in Sources */,
E491019813C99BDC0098455B /* KRTextureManager.cpp in Sources */,
E491019913C99BDC0098455B /* KRTexture.cpp in Sources */,
E491019A13C99BDC0098455B /* KRModelManager.cpp in Sources */,
E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */,
E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */,
E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */,
E414BAE91435585A00A668C4 /* KRScene.cpp in Sources */,
E414BAED14355EFF00A668C4 /* KRBoundingVolume.cpp in Sources */,
E48B3CC014393E30000C50E2 /* KRCamera.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
E491016913C99B9E0098455B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvmgcc42;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
SDKROOT = iphoneos;
};
name = Debug;
};
E491016A13C99B9E0098455B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvmgcc42;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
SDKROOT = iphoneos;
};
name = Release;
};
E491016C13C99B9E0098455B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
DSTROOT = /tmp/KREngine.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "KREngine/KREngine-Prefix.pch";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
E491016D13C99B9E0098455B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
DSTROOT = /tmp/KREngine.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "KREngine/KREngine-Prefix.pch";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
E491015B13C99B9D0098455B /* Build configuration list for PBXProject "KREngine" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E491016913C99B9E0098455B /* Debug */,
E491016A13C99B9E0098455B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E491016B13C99B9E0098455B /* Build configuration list for PBXNativeTarget "KREngine" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E491016C13C99B9E0098455B /* Debug */,
E491016D13C99B9E0098455B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = E491015813C99B9D0098455B /* Project object */;
}

View File

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

View File

@@ -0,0 +1,264 @@
//
// KRBoundingVolume.cpp
// KREngine
//
// Created by Kearwood Gilbert on 11-09-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#include <iostream>
#import "KRBoundingVolume.h"
KRBoundingVolume::KRBoundingVolume(const Vector3 *pVertices) {
for(int iVertex=0; iVertex < 8; iVertex++) {
m_vertices[iVertex] = pVertices[iVertex];
}
}
KRBoundingVolume::KRBoundingVolume(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 modelMatrix) {
m_vertices[0] = Vector3(corner1.x, corner1.y, corner1.z);
m_vertices[1] = Vector3(corner2.x, corner1.y, corner1.z);
m_vertices[2] = Vector3(corner2.x, corner2.y, corner1.z);
m_vertices[3] = Vector3(corner1.x, corner2.y, corner1.z);
m_vertices[4] = Vector3(corner1.x, corner1.y, corner2.z);
m_vertices[5] = Vector3(corner2.x, corner1.y, corner2.z);
m_vertices[6] = Vector3(corner2.x, corner2.y, corner2.z);
m_vertices[7] = Vector3(corner1.x, corner2.y, corner2.z);
for(int iVertex=0; iVertex < 8; iVertex++) {
m_vertices[iVertex] = modelMatrix.dot(m_vertices[iVertex]);
}
}
KRBoundingVolume::KRBoundingVolume(const KRMat4 &matView, GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz) {
// Construct a bounding volume representing the volume of the view frustrum
KRMat4 invView = matView;
invView.invert();
GLfloat r = tan(fov / 2.0);
m_vertices[0] = Vector3(-1.0 * r * nearz * aspect, -1.0 * r * nearz, -nearz);
m_vertices[1] = Vector3(1.0 * r * nearz * aspect, -1.0 * r * nearz, -nearz);
m_vertices[2] = Vector3(1.0 * r * nearz * aspect, 1.0 * r * nearz, -nearz);
m_vertices[3] = Vector3(-1.0 * r * nearz * aspect, 1.0 * r * nearz, -nearz);
m_vertices[4] = Vector3(-1.0 * r * farz * aspect, -1.0 * r * farz, -farz);
m_vertices[5] = Vector3(1.0 * r * farz * aspect, -1.0 * r * farz, -farz);
m_vertices[6] = Vector3(1.0 * r * farz * aspect, 1.0 * r * farz, -farz);
m_vertices[7] = Vector3(-1.0 * r * farz * aspect, 1.0 * r * farz, -farz);
for(int iVertex=0; iVertex < 8; iVertex++) {
m_vertices[iVertex] = invView.dot(m_vertices[iVertex]);
}
}
KRBoundingVolume::~KRBoundingVolume() {
}
KRBoundingVolume::KRBoundingVolume(const KRBoundingVolume& p) {
for(int iVertex=0; iVertex < 8; iVertex++) {
m_vertices[iVertex] = p.m_vertices[iVertex];
}
}
KRBoundingVolume& KRBoundingVolume::operator = ( const KRBoundingVolume& p ) {
for(int iVertex=0; iVertex < 8; iVertex++) {
m_vertices[iVertex] = p.m_vertices[iVertex];
}
return *this;
}
KRBoundingVolume KRBoundingVolume::get_union(const KRBoundingVolume &p) const {
// Simple, non-aligned bounding box calculated that contains both volumes.
Vector3 minPoint = m_vertices[0], maxPoint = m_vertices[0];
for(int iVertex=1; iVertex < 8; iVertex++) {
if(m_vertices[iVertex].x < minPoint.x) {
minPoint.x = m_vertices[iVertex].x;
}
if(m_vertices[iVertex].y < minPoint.y) {
minPoint.y = m_vertices[iVertex].y;
}
if(m_vertices[iVertex].z < minPoint.z) {
minPoint.z = m_vertices[iVertex].z;
}
if(m_vertices[iVertex].x > maxPoint.x) {
maxPoint.x = m_vertices[iVertex].x;
}
if(m_vertices[iVertex].y > maxPoint.y) {
maxPoint.y = m_vertices[iVertex].y;
}
if(m_vertices[iVertex].z > maxPoint.z) {
maxPoint.z = m_vertices[iVertex].z;
}
}
for(int iVertex=0; iVertex < 8; iVertex++) {
if(p.m_vertices[iVertex].x < minPoint.x) {
minPoint.x = p.m_vertices[iVertex].x;
}
if(p.m_vertices[iVertex].y < minPoint.y) {
minPoint.y =p.m_vertices[iVertex].y;
}
if(p.m_vertices[iVertex].z < minPoint.z) {
minPoint.z = p.m_vertices[iVertex].z;
}
if(p.m_vertices[iVertex].x > maxPoint.x) {
maxPoint.x = p.m_vertices[iVertex].x;
}
if(p.m_vertices[iVertex].y > maxPoint.y) {
maxPoint.y = p.m_vertices[iVertex].y;
}
if(p.m_vertices[iVertex].z > maxPoint.z) {
maxPoint.z = p.m_vertices[iVertex].z;
}
}
return KRBoundingVolume(minPoint, maxPoint, KRMat4());
}
bool KRBoundingVolume::test_intersect(const KRBoundingVolume &p) const {
// Simple, non-aligned bounding box intersection test
Vector3 minPoint = m_vertices[0], maxPoint = m_vertices[0], minPoint2 = p.m_vertices[0], maxPoint2 = p.m_vertices[0];
for(int iVertex=1; iVertex < 8; iVertex++) {
if(m_vertices[iVertex].x < minPoint.x) {
minPoint.x = m_vertices[iVertex].x;
}
if(m_vertices[iVertex].y < minPoint.y) {
minPoint.y = m_vertices[iVertex].y;
}
if(m_vertices[iVertex].z < minPoint.z) {
minPoint.z = m_vertices[iVertex].z;
}
if(m_vertices[iVertex].x > maxPoint.x) {
maxPoint.x = m_vertices[iVertex].x;
}
if(m_vertices[iVertex].y > maxPoint.y) {
maxPoint.y = m_vertices[iVertex].y;
}
if(m_vertices[iVertex].z > maxPoint.z) {
maxPoint.z = m_vertices[iVertex].z;
}
}
for(int iVertex=1; iVertex < 8; iVertex++) {
if(p.m_vertices[iVertex].x < minPoint2.x) {
minPoint2.x = p.m_vertices[iVertex].x;
}
if(p.m_vertices[iVertex].y < minPoint2.y) {
minPoint2.y =p.m_vertices[iVertex].y;
}
if(p.m_vertices[iVertex].z < minPoint2.z) {
minPoint2.z = p.m_vertices[iVertex].z;
}
if(p.m_vertices[iVertex].x > maxPoint2.x) {
maxPoint2.x = p.m_vertices[iVertex].x;
}
if(p.m_vertices[iVertex].y > maxPoint2.y) {
maxPoint2.y = p.m_vertices[iVertex].y;
}
if(p.m_vertices[iVertex].z > maxPoint2.z) {
maxPoint2.z = p.m_vertices[iVertex].z;
}
}
bool bIntersect = maxPoint.x >= minPoint2.x && maxPoint.y >= minPoint2.y && maxPoint.z >= minPoint2.z
&& minPoint.x <= maxPoint2.x && minPoint.y <= maxPoint2.y && minPoint.z <= maxPoint2.z;
return bIntersect;
}
KRMat4 KRBoundingVolume::calcShadowProj(KRScene *pScene, GLfloat sun_yaw, GLfloat sun_pitch) const {
KRBoundingVolume sceneVolume = pScene->getExtents();
KRMat4 shadowvp;
shadowvp.rotate(sun_pitch, X_AXIS);
shadowvp.rotate(sun_yaw, Y_AXIS);
shadowvp.invert();
shadowvp.scale(1.0, 1.0, -1.0);
Vector3 minPointFrustrum = shadowvp.dot(m_vertices[0]), maxPointFrustrum = minPointFrustrum;
for(int iVertex=1; iVertex < 8; iVertex++) {
Vector3 v = shadowvp.dot(m_vertices[iVertex]);
if(v.x < minPointFrustrum.x) {
minPointFrustrum.x = v.x;
}
if(v.y < minPointFrustrum.y) {
minPointFrustrum.y = v.y;
}
if(v.z < minPointFrustrum.z) {
minPointFrustrum.z = v.z;
}
if(v.x > maxPointFrustrum.x) {
maxPointFrustrum.x = v.x;
}
if(v.y > maxPointFrustrum.y) {
maxPointFrustrum.y = v.y;
}
if(v.z > maxPointFrustrum.z) {
maxPointFrustrum.z = v.z;
}
}
Vector3 minPointScene = shadowvp.dot(sceneVolume.m_vertices[0]), maxPointScene = minPointScene;
for(int iVertex=1; iVertex < 8; iVertex++) {
Vector3 v = shadowvp.dot(sceneVolume.m_vertices[iVertex]);
if(v.x < minPointScene.x) {
minPointScene.x = v.x;
}
if(v.y < minPointScene.y) {
minPointScene.y = v.y;
}
if(v.z < minPointScene.z) {
minPointScene.z = v.z;
}
if(v.x > maxPointScene.x) {
maxPointScene.x = v.x;
}
if(v.y > maxPointScene.y) {
maxPointScene.y = v.y;
}
if(v.z > maxPointScene.z) {
maxPointScene.z = v.z;
}
}
// Include potential shadow casters outside of view frustrum
minPointFrustrum.z = minPointScene.z;
if(maxPointScene.z < maxPointFrustrum.z) {
maxPointFrustrum.z = maxPointScene.z;
}
/*
// Include potential shadow casters outside of view frustrum
GLfloat maxFrustrumDepth = maxPointFrustrum.z;
for(int i=0; i<8; i++) {
Vector3 v = shadowvp.dot(sceneVolume.m_vertices[i]);
if(i == 0) {
minPointFrustrum.z = v.z;
maxPointFrustrum.z = v.z;
} else {
if(v.z < minPointFrustrum.z) {
minPointFrustrum.z = v.z;
}
if(v.z > maxPointFrustrum.z) {
maxPointFrustrum.z = v.z;
}
}
}
if(maxPointFrustrum.z > maxFrustrumDepth) {
maxPointFrustrum.z = maxFrustrumDepth;
}
*/
shadowvp.translate(-minPointFrustrum.x, -minPointFrustrum.y, -minPointFrustrum.z);
shadowvp.scale(2.0/(maxPointFrustrum.x - minPointFrustrum.x), 2.0/(maxPointFrustrum.y - minPointFrustrum.y), 1.0/(maxPointFrustrum.z - minPointFrustrum.z));
shadowvp.translate(-1.0, -1.0, 0.0);
return shadowvp;
}

View File

@@ -0,0 +1,38 @@
//
// KRBoundingVolume.h
// KREngine
//
// Created by Kearwood Gilbert on 11-09-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#ifndef KRBOUNDINGVOLUME_H
#define KRBOUNDINGVOLUME_H
#import "KRVector3.h"
#import "KRMat4.h"
#import "KRScene.h"
class KRScene;
class KRBoundingVolume {
public:
KRBoundingVolume(const Vector3 *pVertices);
KRBoundingVolume(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 modelMatrix);
KRBoundingVolume(const KRMat4 &matView, GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz);
~KRBoundingVolume();
KRBoundingVolume(const KRBoundingVolume& p);
KRBoundingVolume& operator = ( const KRBoundingVolume& p );
KRBoundingVolume get_union(const KRBoundingVolume &p) const;
bool test_intersect(const KRBoundingVolume &p) const;
KRMat4 calcShadowProj(KRScene *pScene, GLfloat sun_yaw, GLfloat sun_pitch) const;
private:
Vector3 m_vertices[8];
};
#endif

View File

@@ -0,0 +1,65 @@
//
// KRSettings.cpp
// KREngine
//
// Created by Kearwood Gilbert on 11-10-02.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#include <iostream>
#import "KRCamera.h"
KRCamera::KRCamera() {
double const PI = 3.141592653589793f;
bShowShadowBuffer = false;
bEnablePerPixel = true;
bEnableDiffuseMap = true;
bEnableNormalMap = true;
bEnableSpecMap = true;
bDebugPSSM = false;
bEnableAmbient = true;
bEnableDiffuse = true;
bEnableSpecular = true;
bDebugSuperShiny = false;
dAmbientR = 0.25f;
dAmbientG = 0.25f;
dAmbientB = 0.35f;
dSunR = 1.0f;
dSunG = 1.0f;
dSunB = 0.70f;
perspective_fov = PI / 8.0;
perspective_aspect = 1.3333;
perspective_nearz = 0.25f;
perspective_farz = 100.0f;
dof_quality = 0;
dof_depth = 0.05f;
dof_falloff = 0.05f;
bEnableFlash = false;
flash_intensity = 1.0f;
flash_depth = 0.7f;
flash_falloff = 0.5f;
bEnableVignette = false;
vignette_radius = 0.4f;
vignette_falloff = 1.0f;
}
KRCamera::~KRCamera() {
}
KRMat4 KRCamera::getProjectionMatrix() {
KRMat4 projectionMatrix;
projectionMatrix.perspective(perspective_fov, perspective_aspect, perspective_nearz, perspective_farz);
projectionMatrix.rotate(-90 * 0.0174532925199, Z_AXIS);
return projectionMatrix;
}

View File

@@ -0,0 +1,55 @@
//
// KRSettings.h
// KREngine
//
// Created by Kearwood Gilbert on 11-10-02.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#ifndef KRCAMERA_H
#define KRCAMERA_H
#import "KRMat4.h"
class KRCamera {
public:
KRCamera();
~KRCamera();
KRMat4 getProjectionMatrix();
bool bEnablePerPixel;
bool bEnableDiffuseMap;
bool bEnableNormalMap;
bool bEnableSpecMap;
bool bDebugPSSM;
bool bDebugSuperShiny;
bool bShowShadowBuffer;
bool bEnableAmbient;
bool bEnableDiffuse;
bool bEnableSpecular;
double dSunR;
double dSunG;
double dSunB;
double dAmbientR;
double dAmbientG;
double dAmbientB;
double perspective_fov;
double perspective_nearz;
double perspective_farz;
double perspective_aspect;
int dof_quality;
double dof_depth;
double dof_falloff;
bool bEnableFlash;
double flash_intensity;
double flash_depth;
double flash_falloff;
bool bEnableVignette;
double vignette_radius;
double vignette_falloff;
};
#endif

View File

@@ -0,0 +1,107 @@
//
// 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 "KRMat4.h"
#import "KRVector3.h"
#import "KRModel.h"
#import "KRScene.h"
#import "KRTextureManager.h"
#import "KRMaterialManager.h"
#import "KRShaderManager.h"
#import "KRModelManager.h"
#import "KRCamera.h"
typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_FLOAT, KRENGINE_PARAMETER_BOOL} KREngineParameterType;
#define KRENGINE_MAX_SHADOW_BUFFERS 3
#define KRENGINE_SHADOW_MAP_WIDTH 2048
#define KRENGINE_SHADOW_MAP_HEIGHT 2048
@interface KREngine : NSObject
{
@private
GLint backingWidth, backingHeight;
GLuint compositeFramebuffer, compositeDepthTexture, compositeColorTexture;
int m_cShadowBuffers;
GLuint shadowFramebuffer[KRENGINE_MAX_SHADOW_BUFFERS], shadowDepthTexture[KRENGINE_MAX_SHADOW_BUFFERS];
bool shadowValid[KRENGINE_MAX_SHADOW_BUFFERS];
KRMat4 shadowmvpmatrix[KRENGINE_MAX_SHADOW_BUFFERS]; /* MVP Matrix for view from light source */
// uniform index
enum {
KRENGINE_UNIFORM_MATERIAL_AMBIENT,
KRENGINE_UNIFORM_MATERIAL_DIFFUSE,
KRENGINE_UNIFORM_MATERIAL_SPECULAR,
KRENGINE_UNIFORM_MVP,
KRENGINE_UNIFORM_SHADOWMVP1,
KRENGINE_UNIFORM_SHADOWMVP2,
KRENGINE_UNIFORM_SHADOWMVP3,
KRENGINE_UNIFORM_LIGHTDIRECTION,
KRENGINE_UNIFORM_CAMERAPOS,
KRENGINE_NUM_UNIFORMS
};
GLint m_shadowUniforms[KRENGINE_NUM_UNIFORMS];
GLuint m_postShaderProgram;
GLuint m_shadowShaderProgram;
KRTextureManager *m_pTextureManager;
KRMaterialManager *m_pMaterialManager;
KRShaderManager *m_pShaderManager;
KRModelManager *m_pModelManager;
int m_iFrame;
double sun_pitch, sun_yaw;
KRCamera m_camera;
NSString *debug_text;
}
- (id)initForWidth: (GLuint)width Height: (GLuint)height;
- (BOOL)loadVertexShader:(NSString *)vertexShaderName fragmentShader:(NSString *)fragmentShaderName forProgram:(GLuint *)programPointer withOptions:(NSString *)options;
- (BOOL)loadResource:(NSString *)path;
- (void)renderShadowBufferNumber: (int)iShadow ForScene: (KRScene *)pScene;
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix LightDirection: (Vector3)lightDirection CameraPosition: (Vector3)cameraPosition;
- (KRModelManager *)getModelManager;
- (void)invalidateShadowBuffers;
- (void)allocateShadowBuffers;
- (void)invalidatePostShader;
- (void)bindPostShader;
// Parameter enumeration interface
-(int)getParameterCount;
-(NSString *)getParameterNameWithIndex: (int)i;
-(NSString *)getParameterLabelWithIndex: (int)i;
-(KREngineParameterType)getParameterTypeWithIndex: (int)i;
-(double)getParameterMinWithIndex: (int)i;
-(double)getParameterMaxWithIndex: (int)i;
-(double)getParameterValueWithIndex: (int)i;
-(void)setParameterValueWithIndex: (int)i Value: (double)v;
-(void)setParameterValueWithName: (NSString *)name Value: (double)v;
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix;
- (void)renderScene: (KRScene *)pScene WithPosition: (Vector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll;
- (void)setNearZ: (double)dNearZ;
- (void)setFarZ: (double)dFarZ;
- (void)setAspect: (double)dAspect;
- (void)setDebugText: (NSString *)text;
@end

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
//
// KRInstance.cpp
// KREngine
//
// Created by Kearwood Gilbert on 11-09-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#include <iostream>
#import "KRInstance.h"
KRInstance::KRInstance(KRModel *pModel, const KRMat4 modelMatrix) {
m_pModel = pModel;
m_modelMatrix = modelMatrix;
}
KRInstance::~KRInstance() {
}
KRMat4 &KRInstance::getModelMatrix() {
return m_modelMatrix;
}
KRModel *KRInstance::getModel() {
return m_pModel;
}
void KRInstance::render(KRCamera *pCamera, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &viewMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
KRMat4 projectionMatrix;
if(!bRenderShadowMap) {
projectionMatrix = pCamera->getProjectionMatrix();
}
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
// Transform location of camera to object space for calculation of specular halfVec
KRMat4 inverseModelMatrix = m_modelMatrix;
inverseModelMatrix.invert();
Vector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
Vector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
m_pModel->render(pCamera, pMaterialManager, bRenderShadowMap, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
}
KRBoundingVolume KRInstance::getExtents() {
return KRBoundingVolume(Vector3(m_pModel->getMinX(), m_pModel->getMinY(), m_pModel->getMinZ()), Vector3(m_pModel->getMaxX(), m_pModel->getMaxY(), m_pModel->getMaxZ()), m_modelMatrix);
}

View File

@@ -0,0 +1,42 @@
//
// KRInstance.h
// KREngine
//
// Created by Kearwood Gilbert on 11-09-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#import "KRModel.h"
#import "KRMat4.h"
#import "KRVector3.h"
#import "KRBoundingVolume.h"
#import "KRInstance.h"
#import "KRCamera.h"
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#ifndef KRINSTANCE_H
#define KRINSTANCE_H
class KRBoundingVolume;
class KRInstance {
public:
KRInstance(KRModel *pModel, const KRMat4 modelMatrix);
~KRInstance();
void render(KRCamera *pCamera, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &viewMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
KRBoundingVolume getExtents();
KRMat4 &getModelMatrix();
KRModel *getModel();
private:
KRModel *m_pModel;
KRMat4 m_modelMatrix;
};
#endif

View File

@@ -0,0 +1,264 @@
//
// 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 *pMat) {
memcpy(m_mat, pMat, 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, const KRMat4 &m) {
KRMat4 result = *this;
result *= m;
return result;
}
*/
KRMat4 KRMat4::operator*(const KRMat4 &m) {
KRMat4 ret = *this;
ret *= m;
return ret;
}
/* 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 / 2.0f) * nearz;
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);
}
void KRMat4::bias() {
// Initialize with a bias matrix
static const GLfloat BIAS_MATRIX[] = {
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0
};
memcpy(m_mat, BIAS_MATRIX, sizeof(GLfloat) * 16);
}
/* Generate an orthographic view matrix */
void KRMat4::ortho(GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, GLfloat nearz, GLfloat farz) {
memset(m_mat, 0, sizeof(GLfloat) * 16);
/*
m_mat[0] = 2.0f / (right - left);
m_mat[3] = -(right + left) / (right - left);
m_mat[5] = 2.0f / (top - bottom);
m_mat[7] = -(top + bottom) / (top - bottom);
m_mat[10] = -2.0f / (farz - nearz);
m_mat[11] = -(farz + nearz) / (farz - nearz);
m_mat[15] = 1.0f;
*/
m_mat[0] = 2.0f / (right - left);
m_mat[5] = 2.0f / (bottom - top);
m_mat[10] = -1.0f / (farz - nearz);
m_mat[11] = -nearz / (farz - nearz);
m_mat[15] = 1.0f;
}
bool KRMat4::invert() {
/*
GLfloat inverseTranslation[16];
GLfloat inverseRotation[16];
inverseTranslation[0] = 1 ; inverseTranslation[4] = 0 ; inverseTranslation[8] = 0 ; inverseTranslation[12] = -m_mat[12] ;
inverseTranslation[1] = 0 ; inverseTranslation[5] = 1 ; inverseTranslation[9] = 0 ; inverseTranslation[13] = -m_mat[13] ;
inverseTranslation[2] = 0 ; inverseTranslation[6] = 0 ; inverseTranslation[10] = 1 ; inverseTranslation[14] = -m_mat[14] ;
inverseTranslation[3] = 0 ; inverseTranslation[7] = 0 ; inverseTranslation[11] = 0 ; inverseTranslation[15] = 1 ;
inverseRotation[0] = m_mat[0] ; inverseRotation[4] = m_mat[1] ; inverseRotation[8] = m_mat[2] ; inverseRotation[12] = 0 ;
inverseRotation[1] = m_mat[4] ; inverseRotation[5] = m_mat[5] ; inverseRotation[9] = m_mat[6] ; inverseRotation[13] = 0 ;
inverseRotation[2] = m_mat[8] ; inverseRotation[6] = m_mat[9] ; inverseRotation[10] = m_mat[10] ; inverseRotation[14] = 0 ;
inverseRotation[3] = 0 ; inverseRotation[7] = 0 ; inverseRotation[11] = 0 ; inverseRotation[15] = 1 ;
KRMat4 inverseRotMat(inverseRotation);
KRMat4 inverseTransMat(inverseTranslation);
KRMat4 m = inverseRotMat * inverseTransMat;
memcpy(m_mat, m.m_mat, sizeof(GLfloat) * 16);
*/
// Based on gluInvertMatrix implementation
double inv[16], det;
int i;
inv[0] = m_mat[5]*m_mat[10]*m_mat[15] - m_mat[5]*m_mat[11]*m_mat[14] - m_mat[9]*m_mat[6]*m_mat[15]
+ m_mat[9]*m_mat[7]*m_mat[14] + m_mat[13]*m_mat[6]*m_mat[11] - m_mat[13]*m_mat[7]*m_mat[10];
inv[4] = -m_mat[4]*m_mat[10]*m_mat[15] + m_mat[4]*m_mat[11]*m_mat[14] + m_mat[8]*m_mat[6]*m_mat[15]
- m_mat[8]*m_mat[7]*m_mat[14] - m_mat[12]*m_mat[6]*m_mat[11] + m_mat[12]*m_mat[7]*m_mat[10];
inv[8] = m_mat[4]*m_mat[9]*m_mat[15] - m_mat[4]*m_mat[11]*m_mat[13] - m_mat[8]*m_mat[5]*m_mat[15]
+ m_mat[8]*m_mat[7]*m_mat[13] + m_mat[12]*m_mat[5]*m_mat[11] - m_mat[12]*m_mat[7]*m_mat[9];
inv[12] = -m_mat[4]*m_mat[9]*m_mat[14] + m_mat[4]*m_mat[10]*m_mat[13] + m_mat[8]*m_mat[5]*m_mat[14]
- m_mat[8]*m_mat[6]*m_mat[13] - m_mat[12]*m_mat[5]*m_mat[10] + m_mat[12]*m_mat[6]*m_mat[9];
inv[1] = -m_mat[1]*m_mat[10]*m_mat[15] + m_mat[1]*m_mat[11]*m_mat[14] + m_mat[9]*m_mat[2]*m_mat[15]
- m_mat[9]*m_mat[3]*m_mat[14] - m_mat[13]*m_mat[2]*m_mat[11] + m_mat[13]*m_mat[3]*m_mat[10];
inv[5] = m_mat[0]*m_mat[10]*m_mat[15] - m_mat[0]*m_mat[11]*m_mat[14] - m_mat[8]*m_mat[2]*m_mat[15]
+ m_mat[8]*m_mat[3]*m_mat[14] + m_mat[12]*m_mat[2]*m_mat[11] - m_mat[12]*m_mat[3]*m_mat[10];
inv[9] = -m_mat[0]*m_mat[9]*m_mat[15] + m_mat[0]*m_mat[11]*m_mat[13] + m_mat[8]*m_mat[1]*m_mat[15]
- m_mat[8]*m_mat[3]*m_mat[13] - m_mat[12]*m_mat[1]*m_mat[11] + m_mat[12]*m_mat[3]*m_mat[9];
inv[13] = m_mat[0]*m_mat[9]*m_mat[14] - m_mat[0]*m_mat[10]*m_mat[13] - m_mat[8]*m_mat[1]*m_mat[14]
+ m_mat[8]*m_mat[2]*m_mat[13] + m_mat[12]*m_mat[1]*m_mat[10] - m_mat[12]*m_mat[2]*m_mat[9];
inv[2] = m_mat[1]*m_mat[6]*m_mat[15] - m_mat[1]*m_mat[7]*m_mat[14] - m_mat[5]*m_mat[2]*m_mat[15]
+ m_mat[5]*m_mat[3]*m_mat[14] + m_mat[13]*m_mat[2]*m_mat[7] - m_mat[13]*m_mat[3]*m_mat[6];
inv[6] = -m_mat[0]*m_mat[6]*m_mat[15] + m_mat[0]*m_mat[7]*m_mat[14] + m_mat[4]*m_mat[2]*m_mat[15]
- m_mat[4]*m_mat[3]*m_mat[14] - m_mat[12]*m_mat[2]*m_mat[7] + m_mat[12]*m_mat[3]*m_mat[6];
inv[10] = m_mat[0]*m_mat[5]*m_mat[15] - m_mat[0]*m_mat[7]*m_mat[13] - m_mat[4]*m_mat[1]*m_mat[15]
+ m_mat[4]*m_mat[3]*m_mat[13] + m_mat[12]*m_mat[1]*m_mat[7] - m_mat[12]*m_mat[3]*m_mat[5];
inv[14] = -m_mat[0]*m_mat[5]*m_mat[14] + m_mat[0]*m_mat[6]*m_mat[13] + m_mat[4]*m_mat[1]*m_mat[14]
- m_mat[4]*m_mat[2]*m_mat[13] - m_mat[12]*m_mat[1]*m_mat[6] + m_mat[12]*m_mat[2]*m_mat[5];
inv[3] = -m_mat[1]*m_mat[6]*m_mat[11] + m_mat[1]*m_mat[7]*m_mat[10] + m_mat[5]*m_mat[2]*m_mat[11]
- m_mat[5]*m_mat[3]*m_mat[10] - m_mat[9]*m_mat[2]*m_mat[7] + m_mat[9]*m_mat[3]*m_mat[6];
inv[7] = m_mat[0]*m_mat[6]*m_mat[11] - m_mat[0]*m_mat[7]*m_mat[10] - m_mat[4]*m_mat[2]*m_mat[11]
+ m_mat[4]*m_mat[3]*m_mat[10] + m_mat[8]*m_mat[2]*m_mat[7] - m_mat[8]*m_mat[3]*m_mat[6];
inv[11] = -m_mat[0]*m_mat[5]*m_mat[11] + m_mat[0]*m_mat[7]*m_mat[9] + m_mat[4]*m_mat[1]*m_mat[11]
- m_mat[4]*m_mat[3]*m_mat[9] - m_mat[8]*m_mat[1]*m_mat[7] + m_mat[8]*m_mat[3]*m_mat[5];
inv[15] = m_mat[0]*m_mat[5]*m_mat[10] - m_mat[0]*m_mat[6]*m_mat[9] - m_mat[4]*m_mat[1]*m_mat[10]
+ m_mat[4]*m_mat[2]*m_mat[9] + m_mat[8]*m_mat[1]*m_mat[6] - m_mat[8]*m_mat[2]*m_mat[5];
det = m_mat[0]*inv[0] + m_mat[1]*inv[4] + m_mat[2]*inv[8] + m_mat[3]*inv[12];
if (det == 0) {
return false;
}
det = 1.0 / det;
for (i = 0; i < 16; i++) {
m_mat[i] = inv[i] * det;
}
return true;
}
Vector3 KRMat4::dot(const Vector3 &v) const {
return Vector3(
v.x * (float)m_mat[0*4 + 0] + v.y * (float)m_mat[1*4 + 0] + v.z * (float)m_mat[2*4 + 0] + (float)m_mat[3*4 + 0],
v.x * (float)m_mat[0*4 + 1] + v.y * (float)m_mat[1*4 + 1] + v.z * (float)m_mat[2*4 + 1] + (float)m_mat[3*4 + 1],
v.x * (float)m_mat[0*4 + 2] + v.y * (float)m_mat[1*4 + 2] + v.z * (float)m_mat[2*4 + 2] + (float)m_mat[3*4 + 2]
);
}

View File

@@ -0,0 +1,75 @@
//
// 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>
#import "KRVector3.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();
KRMat4(GLfloat *pMat);
// 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);
KRMat4 operator*(const KRMat4 &m);
GLfloat *getPointer();
void perspective(GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz);
void ortho(GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, 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);
void bias();
bool invert();
Vector3 dot(const Vector3 &v) const;
};
#endif // KRMAT4_I

View File

@@ -0,0 +1,144 @@
//
// KRMaterial.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-10-24.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
#include "KRMaterial.h"
KRMaterial::KRMaterial(KRShaderManager *pShaderManager) {
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;
m_tr = (GLfloat)0.0f;
m_ns = (GLfloat)0.0f;
m_pShaderManager = pShaderManager;
}
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::setTransparency(GLfloat a) {
m_tr = a;
}
void KRMaterial::setShininess(GLfloat s) {
m_ns = s;
}
bool KRMaterial::isTransparent() {
return m_tr != 0.0;
}
void KRMaterial::bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->bEnableDiffuseMap;
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
KRShader *pShader = m_pShaderManager->getShader(pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers);
pShader->bind(pCamera, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
glUniform3f(
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT],
m_ka_r + pCamera->dAmbientR,
m_ka_g + pCamera->dAmbientG,
m_ka_b + pCamera->dAmbientB
);
glUniform3f(
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE],
m_kd_r * pCamera->dSunR,
m_kd_g * pCamera->dSunG,
m_kd_b * pCamera->dSunB
);
glUniform3f(
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR],
m_ks_r * pCamera->dSunR,
m_ks_g * pCamera->dSunG,
m_ks_b * pCamera->dSunB
);
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], 1.0f - m_tr);
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns);
int iTextureName = 0;
if(bDiffuseMap) {
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(bSpecMap) {
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(bNormalMap) {
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);
}
}

View File

@@ -0,0 +1,59 @@
//
// 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>
#import <string>
using std::list;
#ifndef KRMATERIAL_H
#define KRMATRIAL_H
#import "KRTexture.h"
#import "KRShaderManager.h"
#import "KRShader.h"
#import "KRCamera.h"
class KRMaterial {
public:
KRMaterial(KRShaderManager *pShaderManager);
~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 setTransparency(GLfloat a);
void setShininess(GLfloat s);
void bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
bool isTransparent();
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
GLfloat m_tr; // Transparency
GLfloat m_ns; // Shininess
KRShaderManager *m_pShaderManager;
};
#endif

View File

@@ -0,0 +1,184 @@
//
// 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, KRShaderManager *pShaderManager) {
m_pTextureManager = pTextureManager;
m_pShaderManager = pShaderManager;
}
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_pShaderManager);
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(strcmp(szSymbol[0], "Tr") == 0) {
char *pScan2 = szSymbol[1];
double a = strtof(pScan2, &pScan2);
pMaterial->setTransparency(a);
} else if(strcmp(szSymbol[0], "Ns") == 0) {
char *pScan2 = szSymbol[1];
double a = strtof(pScan2, &pScan2);
pMaterial->setShininess(a);
} 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);
}
return bSuccess;
}

View File

@@ -0,0 +1,37 @@
//
// 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 "KRMaterialManager.h"
#include <map>
#import <string>
using std::map;
class KRMaterialManager {
public:
KRMaterialManager(KRTextureManager *pTextureManager, KRShaderManager *pShaderManager);
~KRMaterialManager();
bool loadFile(const char *szPath);
KRMaterial *getMaterial(const char *szName);
private:
map<std::string, KRMaterial *> m_materials;
KRTextureManager *m_pTextureManager;
KRShaderManager *m_pShaderManager;
};
#endif

View File

@@ -0,0 +1,617 @@
//
// 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"
#import "KRShader.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(KRCamera *pCamera, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
for(std::vector<Material *>::iterator itr = m_materials.begin(); itr != m_materials.end(); itr++) {
KRMaterial *pMaterial = (*itr)->pMaterial;
if(pMaterial != NULL) {
if(!bRenderShadowMap) {
pMaterial->bind(pCamera, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
}
if(!bRenderShadowMap || !pMaterial->isTransparent()) {
// Exclude transparent and semi-transparent meshes from shadow maps
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(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(0));
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_NORMAL, 3, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(sizeof(Vertex3D)));
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(sizeof(Vertex3D) + sizeof(Vector3D)));
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUV, 2, GL_FLOAT, 0, sizeof(VertexData), BUFFER_OFFSET(sizeof(Vertex3D) + sizeof(Vector3D) * 2));
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TEXUV);
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,98 @@
//
// 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>
#import <string>
using std::vector;
#ifndef KRMODEL_I
#define KRMODEL_I
#import "KRMaterialManager.h"
#import "KRCamera.h"
class KRModel {
public:
KRModel(std::string path, KRMaterialManager *pMaterialManager);
~KRModel();
void render(KRCamera *pCamera, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
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,35 @@
//
// KRModelManager.cpp
// gldemo
//
// Created by Kearwood Gilbert on 10-12-31.
// Copyright 2010 Kearwood Software. All rights reserved.
//
#include "KRModelManager.h"
KRModelManager::KRModelManager(KRMaterialManager *pMaterialManager) {
m_pMaterialManager = pMaterialManager;
}
KRModelManager::~KRModelManager() {
for(map<std::string, KRModel *>::iterator itr = m_models.begin(); itr != m_models.end(); ++itr){
delete (*itr).second;
}
m_models.empty();
}
KRModel *KRModelManager::loadModel(const char *szName, const char *szPath) {
KRModel *pModel = new KRModel(szPath, m_pMaterialManager);
m_models[szName] = pModel;
return pModel;
}
KRModel *KRModelManager::getModel(const char *szName) {
return m_models[szName];
}
KRModel *KRModelManager::getFirstModel() {
static std::map<std::string, KRModel *>::iterator model_itr = m_models.begin();
return (*model_itr).second;
}

View File

@@ -0,0 +1,32 @@
//
// KRModelManager.h
// gldemo
//
// Created by Kearwood Gilbert on 10-12-31.
// Copyright 2010 Kearwood Software. All rights reserved.
//
#ifndef KRMODELMANAGER_H
#define KRMODELMANAGER_H
#include "KRModel.h"
#include <map>
#import <string>
using std::map;
class KRModelManager {
public:
KRModelManager(KRMaterialManager *pMaterialManager);
~KRModelManager();
KRModel *loadModel(const char *szName, const char *szPath);
KRModel *getModel(const char *szName);
KRModel *getFirstModel();
private:
std::map<std::string, KRModel *> m_models;
KRMaterialManager *m_pMaterialManager;
};
#endif

View File

@@ -0,0 +1,95 @@
//
// KRScene.cpp
// KREngine
//
// Created by Kearwood Gilbert on 11-09-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#include <iostream>
#import "KRVector3.h"
#import "KRMat4.h"
#import "KRScene.h"
KRScene::KRScene() {
m_pExtents = NULL;
}
KRScene::~KRScene() {
for(vector<KRInstance *>::iterator itr = m_instances.begin(); itr != m_instances.end(); ++itr){
delete *itr;
}
m_instances.empty();
clearExtents();
}
KRInstance *KRScene::addInstance(KRModel *pModel, KRMat4 modelMatrix) {
clearExtents();
KRInstance *pInstance = new KRInstance(pModel, modelMatrix);
m_instances.push_back(pInstance);
return pInstance;
}
void KRScene::render(KRCamera *pCamera, KRBoundingVolume &frustrumVolume, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &viewMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
if(cShadowBuffers > 0 && !bRenderShadowMap) {
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[0]);
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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
if(cShadowBuffers > 1 && !bRenderShadowMap) {
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[1]);
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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
if(cShadowBuffers > 2 && !bRenderShadowMap) {
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, shadowDepthTextures[2]);
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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
for(vector<KRInstance *>::iterator itr = m_instances.begin(); itr != m_instances.end(); ++itr){
KRInstance *pInstance = *itr;
if(pInstance->getExtents().test_intersect(frustrumVolume) || bRenderShadowMap) {
pInstance->render(pCamera, pMaterialManager, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
}
}
}
void KRScene::calcExtents() {
clearExtents();
for(vector<KRInstance *>::iterator itr = m_instances.begin(); itr != m_instances.end(); ++itr){
KRInstance *pInstance = *itr;
if(m_pExtents) {
*m_pExtents = m_pExtents->get_union(pInstance->getExtents());
} else {
m_pExtents = new KRBoundingVolume(pInstance->getExtents());
}
}
}
KRBoundingVolume KRScene::getExtents() {
if(!m_pExtents) {
calcExtents();
}
return *m_pExtents;
}
void KRScene::clearExtents() {
if(m_pExtents) {
delete m_pExtents;
m_pExtents = NULL;
}
}

View File

@@ -0,0 +1,41 @@
//
// KRScene.h
// KREngine
//
// Created by Kearwood Gilbert on 11-09-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#ifndef KRSCENE_H
#define KRSCENE_H
#import <vector>
#import "KRInstance.h"
#import "KRBoundingVolume.h"
#import "KRMat4.h"
#import "KRModel.h"
#import "KRCamera.h"
class KRBoundingVolume;
class KRInstance;
using std::vector;
class KRScene {
public:
KRScene();
~KRScene();
KRInstance *addInstance(KRModel *pModel, KRMat4 modelMatrix);
void render(KRCamera *pCamera, KRBoundingVolume &frustrumVolume, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &viewMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
KRBoundingVolume getExtents();
private:
vector<KRInstance *> m_instances;
KRBoundingVolume *m_pExtents;
void calcExtents();
void clearExtents();
};
#endif

View File

@@ -0,0 +1,181 @@
//
// KRShader.cpp
// KREngine
//
// Created by Kearwood Gilbert on 11-08-11.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#include "KRShader.h"
KRShader::KRShader(std::string options, const GLchar *szVertShaderSource, const GLchar *szFragShaderSource) {
m_iProgram = 0;
GLuint vertexShader = 0, fragShader = 0;
try {
const GLchar *vertSource[2] = {options.c_str(), szVertShaderSource};
const GLchar *fragSource[2] = {options.c_str(), szFragShaderSource};
// Create shader program.
m_iProgram = glCreateProgram();
// Create and compile vertex shader.
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 2, vertSource, NULL);
glCompileShader(vertexShader);
// Create and compile vertex shader.
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragShader, 2, fragSource, NULL);
glCompileShader(fragShader);
// Attach vertex shader to program.
glAttachShader(m_iProgram, vertexShader);
// Attach fragment shader to program.
glAttachShader(m_iProgram, fragShader);
// Bind attribute locations.
// This needs to be done prior to linking.
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "position");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUV, "inputTextureCoordinate");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "myVertex");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_NORMAL, "myNormal");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TANGENT, "myTangent");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUV, "myUV");
// Link program.
glLinkProgram(m_iProgram);
// Get uniform locations
m_uniforms[KRENGINE_UNIFORM_MATERIAL_AMBIENT] = glGetUniformLocation(m_iProgram, "material_ambient");
m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse");
m_uniforms[KRENGINE_UNIFORM_MATERIAL_SPECULAR] = glGetUniformLocation(m_iProgram, "material_specular");
m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha");
m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess");
m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_iProgram, "myMVPMatrix");
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "myShadowMVPMatrix1");
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "myShadowMVPMatrix2");
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "myShadowMVPMatrix3");
m_uniforms[KRENGINE_UNIFORM_LIGHTDIRECTION] = glGetUniformLocation(m_iProgram, "lightDirection");
m_uniforms[KRENGINE_UNIFORM_CAMERAPOS] = glGetUniformLocation(m_iProgram, "cameraPosition");
m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] = glGetUniformLocation(m_iProgram, "diffuseTexture");
m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] = glGetUniformLocation(m_iProgram, "specularTexture");
m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] = glGetUniformLocation(m_iProgram, "normalTexture");
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] = glGetUniformLocation(m_iProgram, "shadowTexture1");
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] = glGetUniformLocation(m_iProgram, "shadowTexture2");
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] = glGetUniformLocation(m_iProgram, "shadowTexture3");
} catch(...) {
if(vertexShader) {
glDeleteShader(vertexShader);
vertexShader = 0;
}
if(fragShader) {
glDeleteShader(fragShader);
fragShader = 0;
}
if(m_iProgram) {
glDeleteProgram(m_iProgram);
m_iProgram = 0;
}
}
// Release vertex and fragment shaders.
if (vertexShader) {
glDeleteShader(vertexShader);
}
if (fragShader) {
glDeleteShader(fragShader);
}
}
KRShader::~KRShader() {
if(m_iProgram) {
glDeleteProgram(m_iProgram);
}
}
void KRShader::bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
glUseProgram(m_iProgram);
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MVP], 1, GL_FALSE, mvpMatrix.getPointer());
Vector3 nLightDir = lightDirection;
nLightDir.normalize();
// Bind the light direction vector
glUniform3f(
m_uniforms[KRENGINE_UNIFORM_LIGHTDIRECTION],
(GLfloat)nLightDir.x,
(GLfloat)nLightDir.y,
(GLfloat)nLightDir.z
);
// Bind the camera position, in model space
glUniform3f(
m_uniforms[KRENGINE_UNIFORM_CAMERAPOS],
(GLfloat)cameraPosition.x,
(GLfloat)cameraPosition.y,
(GLfloat)cameraPosition.z
);
// Bind the shadowmap space matrices
for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) {
glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1 + iShadow], 1, GL_FALSE, pShadowMatrices[iShadow].getPointer());
}
// Sets the diffuseTexture variable to the first texture unit
glUniform1i(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE], 0);
// Sets the specularTexture variable to the second texture unit
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE], 1);
// Sets the normalTexture variable to the third texture unit
glUniform1i(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE], 2);
// Sets the shadowTexture variable to the fourth texture unit
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1], 3);
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4);
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5);
/*
#if defined(DEBUG)
if (![self validateProgram:m_iProgram])
{
NSLog(@"Failed to validate program: %d", m_shadowShaderProgram);
return;
}
#endif
*/
GLint logLength, status;
glValidateProgram(m_iProgram);
glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(m_iProgram, logLength, &logLength, log);
fprintf(stderr, "Program validate log:\n%s", log);
free(log);
}
/*
glGetProgramiv(m_iProgram, GL_VALIDATE_STATUS, &status);
if (status == 0) {
return false;
} else {
return true;
}
*/
}
GLuint KRShader::getProgram() {
return m_iProgram;
}

View File

@@ -0,0 +1,67 @@
//
// KRShader.h
// KREngine
//
// Created by Kearwood Gilbert on 11-08-11.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <stdint.h>
#import <vector>
#import <string>
using std::vector;
#ifndef KRSHADER_H
#define KRSHADER_H
#import "KRShader.h"
#import "KRMat4.h"
#import "KRCamera.h"
class KRShader {
public:
KRShader(std::string options, const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
~KRShader();
GLuint getProgram();
void bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPosition, Vector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
enum {
KRENGINE_ATTRIB_VERTEX,
KRENGINE_ATTRIB_NORMAL,
KRENGINE_ATTRIB_TANGENT,
KRENGINE_ATTRIB_TEXUV,
KRENGINE_NUM_ATTRIBUTES
};
enum {
KRENGINE_UNIFORM_MATERIAL_AMBIENT,
KRENGINE_UNIFORM_MATERIAL_DIFFUSE,
KRENGINE_UNIFORM_MATERIAL_SPECULAR,
KRENGINE_UNIFORM_MATERIAL_ALPHA,
KRENGINE_UNIFORM_MATERIAL_SHININESS,
KRENGINE_UNIFORM_MVP,
KRENGINE_UNIFORM_LIGHTDIRECTION,
KRENGINE_UNIFORM_CAMERAPOS,
KRENGINE_UNIFORM_DIFFUSETEXTURE,
KRENGINE_UNIFORM_SPECULARTEXTURE,
KRENGINE_UNIFORM_NORMALTEXTURE,
KRENGINE_UNIFORM_SHADOWMVP1,
KRENGINE_UNIFORM_SHADOWMVP2,
KRENGINE_UNIFORM_SHADOWMVP3,
KRENGINE_UNIFORM_SHADOWTEXTURE1,
KRENGINE_UNIFORM_SHADOWTEXTURE2,
KRENGINE_UNIFORM_SHADOWTEXTURE3,
KRENGINE_NUM_UNIFORMS
};
GLint m_uniforms[KRENGINE_NUM_UNIFORMS];
private:
GLuint m_iProgram;
};
#endif

View File

@@ -0,0 +1,68 @@
//
// KRShaderManager.cpp
// KREngine
//
// Created by Kearwood Gilbert on 11-08-11.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#include "KRShaderManager.h"
#include <sstream>
using namespace std;
KRShaderManager::KRShaderManager(const GLchar *szVertShaderSource, const GLchar *szFragShaderSource) {
m_szFragShaderSource = new GLchar[strlen(szFragShaderSource)+1];
m_szVertShaderSource = new GLchar[strlen(szVertShaderSource)+1];
strcpy(m_szFragShaderSource, szFragShaderSource);
strcpy(m_szVertShaderSource, szVertShaderSource);
}
KRShaderManager::~KRShaderManager() {
delete m_szFragShaderSource;
delete m_szVertShaderSource;
}
KRShader *KRShaderManager::getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality) {
char szKey[128];
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d", pCamera->bEnablePerPixel, bDiffuseMap, bNormalMap, bSpecMap, pCamera->bDebugPSSM, iShadowQuality, /*pCamera->dAmbientR, pCamera->dAmbientG, pCamera->dAmbientB, pCamera->dSunR, pCamera->dSunG, pCamera->dSunB, */pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular);
/*
const char *options = "#define HAS_DIFFUSE_MAP 1\n#define HAS_NORMAL_MAP 0\n#define HAS_SPEC_MAP 0\n#define ENABLE_PER_PIXEL 0\n#define DEBUG_PSSM 0\n#define SHADOW_QUALITY 0\n#define SUN_INTENSITY 1.5\n#define AMBIENT_INTENSITY_R 0.25\n#define AMBIENT_INTENSITY_G 0.25\n#define AMBIENT_INTENSITY_B 0.25\n";
*/
KRShader *pShader = m_shaders[szKey];
if(pShader == NULL) {
if(m_shaders.size() > KRENGINE_MAX_SHADER_HANDLES) {
// Keep the size of the shader cache reasonable
std::map<std::string, KRShader *>::iterator itr = m_shaders.begin();
delete (*itr).second;
m_shaders.erase(itr);
}
stringstream stream;
stream.precision(std::numeric_limits<long double>::digits10);
stream << "#define HAS_DIFFUSE_MAP " << (bDiffuseMap ? "1" : "0");
stream << "\n#define HAS_NORMAL_MAP " << (bNormalMap ? "1" : "0");
stream << "\n#define HAS_SPEC_MAP " << (bSpecMap ? "1" : "0");
stream << "\n#define ENABLE_PER_PIXEL " << (pCamera->bEnablePerPixel ? "1" : "0");
stream << "\n#define DEBUG_PSSM " << (pCamera->bDebugPSSM ? "1" : "0");
stream << "\n#define SHADOW_QUALITY " << iShadowQuality;
stream << "\n#define ENABLE_AMBIENT " << (pCamera->bEnableAmbient ? "1" : "0");
stream << "\n#define ENABLE_DIFFUSE " << (pCamera->bEnableDiffuse ? "1" : "0");
stream << "\n#define ENABLE_SPECULAR " << (pCamera->bEnableSpecular ? "1" : "0");
stream.setf(ios::fixed,ios::floatfield);
stream << "\n";
std::string options = stream.str();
pShader = new KRShader(options, m_szVertShaderSource, m_szFragShaderSource);
m_shaders[szKey] = pShader;
}
return pShader;
}

View File

@@ -0,0 +1,43 @@
//
// KRShaderManager.h
// KREngine
//
// Created by Kearwood Gilbert on 11-08-11.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <stdint.h>
#import <vector>
#import <map>
#import <string>
#import "KRCamera.h"
using std::map;
using std::vector;
#include "KRShader.h"
#ifndef KRSHADERMANAGER_H
#define KRSHADERMANAGER_H
#define KRENGINE_MAX_SHADER_HANDLES 100
class KRShaderManager {
public:
KRShaderManager(const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
~KRShaderManager();
KRShader *getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality);
private:
std::map<std::string, KRShader *> m_shaders;
GLchar *m_szFragShaderSource;
GLchar *m_szVertShaderSource;
KRShader *m_pShader;
};
#endif

View File

@@ -0,0 +1,209 @@
//
// 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>
#import <assert.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;
} else {
assert(false);
}
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,49 @@
//
// 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>
#import <string>
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;
};
std::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,32 @@
//
// 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>
#import <string>
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:
std::map<std::string, KRTexture *> m_textures;
};
#endif

View File

@@ -0,0 +1,97 @@
//
// 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()
{
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
Vector3::Vector3(float X = 0, float Y = 0, float Z = 0)
{
x = X;
y = Y;
z = Z;
}
Vector3::Vector3(const Vector3& p) {
x = p.x;
y = p.y;
z = p.z;
}
Vector3& Vector3::operator = ( const Vector3& p ) {
x = p.x;
y = p.y;
z = p.z;
return *this;
}
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,54 @@
//
// 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();
~Vector3();
Vector3(const Vector3& p);
Vector3& operator = ( const Vector3& p );
//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,7 @@
//
// Prefix header for all source files of the 'KREngine' target in the 'KREngine' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif

View File

@@ -0,0 +1,154 @@
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
uniform lowp float material_alpha;
#if ENABLE_PER_PIXEL == 1
uniform mediump float material_shininess;
#endif
#if HAS_DIFFUSE_MAP == 1
uniform sampler2D diffuseTexture;
#endif
#if HAS_SPEC_MAP == 1
uniform sampler2D specularTexture;
#endif
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
uniform sampler2D normalTexture;
#endif
#if SHADOW_QUALITY >= 1
uniform sampler2D shadowTexture1;
varying highp vec4 shadowMapCoord1;
#endif
#if SHADOW_QUALITY >= 2
uniform sampler2D shadowTexture2;
varying highp vec4 shadowMapCoord2;
#endif
#if SHADOW_QUALITY >= 3
uniform sampler2D shadowTexture3;
varying highp vec4 shadowMapCoord3;
#endif
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
varying mediump vec2 texCoord;
#endif
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
varying mediump vec3 normal;
#endif
#if ENABLE_PER_PIXEL == 1
varying mediump vec3 lightVec;
varying mediump vec3 halfVec;
#else
varying mediump float lamberFactor;
varying mediump float specularFactor;
#endif
void main()
{
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
// 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);
#endif
#if ENABLE_PER_PIXEL == 1
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
mediump float specularFactor = 0.0;
if(material_shininess > 0.0) {
specularFactor = max(0.0,pow(dot(halfVec,normal), material_shininess));
}
#endif
#if HAS_DIFFUSE_MAP == 1
mediump vec4 diffuseMaterial = vec4(vec3(texture2D(diffuseTexture, texCoord)), material_alpha);
#else
mediump vec4 diffuseMaterial = vec4(vec3(1.0), material_alpha);
#endif
#if SHADOW_QUALITY == 1
highp float shadowMapDepth = 1.0;
highp float vertexShadowDepth = 1.0;
highp vec2 shadowMapPos = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).st;
if(shadowMapCoord1.x >= -1.0 && shadowMapCoord1.x <= 1.0 && shadowMapCoord1.y >= -1.0 && shadowMapCoord1.y <= 1.0 && shadowMapCoord1.z >= 0.0 && shadowMapCoord1.z <= 1.0) {
#if DEBUG_PSSM == 1
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5, 0.0);
#endif
shadowMapDepth = texture2D(shadowTexture1, shadowMapPos).z; // unpack(texture2D(shadowTexture1, shadowMapPos));
vertexShadowDepth = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).z;
}
#endif
#if SHADOW_QUALITY >= 2
highp float shadowMapDepth = 1.0;
highp float vertexShadowDepth = 1.0;
if(shadowMapCoord1.x >= -1.0 && shadowMapCoord1.x <= 1.0 && shadowMapCoord1.y >= -1.0 && shadowMapCoord1.y <= 1.0 && shadowMapCoord1.z >= 0.0 && shadowMapCoord1.z <= 1.0) {
#if DEBUG_PSSM == 1
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5, 0.0);
#endif
highp vec2 shadowMapPos = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).st;
shadowMapDepth = texture2D(shadowTexture1, shadowMapPos).z;
vertexShadowDepth = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).z;
}
else if(shadowMapCoord2.s >= -1.0 && shadowMapCoord2.s <= 1.0 && shadowMapCoord2.t >= -1.0 && shadowMapCoord2.t <= 1.0 && shadowMapCoord2.z >= 0.0 && shadowMapCoord2.z <= 1.0) {
#if DEBUG_PSSM == 1
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.50, 0.75, 1.0) + vec4(0.0, 0.5, 0.0, 0.0);
#endif
highp vec2 shadowMapPos = ((shadowMapCoord2 / shadowMapCoord2.w + 1.0) / 2.0).st;
shadowMapDepth = texture2D(shadowTexture2, shadowMapPos).z;
vertexShadowDepth = ((shadowMapCoord2 / shadowMapCoord2.w + 1.0) / 2.0).z;
}
#if SHADOW_QUALITY >= 3
else if(shadowMapCoord3.s >= -1.0 && shadowMapCoord3.s <= 1.0 && shadowMapCoord3.t >= -1.0 && shadowMapCoord3.t <= 1.0 && shadowMapCoord3.z >= 0.0 && shadowMapCoord3.z <= 1.0) {
#if DEBUG_PSSM == 1
diffuseMaterial = diffuseMaterial * vec4(0.50, 0.75, 0.75, 1.0) + vec4(0.5, 0.0, 0.0, 0.0);
#endif
highp vec2 shadowMapPos = ((shadowMapCoord3 / shadowMapCoord3.w + 1.0) / 2.0).st;
shadowMapDepth = texture2D(shadowTexture3, shadowMapPos).z;
vertexShadowDepth = ((shadowMapCoord3 / shadowMapCoord3.w + 1.0) / 2.0).z;
}
#endif
#endif
#if SHADOW_QUALITY >= 1
if(vertexShadowDepth >= shadowMapDepth && shadowMapDepth < 1.0) {
lamberFactor = 0.0;
specularFactor = 0.0;
}
#endif
#if ENABLE_AMBIENT
// -------------------- Add ambient light and alpha component --------------------
gl_FragColor = vec4(vec3(diffuseMaterial) * material_ambient, material_alpha);
#else
gl_FragColor = vec4(0.0, 0.0, 0.0, material_alpha);
#endif
#if ENABLE_DIFFUSE
// -------------------- Add diffuse light --------------------
gl_FragColor += vec4(vec3(diffuseMaterial) * material_diffuse * lamberFactor, 0.0);
#endif
#if ENABLE_SPECULAR
// -------------------- Add specular light --------------------
#if HAS_SPEC_MAP == 1
gl_FragColor += vec4(material_specular * vec3(texture2D(specularTexture, texCoord)) * specularFactor, 0.0);
#else
gl_FragColor += vec4(material_specular * specularFactor, 0.0);
#endif
#endif
}

View File

@@ -0,0 +1,101 @@
//
// Shader.vsh
// gldemo
//
// Created by Kearwood Gilbert on 10-09-16.
// Copyright (c) 2010 Kearwood Software. All rights reserved.
//
attribute highp vec3 myVertex, myNormal;
attribute highp vec3 myTangent;
attribute mediump vec2 myUV;
uniform highp mat4 myMVPMatrix, myShadowMVPMatrix1,myShadowMVPMatrix2,myShadowMVPMatrix3; // mvpmatrix is the result of multiplying the model, view, and projection matrices
// uniform lowp vec3 material_ambient, material_diffuse, material_specular;
uniform highp vec3 lightDirection; // Must be normalized before entering shader
uniform highp vec3 cameraPosition;
#if ENABLE_PER_PIXEL == 0
uniform mediump float material_shininess;
#endif
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
varying mediump vec2 texCoord;
#endif
#if ENABLE_PER_PIXEL == 1
varying mediump vec3 lightVec;
varying mediump vec3 halfVec;
#else
varying mediump float lamberFactor;
varying mediump float specularFactor;
#endif
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
varying mediump vec3 normal;
#endif
#if SHADOW_QUALITY >= 1
varying highp vec4 shadowMapCoord1;
#endif
#if SHADOW_QUALITY >= 2
varying highp vec4 shadowMapCoord2;
#endif
#if SHADOW_QUALITY >= 3
varying highp vec4 shadowMapCoord3;
#endif
void main()
{
// Transform position
gl_Position = myMVPMatrix * vec4(myVertex,1.0);
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
// Pass UV co-ordinates
texCoord = myUV.st;
#endif
#if SHADOW_QUALITY >= 1
shadowMapCoord1 = myShadowMVPMatrix1 * vec4(myVertex,1.0);
#endif
#if SHADOW_QUALITY >= 2
shadowMapCoord2 = myShadowMVPMatrix2 * vec4(myVertex,1.0);
#endif
#if SHADOW_QUALITY >= 3
shadowMapCoord3 = myShadowMVPMatrix3 * vec4(myVertex,1.0);
#endif
// ----------- Directional Light (Sun) -----------
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
// ----- Calculate per-pixel lighting in tangent space, for normal mapping ------
mediump vec3 eyeVec = normalize(cameraPosition - myVertex);
mediump vec3 a_bitangent = cross(myNormal, myTangent);
lightVec = normalize(vec3(dot(lightDirection, myTangent), dot(lightDirection, a_bitangent), dot(lightDirection, myNormal)));
halfVec = normalize(vec3(dot(eyeVec, myTangent), dot(eyeVec, a_bitangent), dot(eyeVec, myNormal)));
halfVec = normalize(halfVec + lightVec); // Normalizing anyways, no need to divide by 2
#else
#if ENABLE_PER_PIXEL == 1
// ------ Calculate per-pixel lighting without normal mapping ------
normal = myNormal;
lightVec = lightDirection;
halfVec = normalize((normalize(cameraPosition - myVertex) + lightVec)); // Normalizing anyways, no need to divide by 2
#else
// ------ Calculate per-vertex lighting ------
mediump vec3 halfVec = normalize((normalize(cameraPosition - myVertex) + lightDirection)); // Normalizing anyways, no need to divide by 2
lamberFactor = max(0.0,dot(lightDirection, myNormal));
specularFactor = 0.0;
if(material_shininess > 0.0) {
specularFactor = max(0.0,pow(dot(halfVec,myNormal), material_shininess));
}
#endif
#endif
}

View File

@@ -0,0 +1,153 @@
#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);
#if DOF_QUALITY > 0 || ENABLE_FLASH == 1
mediump float depth = texture2D(depthFrame, textureCoordinate).r;
#endif
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 - DOF_DEPTH - focusDepth) / DOF_FALLOFF, 0.0, 1.0);
pixelColor = pixelColor * blurAmount + renderColor * (1.0 - blurAmount);
#endif
// ---- DEPTH_OF_FIELD END ----
// ---- NIGHT_TIME START ----
#if ENABLE_FLASH == 1
// Un-comment to enable night time / flash effect
pixelColor *= vec4(vec3(1.0 - clamp((depth - FLASH_DEPTH) / FLASH_FALLOFF, 0.0, 1.0)) * FLASH_INTENSITY, 1.0);
//pixelColor *= vec4(vec3(clamp(1.0 / (depth - FLASH_DEPTH) * FLASH_FALLOFF, 0.0, 1.0) * FLASH_INTENSITY), 1.0);
#endif
// ---- 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
#if ENABLE_VIGNETTE
pixelColor *= vec4(vec3(clamp(1.0 - (distance(textureCoordinate, vec2(0.5, 0.5)) - VIGNETTE_RADIUS) / VIGNETTE_FALLOFF, 0.0, 1.0)), 1.0);
#endif
// ---- 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,8 @@
uniform sampler2D diffuseTexture;
varying mediump vec2 texCoord;
void main()
{
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

View File

@@ -0,0 +1,26 @@
#define SHADOW_BIAS 0.01
attribute highp vec3 myVertex;
/*
attribute mediump vec2 myUV;
varying mediump vec2 texCoord;
*/
uniform highp mat4 myShadowMVPMatrix1; // Shadowmvpmatrix is the result of multiplying the model, view, and projection matrices
void main()
{
// Transform position
/*
position = myShadowMVPMatrix1 * vec4(myVertex,1.0);
*/
gl_Position = myShadowMVPMatrix1 * vec4(myVertex,1.0);
gl_Position.z += SHADOW_BIAS;
/*
// Pass UV co-ordinates
texCoord = myUV.st;
*/
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:objpack/objpack.xcodeproj">
</FileRef>
<FileRef
location = "group:objview/KRObjView.xcodeproj">
</FileRef>
<FileRef
location = "container:KREngine/KREngine.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,215 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
E404C89D136B8E2F00B6C99B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E404C89C136B8E2F00B6C99B /* main.cpp */; };
E404C8A6136B901400B6C99B /* KROBJPacker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E404C8A4136B901400B6C99B /* KROBJPacker.cpp */; };
E404C8A9136B919F00B6C99B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E404C8A7136B919F00B6C99B /* KRVector3.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
E404C896136B8E2F00B6C99B /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
E404C898136B8E2F00B6C99B /* objpack */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = objpack; sourceTree = BUILT_PRODUCTS_DIR; };
E404C89C136B8E2F00B6C99B /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
E404C89E136B8E2F00B6C99B /* objpack.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = objpack.1; sourceTree = "<group>"; };
E404C8A4136B901400B6C99B /* KROBJPacker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KROBJPacker.cpp; sourceTree = "<group>"; };
E404C8A5136B901400B6C99B /* KROBJPacker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KROBJPacker.h; sourceTree = "<group>"; };
E404C8A7136B919F00B6C99B /* KRVector3.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRVector3.cpp; sourceTree = "<group>"; };
E404C8A8136B919F00B6C99B /* KRVector3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRVector3.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
E404C895136B8E2F00B6C99B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
E404C88D136B8E2F00B6C99B = {
isa = PBXGroup;
children = (
E404C89B136B8E2F00B6C99B /* objpack */,
E404C899136B8E2F00B6C99B /* Products */,
);
sourceTree = "<group>";
};
E404C899136B8E2F00B6C99B /* Products */ = {
isa = PBXGroup;
children = (
E404C898136B8E2F00B6C99B /* objpack */,
);
name = Products;
sourceTree = "<group>";
};
E404C89B136B8E2F00B6C99B /* objpack */ = {
isa = PBXGroup;
children = (
E404C89C136B8E2F00B6C99B /* main.cpp */,
E404C89E136B8E2F00B6C99B /* objpack.1 */,
E404C8A4136B901400B6C99B /* KROBJPacker.cpp */,
E404C8A5136B901400B6C99B /* KROBJPacker.h */,
E404C8A7136B919F00B6C99B /* KRVector3.cpp */,
E404C8A8136B919F00B6C99B /* KRVector3.h */,
);
path = objpack;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
E404C897136B8E2F00B6C99B /* objpack */ = {
isa = PBXNativeTarget;
buildConfigurationList = E404C8A1136B8E3000B6C99B /* Build configuration list for PBXNativeTarget "objpack" */;
buildPhases = (
E404C894136B8E2F00B6C99B /* Sources */,
E404C895136B8E2F00B6C99B /* Frameworks */,
E404C896136B8E2F00B6C99B /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = objpack;
productName = objpack;
productReference = E404C898136B8E2F00B6C99B /* objpack */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
E404C88F136B8E2F00B6C99B /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
ORGANIZATIONNAME = "Kearwood Software";
};
buildConfigurationList = E404C892136B8E2F00B6C99B /* Build configuration list for PBXProject "objpack" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = E404C88D136B8E2F00B6C99B;
productRefGroup = E404C899136B8E2F00B6C99B /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
E404C897136B8E2F00B6C99B /* objpack */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
E404C894136B8E2F00B6C99B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E404C89D136B8E2F00B6C99B /* main.cpp in Sources */,
E404C8A6136B901400B6C99B /* KROBJPacker.cpp in Sources */,
E404C8A9136B919F00B6C99B /* KRVector3.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
E404C89F136B8E3000B6C99B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
E404C8A0136B8E3000B6C99B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.6;
SDKROOT = macosx;
};
name = Release;
};
E404C8A2136B8E3000B6C99B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
E404C8A3136B8E3000B6C99B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
E404C892136B8E2F00B6C99B /* Build configuration list for PBXProject "objpack" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E404C89F136B8E3000B6C99B /* Debug */,
E404C8A0136B8E3000B6C99B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E404C8A1136B8E3000B6C99B /* Build configuration list for PBXNativeTarget "objpack" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E404C8A2136B8E3000B6C99B /* Debug */,
E404C8A3136B8E3000B6C99B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = E404C88F136B8E2F00B6C99B /* Project object */;
}

View File

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

View File

@@ -0,0 +1,491 @@
//
// objpacker.cpp
// objpack
//
// Created by Kearwood Gilbert on 11-04-29.
// Copyright 2011 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 <vector.h>
#include "KROBJPacker.h"
#include "KRVector3.h"
KROBJPacker::KROBJPacker() {
}
KROBJPacker::~KROBJPacker() {
}
void KROBJPacker::pack(const char *szPath) {
int fdFile = 0;
int fileSize = 0;
void *pFile = NULL;
char szSymbol[16][64];
std::vector<std::string> materials;
Vertex3D *pVertices = NULL;
Vector3D *pNormals = NULL;
TexCoord *pTexCoords = NULL;
int *pFaces = NULL;
vector<pack_material *> m_materials;
VertexData *m_pVertexData = NULL;
pack_header header;
strcpy(header.szTag, "KROBJPACK1.0 ");
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
cout << " Pass 1 - Getting Counts\n";
int cVertices = 0;
int cNormals = 0;
int cTexCoords = 0;
int cVertexData = 0;
cVertices = 0;
int cFaces = 1;
int 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(std::string(szSymbol[1]));
}
}
}
// Pass 2 - Populate vertexes and faces
cout << " Pass 2 - Populate vertexes and faces\n";
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<std::string>::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)
int 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;
pack_material *pMaterial = new pack_material();
pMaterial->start_vertex = iVertex;
pMaterial->vertex_count = 0;
memset(pMaterial->szName, 64, 0);
if(material_itr < materials.end()) {
strncpy(pMaterial->szName, (*material_itr++).c_str(), 64);
}
m_materials.push_back(pMaterial);
pFace = pFaces;
while(*pFace != 0 && iVertex < cVertexData) {
pMaterial->start_vertex = iVertex;
int *pMaterialEndFace = pFace + *pFace++;
while(pFace < pMaterialEndFace && iVertex < cVertexData) {
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 pack_material();
pMaterial->start_vertex = iVertex;
pMaterial->vertex_count = 0;
memset(pMaterial->szName, 64, 0);
if(material_itr < materials.end()) {
strncpy(pMaterial->szName, (*material_itr++).c_str(), 64);
}
m_materials.push_back(pMaterial);
}
}
header.minx = 0.0;
header.miny = 0.0;
header.minz = 0.0;
header.maxx = 0.0;
header.maxy = 0.0;
header.maxz = 0.0;
// Calculate surface normals and tangents
cout << " Pass 3 - Calculate surface normals and tangents\n";
// http://www.terathon.com/code/tangent.html
// http://www.fabiensanglard.net/bumpMapping/index.php
for(std::vector<pack_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 < header.minx) header.minx = pVertex->vertex.x;
if(pVertex->vertex.x > header.maxx) header.maxx = pVertex->vertex.x;
if(pVertex->vertex.y < header.miny) header.miny = pVertex->vertex.y;
if(pVertex->vertex.y > header.maxy) header.maxy = pVertex->vertex.y;
if(pVertex->vertex.z < header.minz) header.minz = pVertex->vertex.z;
if(pVertex->vertex.z > header.maxz) header.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;
}
}
// Write output file
std::string out_file_name = szPath;
out_file_name.append(".pack");
cout << " Writing obj.pack file:" << out_file_name << " ... \n";
FILE *out_file = fopen(out_file_name.c_str(), "w");
header.material_count = 0;
for(std::vector<pack_material *>::iterator itr = m_materials.begin(); itr != m_materials.end(); itr++) {
pack_material *pMaterial = (*itr);
if(pMaterial->vertex_count) { // Skip materials with no vertices
header.material_count++;
}
}
header.vertex_count = cVertexData;
fwrite(&header, sizeof(header), 1, out_file);
for(std::vector<pack_material *>::iterator itr = m_materials.begin(); itr != m_materials.end(); itr++) {
pack_material *pMaterial = (*itr);
if(pMaterial->vertex_count) { // Skip materials with no vertices
fwrite(pMaterial, sizeof(pack_material), 1, out_file);
cout << " " << pMaterial->szName << ": " << pMaterial->vertex_count << " vertices\n";
}
}
fwrite(m_pVertexData, sizeof(VertexData), cVertexData, out_file);
fclose(out_file);
}
}
}
if(pFile != NULL) {
munmap(pFile, fileSize);
}
if(fdFile != 0) {
close(fdFile);
}
if(m_pVertexData) {
free(m_pVertexData);
}
if(pVertices) {
free(pVertices);
}
if(pNormals) {
free(pNormals);
}
if(pTexCoords) {
free(pTexCoords);
}
if(pFaces) {
free(pFaces);
}
}

View File

@@ -0,0 +1,55 @@
//
// objpacker.h
// objpack
//
// Created by Kearwood Gilbert on 11-04-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#import <vector.h>
#import <stdint.h>
#ifndef OBJPACKER_H
#define OBJPACKER_H
class KROBJPacker {
public:
KROBJPacker();
~KROBJPacker();
void pack(const char *szPath);
private:
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 {
float x;
float y;
float z;
} Vertex3D, Vector3D;
typedef struct {
float u;
float v;
} TexCoord;
typedef struct {
Vertex3D vertex;
Vector3D normal;
Vector3D tangent;
TexCoord texcoord;
} VertexData;
};
#endif // OBJPACKER_H

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

29
objpack/objpack/main.cpp Normal file
View File

@@ -0,0 +1,29 @@
//
// main.cpp
// objpack
//
// Created by Kearwood Gilbert on 11-04-29.
// Copyright 2011 Kearwood Software. All rights reserved.
//
#include <iostream>
#import "KROBJPacker.h"
int main (int argc, const char * argv[])
{
if(argc < 2) {
std::cout << "You must pass an .obj file as a parameter. An .obj.pack file will be written for each .obj file.\n";
} else {
KROBJPacker p;
for(int i=1; i < argc; i++) {
std::cout << "Packing " << argv[i] << " ...\n";
p.pack(argv[i]);
}
std::cout << "Done.\n";
}
return 0;
}

79
objpack/objpack/objpack.1 Normal file
View File

@@ -0,0 +1,79 @@
.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
.\"See Also:
.\"man mdoc.samples for a complete listing of options
.\"man mdoc for the short list of editing options
.\"/usr/share/misc/mdoc.template
.Dd 11-04-29 \" DATE
.Dt objpack 1 \" Program name and manual section number
.Os Darwin
.Sh NAME \" Section Header - required - don't modify
.Nm objpack,
.\" The following lines are read in generating the apropos(man -k) database. Use only key
.\" words here as the database is built based on the words here and in the .ND line.
.Nm Other_name_for_same_program(),
.Nm Yet another name for the same program.
.\" Use .Nm macro to designate other names for the documented program.
.Nd This line parsed for whatis database.
.Sh SYNOPSIS \" Section Header - required - don't modify
.Nm
.Op Fl abcd \" [-abcd]
.Op Fl a Ar path \" [-a path]
.Op Ar file \" [file]
.Op Ar \" [file ...]
.Ar arg0 \" Underlined argument - use .Ar anywhere to underline
arg2 ... \" Arguments
.Sh DESCRIPTION \" Section Header - required - don't modify
Use the .Nm macro to refer to your program throughout the man page like such:
.Nm
Underlining is accomplished with the .Ar macro like this:
.Ar underlined text .
.Pp \" Inserts a space
A list of items with descriptions:
.Bl -tag -width -indent \" Begins a tagged list
.It item a \" Each item preceded by .It macro
Description of item a
.It item b
Description of item b
.El \" Ends the list
.Pp
A list of flags and their descriptions:
.Bl -tag -width -indent \" Differs from above in tag removed
.It Fl a \"-a flag as a list item
Description of -a flag
.It Fl b
Description of -b flag
.El \" Ends the list
.Pp
.\" .Sh ENVIRONMENT \" May not be needed
.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
.\" .It Ev ENV_VAR_1
.\" Description of ENV_VAR_1
.\" .It Ev ENV_VAR_2
.\" Description of ENV_VAR_2
.\" .El
.Sh FILES \" File used or created by the topic of the man page
.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
.It Pa /usr/share/file_name
FILE_1 description
.It Pa /Users/joeuser/Library/really_long_file_name
FILE_2 description
.El \" Ends the list
.\" .Sh DIAGNOSTICS \" May not be needed
.\" .Bl -diag
.\" .It Diagnostic Tag
.\" Diagnostic informtion here.
.\" .It Diagnostic Tag
.\" Diagnostic informtion here.
.\" .El
.Sh SEE ALSO
.\" List links in ascending order by section, alphabetically within a section.
.\" Please do not reference files that do not exist without filing a bug report
.Xr a 1 ,
.Xr b 1 ,
.Xr c 1 ,
.Xr a 2 ,
.Xr b 2 ,
.Xr a 3 ,
.Xr b 3
.\" .Sh BUGS \" Document known, unremedied bugs
.\" .Sh HISTORY \" Document history if command behaves in a unique manner

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;
}