├── .gitignore ├── 01-DrawTriangle ├── DrawTriangle_OOP │ ├── DrawTriangle_OOP.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── DrawTriangle_OOP │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Classes │ │ ├── Common │ │ │ ├── VFCommon.h │ │ │ ├── VFFreeSource.h │ │ │ ├── VFHandleError.h │ │ │ └── VFOpenGLES2XHeader.h │ │ ├── Datas │ │ │ ├── VFBaseGeometricVertexData.h │ │ │ ├── VFVertexDatasManager.h │ │ │ └── VFVertexDatasManager.m │ │ ├── ErrorHandle │ │ │ ├── VFErrorHandler.h │ │ │ ├── VFErrorHandler.m │ │ │ └── VFErrorUnitis.h │ │ ├── Render │ │ │ ├── VFFrameBufferManager.h │ │ │ ├── VFFrameBufferManager.m │ │ │ ├── VFRenderBufferManager.h │ │ │ ├── VFRenderBufferManager.m │ │ │ ├── VFRenderContext.h │ │ │ ├── VFRenderContext.m │ │ │ ├── VFRenderWindow.h │ │ │ └── VFRenderWindow.m │ │ └── Shader │ │ │ ├── VFFragmentShader.glsl │ │ │ ├── VFShaderManager.h │ │ │ ├── VFShaderManager.m │ │ │ └── VFVertexShader.glsl │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── DrawTriangle_OOP_Challenges │ ├── DrawTriangle_OOP │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ ├── Classes │ │ │ ├── Common │ │ │ │ ├── VFCommon.h │ │ │ │ ├── VFFreeSource.h │ │ │ │ ├── VFHandleError.h │ │ │ │ └── VFOpenGLES2XHeader.h │ │ │ ├── Datas │ │ │ │ ├── VFBaseGeometricVertexData.h │ │ │ │ ├── VFVertexDatasManager.h │ │ │ │ └── VFVertexDatasManager.m │ │ │ ├── ErrorHandle │ │ │ │ ├── VFErrorHandler.h │ │ │ │ ├── VFErrorHandler.m │ │ │ │ └── VFErrorUnitis.h │ │ │ ├── Render │ │ │ │ ├── VFFrameBufferManager.h │ │ │ │ ├── VFFrameBufferManager.m │ │ │ │ ├── VFRenderBufferManager.h │ │ │ │ ├── VFRenderBufferManager.m │ │ │ │ ├── VFRenderContext.h │ │ │ │ ├── VFRenderContext.m │ │ │ │ ├── VFRenderWindow.h │ │ │ │ └── VFRenderWindow.m │ │ │ └── Shader │ │ │ │ ├── VFFragmentShader.glsl │ │ │ │ ├── VFShaderManager.h │ │ │ │ ├── VFShaderManager.m │ │ │ │ └── VFVertexShader.glsl │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m │ └── DrawTriangle_OOP_Challenges_1.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── DrawTriangle_OneStep │ ├── DrawTriangle_OneStep.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── DrawTriangle_OneStep │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── VFGLTriangleView.h │ ├── VFGLTriangleView.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 02-DrawTriangle_Fix └── DrawTriangle_Fix │ ├── DrawTriangle_Fix.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── DrawTriangle_Fix │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Classes │ │ ├── Common │ │ │ ├── VFCommon.h │ │ │ ├── VFFreeSource.h │ │ │ ├── VFHandleError.h │ │ │ ├── VFOpenGLES2XHeader.h │ │ │ └── VFShaderValueLocation.h │ │ ├── Datas │ │ │ ├── VFBaseGeometricVertexData.h │ │ │ ├── VFMaths │ │ │ │ ├── VFColor.c │ │ │ │ ├── VFColor.h │ │ │ │ ├── VFMath.h │ │ │ │ ├── VFMathTypes.h │ │ │ │ ├── VFMatrix.c │ │ │ │ ├── VFMatrix.h │ │ │ │ ├── VFVector.c │ │ │ │ └── VFVector.h │ │ │ ├── VFVertexDatasManager.h │ │ │ └── VFVertexDatasManager.m │ │ ├── Render │ │ │ ├── VFFrameBufferManager.h │ │ │ ├── VFFrameBufferManager.m │ │ │ ├── VFRenderBufferManager.h │ │ │ ├── VFRenderBufferManager.m │ │ │ ├── VFRenderContext.h │ │ │ ├── VFRenderContext.m │ │ │ ├── VFRenderWindow.h │ │ │ └── VFRenderWindow.m │ │ └── Shader │ │ │ ├── VFFragmentShader.glsl │ │ │ ├── VFShaderManager.h │ │ │ ├── VFShaderManager.m │ │ │ ├── VFShaderValueInfo.h │ │ │ ├── VFShaderValueInfo.m │ │ │ ├── VFShaderValueRexAnalyzer.h │ │ │ ├── VFShaderValueRexAnalyzer.m │ │ │ └── VFVertexShader.glsl │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m │ └── DrawTriangle_FixTests │ ├── DrawTriangle_FixTests.m │ └── Info.plist ├── 03-DrawGeometries ├── Beizer │ ├── 贝塞尔曲线推导.docx │ └── 贝塞尔曲线推导.pdf ├── DrawGeometries_Challenges │ ├── DrawGeometries_Challenges.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── DrawGeometries_Challenges │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Classes │ │ ├── Common │ │ │ ├── NSValue+Struct2Value.h │ │ │ ├── NSValue+Struct2Value.m │ │ │ ├── VFCommon.h │ │ │ ├── VFFreeSource.h │ │ │ ├── VFHandleError.h │ │ │ ├── VFOpenGLES2XHeader.h │ │ │ ├── VFShaderValueLocation.h │ │ │ └── VFVertex.h │ │ ├── Datas │ │ │ ├── Models │ │ │ │ ├── VFAttachVertexInfo.h │ │ │ │ ├── VFAttachVertexInfo.m │ │ │ │ ├── VFDrawInfo.h │ │ │ │ ├── VFDrawInfo.m │ │ │ │ ├── VFVBODataStoredInfo.h │ │ │ │ └── VFVBODataStoredInfo.m │ │ │ ├── VFBaseGeometricVertexData.h │ │ │ ├── VFGeometriesPoints.h │ │ │ ├── VFMaths │ │ │ │ ├── VFColor.c │ │ │ │ ├── VFColor.h │ │ │ │ ├── VFMath.h │ │ │ │ ├── VFMathTypes.h │ │ │ │ ├── VFMatrix.c │ │ │ │ ├── VFMatrix.h │ │ │ │ ├── VFVector.c │ │ │ │ └── VFVector.h │ │ │ ├── VFVertexDatasManager.h │ │ │ └── VFVertexDatasManager.m │ │ ├── Render │ │ │ ├── VFFrameBufferManager.h │ │ │ ├── VFFrameBufferManager.m │ │ │ ├── VFRenderBufferManager.h │ │ │ ├── VFRenderBufferManager.m │ │ │ ├── VFRenderContext.h │ │ │ ├── VFRenderContext.m │ │ │ ├── VFRenderWindow.h │ │ │ └── VFRenderWindow.m │ │ └── Shader │ │ │ ├── VFFragmentShader.glsl │ │ │ ├── VFShaderManager.h │ │ │ ├── VFShaderManager.m │ │ │ ├── VFShaderValueInfo.h │ │ │ ├── VFShaderValueInfo.m │ │ │ ├── VFShaderValueRexAnalyzer.h │ │ │ ├── VFShaderValueRexAnalyzer.m │ │ │ └── VFVertexShader.glsl │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── DrawGeometries_Lines │ ├── DrawGeometries_Lines.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── DrawGeometries_Lines │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Classes │ │ ├── Common │ │ │ ├── VFCommon.h │ │ │ ├── VFFreeSource.h │ │ │ ├── VFHandleError.h │ │ │ ├── VFOpenGLES2XHeader.h │ │ │ └── VFShaderValueLocation.h │ │ ├── Datas │ │ │ ├── VFBEZ3DPoints.h │ │ │ ├── VFBaseGeometricVertexData.h │ │ │ ├── VFMaths │ │ │ │ ├── VFColor.c │ │ │ │ ├── VFColor.h │ │ │ │ ├── VFMath.h │ │ │ │ ├── VFMathTypes.h │ │ │ │ ├── VFMatrix.c │ │ │ │ ├── VFMatrix.h │ │ │ │ ├── VFVector.c │ │ │ │ └── VFVector.h │ │ │ ├── VFRound.h │ │ │ ├── VFVertexDatasManager.h │ │ │ └── VFVertexDatasManager.m │ │ ├── Render │ │ │ ├── VFFrameBufferManager.h │ │ │ ├── VFFrameBufferManager.m │ │ │ ├── VFRenderBufferManager.h │ │ │ ├── VFRenderBufferManager.m │ │ │ ├── VFRenderContext.h │ │ │ ├── VFRenderContext.m │ │ │ ├── VFRenderWindow.h │ │ │ └── VFRenderWindow.m │ │ └── Shader │ │ │ ├── VFFragmentShader.glsl │ │ │ ├── VFShaderManager.h │ │ │ ├── VFShaderManager.m │ │ │ ├── VFShaderValueInfo.h │ │ │ ├── VFShaderValueInfo.m │ │ │ ├── VFShaderValueRexAnalyzer.h │ │ │ ├── VFShaderValueRexAnalyzer.m │ │ │ └── VFVertexShader.glsl │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── DrawGeometries_Triangles │ ├── DrawGeometries_Triangles.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── DrawGeometries_Triangles │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Classes │ │ ├── Common │ │ │ ├── VFCommon.h │ │ │ ├── VFFreeSource.h │ │ │ ├── VFHandleError.h │ │ │ ├── VFOpenGLES2XHeader.h │ │ │ └── VFShaderValueLocation.h │ │ ├── Datas │ │ │ ├── VFBaseGeometricVertexData.h │ │ │ ├── VFMaths │ │ │ │ ├── VFColor.c │ │ │ │ ├── VFColor.h │ │ │ │ ├── VFMath.h │ │ │ │ ├── VFMathTypes.h │ │ │ │ ├── VFMatrix.c │ │ │ │ ├── VFMatrix.h │ │ │ │ ├── VFVector.c │ │ │ │ └── VFVector.h │ │ │ ├── VFRound.h │ │ │ ├── VFVertexDatasManager.h │ │ │ └── VFVertexDatasManager.m │ │ ├── Render │ │ │ ├── VFFrameBufferManager.h │ │ │ ├── VFFrameBufferManager.m │ │ │ ├── VFRenderBufferManager.h │ │ │ ├── VFRenderBufferManager.m │ │ │ ├── VFRenderContext.h │ │ │ ├── VFRenderContext.m │ │ │ ├── VFRenderWindow.h │ │ │ └── VFRenderWindow.m │ │ └── Shader │ │ │ ├── VFFragmentShader.glsl │ │ │ ├── VFShaderManager.h │ │ │ ├── VFShaderManager.m │ │ │ ├── VFShaderValueInfo.h │ │ │ ├── VFShaderValueInfo.m │ │ │ ├── VFShaderValueRexAnalyzer.h │ │ │ ├── VFShaderValueRexAnalyzer.m │ │ │ └── VFVertexShader.glsl │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── UIs │ ├── DrawGeometries_Points │ │ ├── DrawGeometries_Points.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ └── DrawGeometries_Points │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ │ ├── Classes │ │ │ ├── Common │ │ │ │ ├── NSValue+Struct2Value.h │ │ │ │ ├── NSValue+Struct2Value.m │ │ │ │ ├── VFCommon.h │ │ │ │ ├── VFFreeSource.h │ │ │ │ ├── VFHandleError.h │ │ │ │ ├── VFOpenGLES2XHeader.h │ │ │ │ ├── VFShaderValueLocation.h │ │ │ │ └── VFVertex.h │ │ │ ├── Datas │ │ │ │ ├── Models │ │ │ │ │ ├── VFAttachVertexInfo.h │ │ │ │ │ ├── VFAttachVertexInfo.m │ │ │ │ │ ├── VFDrawInfo.h │ │ │ │ │ ├── VFDrawInfo.m │ │ │ │ │ ├── VFVBODataStoredInfo.h │ │ │ │ │ └── VFVBODataStoredInfo.m │ │ │ │ ├── VFBaseGeometricVertexData.h │ │ │ │ ├── VFGeometriesPoints.h │ │ │ │ ├── VFMaths │ │ │ │ │ ├── VFColor.c │ │ │ │ │ ├── VFColor.h │ │ │ │ │ ├── VFMath.h │ │ │ │ │ ├── VFMathTypes.h │ │ │ │ │ ├── VFMatrix.c │ │ │ │ │ ├── VFMatrix.h │ │ │ │ │ ├── VFVector.c │ │ │ │ │ └── VFVector.h │ │ │ │ ├── VFVertexDatasManager.h │ │ │ │ └── VFVertexDatasManager.m │ │ │ ├── Render │ │ │ │ ├── VFFrameBufferManager.h │ │ │ │ ├── VFFrameBufferManager.m │ │ │ │ ├── VFRenderBufferManager.h │ │ │ │ ├── VFRenderBufferManager.m │ │ │ │ ├── VFRenderContext.h │ │ │ │ ├── VFRenderContext.m │ │ │ │ ├── VFRenderWindow.h │ │ │ │ └── VFRenderWindow.m │ │ │ └── Shader │ │ │ │ ├── VFFragmentShader.glsl │ │ │ │ ├── VFShaderManager.h │ │ │ │ ├── VFShaderManager.m │ │ │ │ ├── VFShaderValueInfo.h │ │ │ │ ├── VFShaderValueInfo.m │ │ │ │ ├── VFShaderValueRexAnalyzer.h │ │ │ │ ├── VFShaderValueRexAnalyzer.m │ │ │ │ └── VFVertexShader.glsl │ │ │ ├── Info.plist │ │ │ ├── ViewController.h │ │ │ ├── ViewController.m │ │ │ └── main.m │ └── Geometries.sketch └── VFDynamicCalculateGeoPoints │ ├── VFDynamicCalculateGeoPoints.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── VFDynamicCalculateGeoPoints │ ├── BEZ3DPoints.h │ ├── Points.h │ ├── VFBezierCurve.h │ ├── VFBezierCurve.m │ ├── VFCalculatePoints.h │ ├── VFCalculatePoints.m │ └── main.m ├── 04-Draw3DGeometries ├── DrawCube │ ├── DrawCube.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── DrawCube │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── VFGLCubeView.h │ │ ├── VFGLCubeView.m │ │ ├── VFRedisplay.h │ │ ├── VFRedisplay.m │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── DrawCube_Camera │ ├── DrawCube_Camera.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── DrawCube_Camera │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Class │ │ ├── Display │ │ │ ├── VFRedisplay.h │ │ │ └── VFRedisplay.m │ │ ├── Shader │ │ │ ├── FragmentShader.glsl │ │ │ └── VertexShader.glsl │ │ ├── VFDrawCubeView.h │ │ └── VFDrawCubeView.m │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── DrawCube_OneStep │ ├── DrawCube_OneStep.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── DrawCube_OneStep │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Class │ │ ├── Display │ │ │ ├── VFRedisplay.h │ │ │ └── VFRedisplay.m │ │ ├── Shader │ │ │ ├── FragmentShader.glsl │ │ │ └── VertexShader.glsl │ │ ├── VFDrawCubeView.h │ │ └── VFDrawCubeView.m │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m └── DrawSquare_3DFix │ ├── DrawSquare_3DFix.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── DrawSquare_3DFix │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── VFGLSquareView.h │ ├── VFGLSquareView.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 05Texture X821 ├── SketchFiles │ └── TextureSource.sketch ├── Texture-Base-OneStep │ ├── Texture-Base-OneStep.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── Texture-Base-OneStep │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Classes │ │ ├── Commom │ │ │ ├── VYDisplayLoop.h │ │ │ ├── VYDisplayLoop.m │ │ │ ├── VYLoadTextureImage.h │ │ │ ├── VYLoadTextureImage.m │ │ │ ├── VYTransforms.h │ │ │ └── VYTransforms.m │ │ ├── Datas │ │ │ └── TextureDatas.h │ │ ├── MainClass │ │ │ ├── VYTextureView.h │ │ │ └── VYTextureView.m │ │ ├── Shader │ │ │ ├── VYTex2DFragmentShader.glsl │ │ │ ├── VYTex2DVertexShader.glsl │ │ │ ├── VYTexCubemapFragmentShader.glsl │ │ │ └── VYTexCubemapVertexShader.glsl │ │ └── TextureSources │ │ │ ├── 128_128.png │ │ │ ├── 2DCubeElong │ │ │ ├── HDR湖泊.png │ │ │ ├── L_768_512.png │ │ │ └── Rubik's cube.png │ │ │ ├── 512_512.png │ │ │ └── Cubemap │ │ │ ├── 512_512_01.png │ │ │ ├── 512_512_02.png │ │ │ ├── 512_512_03.png │ │ │ ├── 512_512_04.png │ │ │ ├── 512_512_05.png │ │ │ └── 512_512_06.png │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── Texture-Depth-BiuBiuBiu │ ├── Texture-Depth-BiuBiuBiu.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ └── Texture-Depth-BiuBiuBiu │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Classes │ │ ├── Commom │ │ │ ├── VYDisplayLoop.h │ │ │ ├── VYDisplayLoop.m │ │ │ ├── VYLoadTextureImage.h │ │ │ ├── VYLoadTextureImage.m │ │ │ ├── VYTransforms.h │ │ │ └── VYTransforms.m │ │ ├── Datas │ │ │ └── TextureDatas.h │ │ ├── MainClass │ │ │ ├── VYTextureView.h │ │ │ └── VYTextureView.m │ │ ├── Shader │ │ │ ├── VYTex2DFragmentShader.glsl │ │ │ ├── VYTex2DVertexShader.glsl │ │ │ ├── VYTexCubemapFragmentShader.glsl │ │ │ └── VYTexCubemapVertexShader.glsl │ │ └── TextureSources │ │ │ ├── 128_128.png │ │ │ ├── 2DCubeElong │ │ │ ├── HDR湖泊.png │ │ │ ├── L_768_512.png │ │ │ └── Rubik's cube.png │ │ │ ├── 512_512.png │ │ │ └── Cubemap │ │ │ ├── 512_512_01.png │ │ │ ├── 512_512_02.png │ │ │ ├── 512_512_03.png │ │ │ ├── 512_512_04.png │ │ │ ├── 512_512_05.png │ │ │ └── 512_512_06.png │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m └── Texture-OneStep-Starter │ ├── Texture-OneStep-Starter.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── Texture-OneStep-Starter │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Classes │ ├── Commom │ │ ├── VYTransforms.h │ │ └── VYTransforms.m │ ├── Datas │ │ └── TextureDatas.h │ ├── MainClass │ │ ├── VYTextureView.h │ │ └── VYTextureView.m │ └── Shader │ │ ├── VYTex2DFragmentShader.glsl │ │ ├── VYTex2DVertexShader.glsl │ │ ├── VYTexCubemapFragmentShader.glsl │ │ └── VYTexCubemapVertexShader.glsl │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Common/VFFreeSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFreeSource.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFFreeSource_h 10 | #define VFFreeSource_h 11 | 12 | @protocol OpenGLESFreeSource 13 | 14 | - (void)releaseSource; 15 | 16 | @end 17 | 18 | #endif /* VFFreeSource_h */ 19 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Common/VFOpenGLES2XHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFOpenGLES2XHeader.h 3 | // DrawPoint 4 | // 5 | // Created by windy on 16/10/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFOpenGLES2XHeader_h 10 | #define VFOpenGLES2XHeader_h 11 | 12 | #ifdef __OBJC__ // GL_ES_VERSION_2_0 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #endif 19 | 20 | #endif /* VFOpenGLES2XHeader_h */ 21 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Datas/VFBaseGeometricVertexData.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFBaseGeometricVertexData.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFBaseGeometricVertexData_h 10 | #define VFBaseGeometricVertexData_h 11 | 12 | // Base Triangle 13 | static const VFVertex vertices[] = { 14 | {{-0.5f, -0.5f, 0.0}}, // lower left corner 15 | {{ 0.5f, -0.5f, 0.0}}, // lower right corner 16 | {{-0.5f, 0.5f, 0.0}}, // upper left corner 17 | }; 18 | 19 | #endif /* VFBaseGeometricVertexData_h */ 20 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Datas/VFVertexDatasManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertexDatasManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | typedef NS_ENUM(NSUInteger, VFVertexDataMode) { 13 | 14 | VFVertexDataMode_VAOs = 0, 15 | VFVertexDataMode_VBOs, 16 | 17 | }; 18 | 19 | @interface VFVertexDatasManager : NSObject 20 | /** 21 | * 顶点数据的加载方式 22 | */ 23 | @property (assign, nonatomic) VFVertexDataMode vertexDataMode; 24 | 25 | /** 26 | * 默认的顶点数据管理者 27 | */ 28 | + (instancetype)defaultVertexManager; 29 | 30 | /** 31 | * 装载数据 32 | */ 33 | - (void)attachVertexDatas; 34 | 35 | /** 36 | * 绘制图形 37 | */ 38 | - (void)draw; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/ErrorHandle/VFErrorHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFErrorHandler.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFErrorUnitis.h" 11 | 12 | @interface VFErrorHandler : NSObject 13 | 14 | /** 15 | * 默认的错误处理器 16 | */ 17 | + (instancetype)defaultErrorHandler; 18 | 19 | /** 20 | * 处理错误 21 | * 22 | * @param errorType 错误类型 23 | */ 24 | - (void)handleErrorWithErrorType:(VFErrorType)errorType; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/ErrorHandle/VFErrorHandler.m: -------------------------------------------------------------------------------- 1 | // 2 | // VFErrorHandler.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFErrorHandler.h" 10 | 11 | @implementation VFErrorHandler 12 | 13 | #pragma mark - 14 | #pragma mark Pbulic: 15 | #pragma mark - 16 | 17 | /** 18 | * 默认的错误处理器 19 | */ 20 | + (instancetype)defaultErrorHandler { 21 | 22 | static dispatch_once_t onceToken; 23 | static VFErrorHandler * defaultHandler; 24 | dispatch_once(&onceToken, ^{ 25 | defaultHandler = [[[self class] alloc] init]; 26 | }); 27 | 28 | return defaultHandler; 29 | 30 | } 31 | 32 | /** 33 | * 处理错误 34 | * 35 | * @param errorType 错误类型 36 | */ 37 | - (void)handleErrorWithErrorType:(VFErrorType)errorType { 38 | 39 | switch (errorType) { 40 | case VFErrorType_RBOIdentifier: { 41 | [self handleRenderBufferObjectIDError]; 42 | break; 43 | } 44 | case VFErrorType_FBOIdentifier: { 45 | [self handleFrameBufferObjectIDError]; 46 | break; 47 | } 48 | } 49 | 50 | [self exit]; 51 | 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark Private: 56 | #pragma mark - 57 | 58 | /** 59 | * 退出程序 60 | */ 61 | - (void)exit { 62 | 63 | exit(1); 64 | 65 | } 66 | 67 | /** 68 | * 处理 RBO 内存分配失败 69 | */ 70 | - (void)handleRenderBufferObjectIDError { 71 | 72 | 73 | 74 | } 75 | 76 | /** 77 | * 处理 FBO 内存分配失败 78 | */ 79 | - (void)handleFrameBufferObjectIDError { 80 | 81 | 82 | 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/ErrorHandle/VFErrorUnitis.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFErrorUnitis.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFErrorUnitis_h 10 | #define VFErrorUnitis_h 11 | 12 | typedef NS_ENUM(NSUInteger, VFErrorType) { 13 | 14 | VFErrorType_RBOIdentifier = 0, 15 | VFErrorType_FBOIdentifier, 16 | 17 | }; 18 | 19 | #endif /* VFErrorUnitis_h */ 20 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Render/VFFrameBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFrameBufferManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFFrameBufferManager : NSObject 13 | 14 | // 当前活跃的帧缓存的标识 15 | @property (assign, nonatomic, readonly) GLuint currentFBOIdentifier; 16 | 17 | /** 18 | * 默认的帧缓存对象管理者 19 | */ 20 | + (instancetype)defaultFrameManager; 21 | 22 | /** 23 | * 创建 FBO 24 | */ 25 | - (void)createFrameBufferObject; 26 | 27 | /** 28 | * 使用 FBO 29 | */ 30 | - (void)useFrameBufferObject; 31 | 32 | /** 33 | * 删除 FBO 34 | */ 35 | - (void)deleteFrameBufferObject; 36 | 37 | /** 38 | * 装载 Render Buffer 的内容到 Frame Buffer 内 39 | */ 40 | - (void)attachRenderBufferToFrameBuffer:(GLuint)renderBufferObjcetID; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Render/VFRenderBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderBufferManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFRenderBufferManager : NSObject 13 | // 当前活跃的渲染缓存的标识 14 | @property (assign, nonatomic, readonly) GLuint currentRBOIdentifier; 15 | 16 | /** 17 | * 默认的渲染缓存对象管理者 18 | */ 19 | + (instancetype)defaultRenderManager; 20 | 21 | /** 22 | * 创建 RBO 23 | */ 24 | - (void)createRenderBufferObject; 25 | 26 | /** 27 | * 使用 RBO 28 | */ 29 | - (void)useRenderBufferObject; 30 | 31 | /** 32 | * 删除 RBO 33 | */ 34 | - (void)deleteRenderBufferObject; 35 | 36 | /** 37 | * 渲染缓存的尺寸 38 | */ 39 | - (CGSize)renderBufferSize; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Render/VFRenderContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFCommon.h" 10 | 11 | @interface VFRenderContext : EAGLContext 12 | 13 | /** 14 | * 绑定进行渲染的窗口 15 | * 16 | * @param deawableLayer 渲染的窗口 17 | */ 18 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer; 19 | 20 | /** 21 | * 设置渲染窗口的背景色 22 | * 23 | * @param color RGBA 颜色值 24 | */ 25 | - (void)setRenderBackgroundColor:(RGBAColor)color; 26 | 27 | /** 28 | * 重置(清空)渲染内存 29 | */ 30 | - (void)clearRenderBuffer; 31 | 32 | /** 33 | * 设置视窗 34 | */ 35 | - (void)setRenderViewPortWithCGRect:(CGRect)rect; 36 | 37 | /** 38 | * 开始渲染 39 | */ 40 | - (void)render; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Render/VFRenderContext.m: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFRenderContext.h" 10 | 11 | @implementation VFRenderContext 12 | 13 | #pragma mark - 14 | #pragma mark Public: 15 | #pragma mark - 16 | 17 | #pragma mark Drawable 18 | 19 | /** 20 | * 绑定进行渲染的窗口 21 | * 22 | * @param drawableLayer 渲染的窗口 23 | */ 24 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer { 25 | 26 | if ( ! [drawableLayer isKindOfClass:[CAEAGLLayer class]] ) { 27 | return; 28 | } 29 | 30 | [self renderbufferStorage:GL_RENDERBUFFER fromDrawable:drawableLayer]; 31 | 32 | } 33 | 34 | #pragma mark - Clear 35 | 36 | /** 37 | * 设置渲染窗口的背景色 38 | * 39 | * @param color RGBA 颜色值 40 | */ 41 | - (void)setRenderBackgroundColor:(RGBAColor)color { 42 | 43 | glClearColor(color.red, color.green, color.blue, color.alpha); 44 | 45 | } 46 | 47 | /** 48 | * 重置(清空)渲染内存 49 | */ 50 | - (void)clearRenderBuffer { 51 | 52 | glClear(GL_COLOR_BUFFER_BIT); 53 | 54 | } 55 | 56 | #pragma mark - View Port 57 | 58 | /** 59 | * 设置视窗 60 | */ 61 | - (void)setRenderViewPortWithCGRect:(CGRect)rect { 62 | 63 | glViewport(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); 64 | 65 | } 66 | 67 | #pragma mark - Render 68 | 69 | /** 70 | * 开始渲染 71 | */ 72 | - (void)render { 73 | 74 | [self presentRenderbuffer:GL_RENDERBUFFER]; 75 | 76 | } 77 | 78 | #pragma mark - 79 | #pragma mark Private: 80 | #pragma mark - 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Render/VFRenderWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderWindow.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFRenderContext.h" 11 | 12 | @interface VFRenderWindow : UIView 13 | 14 | /** 15 | * 返回当前活跃的渲染上下文 16 | * 17 | * @return VFRenderContext 继承于 EAGLContext 18 | */ 19 | - (VFRenderContext *)currentContext; 20 | 21 | /** 22 | * 显示前,准备顶点数据、着色器等 23 | */ 24 | - (void)prepareDisplay; 25 | 26 | /** 27 | * 显示图形 28 | */ 29 | - (void)display; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Shader/VFFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | void main(void) { 5 | gl_FragColor = vec4(1, 1, 1, 1); 6 | } -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Shader/VFShaderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFShaderManager : NSObject 13 | 14 | /** 15 | * 默认的着色器管理者 16 | */ 17 | + (instancetype)defaultShaderManager; 18 | 19 | /** 20 | * 装载着色器 21 | * 22 | * @param vertexStringFileName 顶点着色器代码文件 23 | * @param fragmentStringFileName 片元着色器代码文件 24 | */ 25 | - (void)attachVertexShader:(NSString *)vertexStringFileName fragmentShader:(NSString *)fragmentStringFileName; 26 | 27 | /** 28 | * 使用着色器 29 | */ 30 | - (void)useShader; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/Classes/Shader/VFVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | attribute vec4 v_Position; 5 | 6 | void main(void) { 7 | gl_Position = v_Position; 8 | } -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFRenderWindow.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | VFRenderWindow *renderWindow = [[VFRenderWindow alloc] initWithFrame:self.view.bounds]; 24 | [renderWindow prepareDisplay]; 25 | 26 | [self.view addSubview:renderWindow]; 27 | [renderWindow display]; 28 | 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP/DrawTriangle_OOP/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Common/VFFreeSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFreeSource.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFFreeSource_h 10 | #define VFFreeSource_h 11 | 12 | @protocol OpenGLESFreeSource 13 | 14 | - (void)releaseSource; 15 | 16 | @end 17 | 18 | #endif /* VFFreeSource_h */ 19 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Common/VFOpenGLES2XHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFOpenGLES2XHeader.h 3 | // DrawPoint 4 | // 5 | // Created by windy on 16/10/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFOpenGLES2XHeader_h 10 | #define VFOpenGLES2XHeader_h 11 | 12 | #ifdef __OBJC__ // GL_ES_VERSION_2_0 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #endif 19 | 20 | #endif /* VFOpenGLES2XHeader_h */ 21 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Datas/VFVertexDatasManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertexDatasManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | typedef NS_ENUM(NSUInteger, VFVertexDataMode) { 13 | 14 | VFVertexDataMode_CVOs = 0, 15 | VFVertexDataMode_VAOs, 16 | VFVertexDataMode_VBOs, 17 | 18 | }; 19 | 20 | @interface VFVertexDatasManager : NSObject 21 | /** 22 | * 顶点数据的加载方式 23 | */ 24 | @property (assign, nonatomic) VFVertexDataMode vertexDataMode; 25 | 26 | /** 27 | * 默认的顶点数据管理者 28 | */ 29 | + (instancetype)defaultVertexManager; 30 | 31 | /** 32 | * 装载数据 33 | */ 34 | - (void)attachVertexDatas; 35 | 36 | /** 37 | * 绘制图形 38 | */ 39 | - (void)draw; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/ErrorHandle/VFErrorHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFErrorHandler.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFErrorUnitis.h" 11 | 12 | @interface VFErrorHandler : NSObject 13 | 14 | /** 15 | * 默认的错误处理器 16 | */ 17 | + (instancetype)defaultErrorHandler; 18 | 19 | /** 20 | * 处理错误 21 | * 22 | * @param errorType 错误类型 23 | */ 24 | - (void)handleErrorWithErrorType:(VFErrorType)errorType; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/ErrorHandle/VFErrorHandler.m: -------------------------------------------------------------------------------- 1 | // 2 | // VFErrorHandler.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFErrorHandler.h" 10 | 11 | @implementation VFErrorHandler 12 | 13 | #pragma mark - 14 | #pragma mark Pbulic: 15 | #pragma mark - 16 | 17 | /** 18 | * 默认的错误处理器 19 | */ 20 | + (instancetype)defaultErrorHandler { 21 | 22 | static dispatch_once_t onceToken; 23 | static VFErrorHandler * defaultHandler; 24 | dispatch_once(&onceToken, ^{ 25 | defaultHandler = [[[self class] alloc] init]; 26 | }); 27 | 28 | return defaultHandler; 29 | 30 | } 31 | 32 | /** 33 | * 处理错误 34 | * 35 | * @param errorType 错误类型 36 | */ 37 | - (void)handleErrorWithErrorType:(VFErrorType)errorType { 38 | 39 | switch (errorType) { 40 | case VFErrorType_RBOIdentifier: { 41 | [self handleRenderBufferObjectIDError]; 42 | break; 43 | } 44 | case VFErrorType_FBOIdentifier: { 45 | [self handleFrameBufferObjectIDError]; 46 | break; 47 | } 48 | } 49 | 50 | [self exit]; 51 | 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark Private: 56 | #pragma mark - 57 | 58 | /** 59 | * 退出程序 60 | */ 61 | - (void)exit { 62 | 63 | exit(1); 64 | 65 | } 66 | 67 | /** 68 | * 处理 RBO 内存分配失败 69 | */ 70 | - (void)handleRenderBufferObjectIDError { 71 | 72 | 73 | 74 | } 75 | 76 | /** 77 | * 处理 FBO 内存分配失败 78 | */ 79 | - (void)handleFrameBufferObjectIDError { 80 | 81 | 82 | 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/ErrorHandle/VFErrorUnitis.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFErrorUnitis.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFErrorUnitis_h 10 | #define VFErrorUnitis_h 11 | 12 | typedef NS_ENUM(NSUInteger, VFErrorType) { 13 | 14 | VFErrorType_RBOIdentifier = 0, 15 | VFErrorType_FBOIdentifier, 16 | 17 | }; 18 | 19 | #endif /* VFErrorUnitis_h */ 20 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Render/VFFrameBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFrameBufferManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFFrameBufferManager : NSObject 13 | 14 | // 当前活跃的帧缓存的标识 15 | @property (assign, nonatomic, readonly) GLuint currentFBOIdentifier; 16 | 17 | /** 18 | * 默认的帧缓存对象管理者 19 | */ 20 | + (instancetype)defaultFrameManager; 21 | 22 | /** 23 | * 创建 FBO 24 | */ 25 | - (void)createFrameBufferObject; 26 | 27 | /** 28 | * 使用 FBO 29 | */ 30 | - (void)useFrameBufferObject; 31 | 32 | /** 33 | * 删除 FBO 34 | */ 35 | - (void)deleteFrameBufferObject; 36 | 37 | /** 38 | * 装载 Render Buffer 的内容到 Frame Buffer 内 39 | */ 40 | - (void)attachRenderBufferToFrameBuffer:(GLuint)renderBufferObjcetID; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Render/VFRenderBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderBufferManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFRenderBufferManager : NSObject 13 | // 当前活跃的渲染缓存的标识 14 | @property (assign, nonatomic, readonly) GLuint currentRBOIdentifier; 15 | 16 | /** 17 | * 默认的渲染缓存对象管理者 18 | */ 19 | + (instancetype)defaultRenderManager; 20 | 21 | /** 22 | * 创建 RBO 23 | */ 24 | - (void)createRenderBufferObject; 25 | 26 | /** 27 | * 使用 RBO 28 | */ 29 | - (void)useRenderBufferObject; 30 | 31 | /** 32 | * 删除 RBO 33 | */ 34 | - (void)deleteRenderBufferObject; 35 | 36 | /** 37 | * 渲染缓存的尺寸 38 | */ 39 | - (CGSize)renderBufferSize; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Render/VFRenderContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFCommon.h" 10 | 11 | @interface VFRenderContext : EAGLContext 12 | 13 | /** 14 | * 绑定进行渲染的窗口 15 | * 16 | * @param deawableLayer 渲染的窗口 17 | */ 18 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer; 19 | 20 | /** 21 | * 设置渲染窗口的背景色 22 | * 23 | * @param color RGBA 颜色值 24 | */ 25 | - (void)setRenderBackgroundColor:(RGBAColor)color; 26 | 27 | /** 28 | * 重置(清空)渲染内存 29 | */ 30 | - (void)clearRenderBuffer; 31 | 32 | /** 33 | * 设置视窗 34 | */ 35 | - (void)setRenderViewPortWithCGRect:(CGRect)rect; 36 | 37 | /** 38 | * 开始渲染 39 | */ 40 | - (void)render; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Render/VFRenderContext.m: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFRenderContext.h" 10 | 11 | @implementation VFRenderContext 12 | 13 | #pragma mark - 14 | #pragma mark Public: 15 | #pragma mark - 16 | 17 | #pragma mark Drawable 18 | 19 | /** 20 | * 绑定进行渲染的窗口 21 | * 22 | * @param drawableLayer 渲染的窗口 23 | */ 24 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer { 25 | 26 | if ( ! [drawableLayer isKindOfClass:[CAEAGLLayer class]] ) { 27 | return; 28 | } 29 | 30 | [self renderbufferStorage:GL_RENDERBUFFER fromDrawable:drawableLayer]; 31 | 32 | } 33 | 34 | #pragma mark - Clear 35 | 36 | /** 37 | * 设置渲染窗口的背景色 38 | * 39 | * @param color RGBA 颜色值 40 | */ 41 | - (void)setRenderBackgroundColor:(RGBAColor)color { 42 | 43 | glClearColor(color.red, color.green, color.blue, color.alpha); 44 | 45 | } 46 | 47 | /** 48 | * 重置(清空)渲染内存 49 | */ 50 | - (void)clearRenderBuffer { 51 | 52 | glClear(GL_COLOR_BUFFER_BIT); 53 | 54 | } 55 | 56 | #pragma mark - View Port 57 | 58 | /** 59 | * 设置视窗 60 | */ 61 | - (void)setRenderViewPortWithCGRect:(CGRect)rect { 62 | 63 | glViewport(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); 64 | 65 | } 66 | 67 | #pragma mark - Render 68 | 69 | /** 70 | * 开始渲染 71 | */ 72 | - (void)render { 73 | 74 | [self presentRenderbuffer:GL_RENDERBUFFER]; 75 | 76 | } 77 | 78 | #pragma mark - 79 | #pragma mark Private: 80 | #pragma mark - 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Render/VFRenderWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderWindow.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFRenderContext.h" 11 | 12 | @interface VFRenderWindow : UIView 13 | 14 | /** 15 | * 返回当前活跃的渲染上下文 16 | * 17 | * @return VFRenderContext 继承于 EAGLContext 18 | */ 19 | - (VFRenderContext *)currentContext; 20 | 21 | /** 22 | * 显示前,准备顶点数据、着色器等 23 | */ 24 | - (void)prepareDisplay; 25 | 26 | /** 27 | * 显示图形 28 | */ 29 | - (void)display; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Shader/VFFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | varying mediump vec4 f_color; 5 | 6 | void main(void) { 7 | gl_FragColor = f_color; 8 | } -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Shader/VFShaderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderManager.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFShaderManager : NSObject 13 | 14 | /** 15 | * 默认的着色器管理者 16 | */ 17 | + (instancetype)defaultShaderManager; 18 | 19 | /** 20 | * 装载着色器 21 | * 22 | * @param vertexStringFileName 顶点着色器代码文件 23 | * @param fragmentStringFileName 片元着色器代码文件 24 | */ 25 | - (void)attachVertexShader:(NSString *)vertexStringFileName fragmentShader:(NSString *)fragmentStringFileName; 26 | 27 | /** 28 | * 使用着色器 29 | */ 30 | - (void)useShader; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/Classes/Shader/VFVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | attribute vec4 v_Position; 5 | attribute vec4 v_Color; 6 | 7 | varying mediump vec4 f_color; 8 | 9 | void main(void) { 10 | f_color = v_Color; 11 | gl_Position = v_Position; 12 | } -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFRenderWindow.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | VFRenderWindow *renderWindow = [[VFRenderWindow alloc] initWithFrame:self.view.bounds]; 24 | [renderWindow prepareDisplay]; 25 | 26 | [self.view addSubview:renderWindow]; 27 | [renderWindow display]; 28 | 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawTriangle_OOP 4 | // 5 | // Created by windy on 16/10/30. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OOP_Challenges/DrawTriangle_OOP_Challenges_1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OneStep/DrawTriangle_OneStep.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OneStep/DrawTriangle_OneStep/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OneStep/DrawTriangle_OneStep/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OneStep/DrawTriangle_OneStep/VFGLTriangleView.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFGLTriangleView.h 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, VertexDataMode) { 12 | VertexDataMode_VAO = 0, 13 | VertexDataMode_VBO, 14 | }; 15 | 16 | @interface VFGLTriangleView : UIView 17 | 18 | - (void)setVertexMode:(VertexDataMode)vertexMode; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OneStep/DrawTriangle_OneStep/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OneStep/DrawTriangle_OneStep/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFGLTriangleView.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | CGRect rect = CGRectOffset(self.view.frame, 0, 0); 24 | // CGRect rect = CGRectOffset(self.view.frame, 10, 20); 25 | // CGRect rect = CGRectMake(10, 20, CGRectGetWidth(self.view.frame) / 2, CGRectGetHeight(self.view.frame) / 2); 26 | VFGLTriangleView *glView = [[VFGLTriangleView alloc] initWithFrame:rect]; 27 | [glView setVertexMode:VertexDataMode_VBO]; 28 | 29 | [self.view addSubview:glView]; 30 | 31 | } 32 | 33 | - (void)didReceiveMemoryWarning { 34 | [super didReceiveMemoryWarning]; 35 | // Dispose of any resources that can be recreated. 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /01-DrawTriangle/DrawTriangle_OneStep/DrawTriangle_OneStep/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/10. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Common/VFFreeSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFreeSource.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFFreeSource_h 10 | #define VFFreeSource_h 11 | 12 | @protocol OpenGLESFreeSource 13 | 14 | - (void)releaseSource; 15 | 16 | @end 17 | 18 | #endif /* VFFreeSource_h */ 19 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Common/VFOpenGLES2XHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFOpenGLES2XHeader.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFOpenGLES2XHeader_h 10 | #define VFOpenGLES2XHeader_h 11 | 12 | #ifdef __OBJC__ // GL_ES_VERSION_2_0 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #endif 19 | 20 | #endif /* VFOpenGLES2XHeader_h */ 21 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Common/VFShaderValueLocation.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueLocation.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/11. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFShaderValueLocation_h 10 | #define VFShaderValueLocation_h 11 | 12 | /* Info Key */ 13 | static NSString * POSITION_STRING_KEY = @"Position"; 14 | static NSString * COLOR_STRING_KEY = @"Color"; 15 | static NSString * NORMAL_STRING_KEY = @"Normal"; 16 | static NSString * TEXTURE0_STRING_KEY = @"Texture0"; 17 | 18 | typedef enum { 19 | 20 | VFVertexPositionAttribute = 0, 21 | VFVertexColorAttribute, 22 | 23 | } VFVertexAttribute; 24 | 25 | #endif /* VFShaderValueLocation_h */ 26 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Datas/VFMaths/VFColor.c: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.c 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #include "VFColor.h" 10 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Datas/VFMaths/VFColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFColor_h 10 | #define VFColor_h 11 | 12 | #include 13 | 14 | #endif /* VFColor_h */ 15 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Datas/VFMaths/VFMath.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFMath.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | //#pragma once 10 | 11 | #ifndef VFMath_h 12 | #define VFMath_h 13 | 14 | #include "VFMathTypes.h" 15 | 16 | #include "VFMatrix.h" 17 | #include "VFVector.h" 18 | #include "VFColor.h" 19 | 20 | #endif /* VFMath_h */ 21 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Datas/VFVertexDatasManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertexDatasManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | typedef NS_ENUM(NSUInteger, VFVertexDataMode) { 13 | 14 | VFVertexDataMode_CVOs = 0, 15 | VFVertexDataMode_VAOs, 16 | VFVertexDataMode_VBOs, 17 | 18 | }; 19 | 20 | @interface VFVertexDatasManager : NSObject 21 | 22 | /** 23 | * 默认的顶点数据管理者 24 | */ 25 | + (instancetype)defaultVertexManager; 26 | 27 | /** 28 | * 缩放使当前渲染内容适应当前显示屏幕 29 | */ 30 | - (void)makeScaleToFitCurrentWindowWithScale:(float)scale; 31 | 32 | /** 33 | * 装载数据 34 | */ 35 | - (void)attachVertexDatas; 36 | 37 | /** 38 | * 绘制图形 39 | */ 40 | - (void)draw; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Render/VFFrameBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFrameBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFFrameBufferManager : NSObject 13 | 14 | // 当前活跃的帧缓存的标识 15 | @property (assign, nonatomic, readonly) GLuint currentFBOIdentifier; 16 | 17 | /** 18 | * 默认的帧缓存对象管理者 19 | */ 20 | + (instancetype)defaultFrameManager; 21 | 22 | /** 23 | * 创建 FBO 24 | */ 25 | - (void)createFrameBufferObject; 26 | 27 | /** 28 | * 使用 FBO 29 | */ 30 | - (void)useFrameBufferObject; 31 | 32 | /** 33 | * 删除 FBO 34 | */ 35 | - (void)deleteFrameBufferObject; 36 | 37 | /** 38 | * 装载 Render Buffer 的内容到 Frame Buffer 内 39 | */ 40 | - (void)attachRenderBufferToFrameBuffer:(GLuint)renderBufferObjcetID; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Render/VFRenderBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFRenderBufferManager : NSObject 13 | // 当前活跃的渲染缓存的标识 14 | @property (assign, nonatomic, readonly) GLuint currentRBOIdentifier; 15 | 16 | /** 17 | * 默认的渲染缓存对象管理者 18 | */ 19 | + (instancetype)defaultRenderManager; 20 | 21 | /** 22 | * 创建 RBO 23 | */ 24 | - (void)createRenderBufferObject; 25 | 26 | /** 27 | * 使用 RBO 28 | */ 29 | - (void)useRenderBufferObject; 30 | 31 | /** 32 | * 删除 RBO 33 | */ 34 | - (void)deleteRenderBufferObject; 35 | 36 | /** 37 | * 渲染缓存的尺寸 38 | */ 39 | - (CGSize)renderBufferSize; 40 | 41 | /** 42 | * 当前显示屏幕的像素比 43 | * (因为屏幕 Y 像素 > X 像素, 所以要缩小,不然显示就会向 Y 方向拉伸) 44 | */ 45 | - (CGFloat)windowScaleFactor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Render/VFRenderContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFCommon.h" 10 | 11 | @interface VFRenderContext : EAGLContext 12 | 13 | /** 14 | * 绑定进行渲染的窗口 15 | * 16 | * @param deawableLayer 渲染的窗口 17 | */ 18 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer; 19 | 20 | /** 21 | * 设置渲染窗口的背景色 22 | * 23 | * @param color RGBA 颜色值 24 | */ 25 | - (void)setRenderBackgroundColor:(RGBAColor)color; 26 | 27 | /** 28 | * 重置(清空)渲染内存 29 | */ 30 | - (void)clearRenderBuffer; 31 | 32 | /** 33 | * 设置视窗 34 | */ 35 | - (void)setRenderViewPortWithCGRect:(CGRect)rect; 36 | 37 | /** 38 | * 开始渲染 39 | */ 40 | - (void)render; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Render/VFRenderContext.m: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.m 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFRenderContext.h" 10 | 11 | @implementation VFRenderContext 12 | 13 | #pragma mark - 14 | #pragma mark Public: 15 | #pragma mark - 16 | 17 | #pragma mark Drawable 18 | 19 | /** 20 | * 绑定进行渲染的窗口 21 | * 22 | * @param drawableLayer 渲染的窗口 23 | */ 24 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer { 25 | 26 | if ( ! [drawableLayer isKindOfClass:[CAEAGLLayer class]] ) { 27 | return; 28 | } 29 | 30 | [self renderbufferStorage:GL_RENDERBUFFER fromDrawable:drawableLayer]; 31 | 32 | } 33 | 34 | #pragma mark - Clear 35 | 36 | /** 37 | * 设置渲染窗口的背景色 38 | * 39 | * @param color RGBA 颜色值 40 | */ 41 | - (void)setRenderBackgroundColor:(RGBAColor)color { 42 | 43 | glClearColor(color.red, color.green, color.blue, color.alpha); 44 | 45 | } 46 | 47 | /** 48 | * 重置(清空)渲染内存 49 | */ 50 | - (void)clearRenderBuffer { 51 | 52 | glClear(GL_COLOR_BUFFER_BIT); 53 | 54 | } 55 | 56 | #pragma mark - View Port 57 | 58 | /** 59 | * 设置视窗 60 | */ 61 | - (void)setRenderViewPortWithCGRect:(CGRect)rect { 62 | 63 | glViewport(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); 64 | 65 | } 66 | 67 | #pragma mark - Render 68 | 69 | /** 70 | * 开始渲染 71 | */ 72 | - (void)render { 73 | 74 | [self presentRenderbuffer:GL_RENDERBUFFER]; 75 | 76 | } 77 | 78 | #pragma mark - 79 | #pragma mark Private: 80 | #pragma mark - 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Render/VFRenderWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderWindow.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFRenderContext.h" 11 | 12 | @interface VFRenderWindow : UIView 13 | 14 | /** 15 | * 返回当前活跃的渲染上下文 16 | * 17 | * @return VFRenderContext 继承于 EAGLContext 18 | */ 19 | - (VFRenderContext *)currentContext; 20 | 21 | /** 22 | * 显示前,准备顶点数据、着色器等 23 | */ 24 | - (void)prepareDisplay; 25 | 26 | /** 27 | * 显示图形 28 | */ 29 | - (void)display; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Shader/VFFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | varying mediump vec4 f_color; 5 | 6 | void main(void) { 7 | gl_FragColor = f_color; 8 | } -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Shader/VFShaderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFShaderManager : NSObject 13 | 14 | /** 15 | * 默认的着色器管理者 16 | */ 17 | + (instancetype)defaultShaderManager; 18 | 19 | /** 20 | * 装载着色器 21 | * 22 | * @param vertexStringFileName 顶点着色器代码文件 23 | * @param fragmentStringFileName 片元着色器代码文件 24 | */ 25 | - (void)attachVertexShader:(NSString *)vertexStringFileName fragmentShader:(NSString *)fragmentStringFileName; 26 | 27 | /** 28 | * 使用着色器 29 | */ 30 | - (void)useShader; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Shader/VFShaderValueInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueInfo.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/10. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFShaderValueLocation.h" 11 | 12 | @interface VFShaderValueInfo : NSObject 13 | 14 | /* 变量名 */ 15 | @property (assign, nonatomic) NSString *name; 16 | /* 变量的数据类型 */ 17 | @property (assign, nonatomic) NSString *type; 18 | /* 变量的精度 */ 19 | @property (assign, nonatomic) NSString *precision; 20 | /* 变量的存储类型 */ 21 | @property (assign, nonatomic) NSString *storage; 22 | 23 | /* 变量的内存标识符 */ 24 | @property (assign, nonatomic) NSInteger location; 25 | 26 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type precision:(NSString *)precision storage:(NSString *)storage; 27 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type storage:(NSString *)storage; 28 | 29 | - (NSString *)valueKey; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/Classes/Shader/VFVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | attribute vec4 v_Position; 5 | uniform mat4 v_Projection; 6 | 7 | attribute vec4 v_Color; 8 | varying mediump vec4 f_color; 9 | 10 | void main(void) { 11 | f_color = v_Color; 12 | gl_Position = v_Projection * v_Position; // True, Left Dot Mul 13 | } 14 | 15 | //void main(void) {uniform mat4 v_Translation; 16 | // f_color = v_Color; 17 | // // A · (B · v) === (A · B) · v (A、B is Matrix, v is Vector) 18 | // gl_Position = v_Translation * v_Projection * v_Position; // True, Left Dot Mul 19 | //// gl_Position = v_Projection * v_Translation * v_Position; // True, Left Dot Mul 20 | //// gl_Position = v_Position * v_Projection * v_Translation; // False, Right Dot Mul 21 | //// gl_Position = v_Position * v_Translation * v_Projection; // False, Right Dot Mul 22 | //} -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFRenderWindow.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | VFRenderWindow *renderWindow = [[VFRenderWindow alloc] initWithFrame:self.view.bounds]; 24 | [renderWindow prepareDisplay]; 25 | 26 | [self.view addSubview:renderWindow]; 27 | [renderWindow display]; 28 | 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_Fix/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/10. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_FixTests/DrawTriangle_FixTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // DrawTriangle_FixTests.m 3 | // DrawTriangle_FixTests 4 | // 5 | // Created by windy on 16/11/11. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DrawTriangle_FixTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation DrawTriangle_FixTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /02-DrawTriangle_Fix/DrawTriangle_Fix/DrawTriangle_FixTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /03-DrawGeometries/Beizer/贝塞尔曲线推导.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/03-DrawGeometries/Beizer/贝塞尔曲线推导.docx -------------------------------------------------------------------------------- /03-DrawGeometries/Beizer/贝塞尔曲线推导.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/03-DrawGeometries/Beizer/贝塞尔曲线推导.pdf -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/1. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Common/NSValue+Struct2Value.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+Struct2Value.h 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSValue (Struct2Value) 12 | 13 | // 结构体转换成 NSValue 对象 14 | + (NSValue *)valueObjByStructPtr:(const void *)str objType:(const char * )objType; 15 | // NSValue 转换成 Struct 16 | + (void)structFromValueObj:(NSValue *)value structPtr:(void *)str; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Common/NSValue+Struct2Value.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+Struct2Value.m 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "NSValue+Struct2Value.h" 10 | 11 | @implementation NSValue (Struct2Value) 12 | 13 | #pragma mark - Struct & NSValue 14 | 15 | // 结构体转换成 NSValue 对象 16 | + (NSValue *)valueObjByStructPtr:(const void *)str objType:(const char * )objType { 17 | return [NSValue valueWithBytes:str objCType:objType]; 18 | } 19 | 20 | // NSValue 转换成 Struct 21 | + (void)structFromValueObj:(NSValue *)value structPtr:(void *)str { 22 | [value getValue:str]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Common/VFFreeSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFreeSource.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFFreeSource_h 10 | #define VFFreeSource_h 11 | 12 | @protocol OpenGLESFreeSource 13 | 14 | - (void)releaseSource; 15 | 16 | @end 17 | 18 | #endif /* VFFreeSource_h */ 19 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Common/VFOpenGLES2XHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFOpenGLES2XHeader.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFOpenGLES2XHeader_h 10 | #define VFOpenGLES2XHeader_h 11 | 12 | #ifdef __OBJC__ // GL_ES_VERSION_2_0 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #endif 19 | 20 | #endif /* VFOpenGLES2XHeader_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Common/VFShaderValueLocation.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueLocation.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/11. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFShaderValueLocation_h 10 | #define VFShaderValueLocation_h 11 | 12 | /* Info Key */ 13 | static NSString * POSITION_STRING_KEY = @"Position"; 14 | static NSString * COLOR_STRING_KEY = @"Color"; 15 | static NSString * NORMAL_STRING_KEY = @"Normal"; 16 | static NSString * TEXTURE0_STRING_KEY = @"Texture0"; 17 | 18 | typedef enum { 19 | 20 | VFVertexPositionAttribute = 0, 21 | VFVertexColorAttribute, 22 | 23 | } VFVertexAttribute; 24 | 25 | #endif /* VFShaderValueLocation_h */ 26 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Common/VFVertex.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertex.h 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFVertex_h 10 | #define VFVertex_h 11 | 12 | #import "NSValue+Struct2Value.h" 13 | 14 | #define PositionCoordinateCount (3) 15 | #define NormalCoordinateCount (3) 16 | #define TextureCoordinateCount (2) 17 | 18 | #define ColorCoordinateCount (4) 19 | 20 | #pragma mark - VFVertex 21 | 22 | typedef struct { 23 | 24 | GLfloat Position[PositionCoordinateCount]; // { x, y, z } 25 | GLfloat Color[ColorCoordinateCount]; 26 | 27 | } VFVertex; 28 | 29 | typedef NSValue VFVertexValue; 30 | 31 | static inline VFVertex VFVertexMake(GLfloat Position[PositionCoordinateCount], 32 | GLfloat Color[ColorCoordinateCount]) { 33 | 34 | VFVertex _ver; 35 | for (NSUInteger i = 0; i < PositionCoordinateCount; i++) { 36 | _ver.Position[i] = Position[i]; 37 | } 38 | 39 | for (NSUInteger i = 0; i < ColorCoordinateCount; i++) { 40 | _ver.Color[i] = Color[i]; 41 | } 42 | 43 | return _ver; 44 | 45 | }; 46 | 47 | /** 48 | * 把 VFVertex 点封装成 NSValue 对象 49 | */ 50 | VFVertexValue * VFVertexToValue(VFVertex *info) { 51 | return [NSValue valueObjByStructPtr:info objType:@encode(VFVertex)]; 52 | } 53 | 54 | /** 55 | * 把 VFVertex 点从 NSValue 对象中提取出来 56 | */ 57 | void valueToVFVertex(VFVertexValue *infoV, VFVertex *storedInfo) { 58 | [NSValue structFromValueObj:infoV structPtr:storedInfo]; 59 | } 60 | 61 | #endif /* VFVertex_h */ 62 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Datas/Models/VFAttachVertexInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFAttachVertexInfo.h 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @class VFShaderValueInfo; 13 | 14 | @interface VFAttachVertexInfo : NSObject 15 | 16 | // 着色器的变量信息 17 | @property (strong, nonatomic) VFShaderValueInfo *shaderValueInfo; 18 | // 数据的坐标分量数 19 | @property (assign, nonatomic) GLint coordinateComsCount; 20 | // 数据类型转换 21 | @property (assign, nonatomic) GLboolean exchangeDataType; 22 | // 储存的数据单个变量的分量的数据类型 23 | @property (assign, nonatomic) GLenum dataType; 24 | // 相邻数据的间隔 25 | @property (assign, nonatomic) GLsizei dataStride; 26 | // 数据加载的内存首地址 27 | @property (assign, nonatomic) const GLvoid * dataLoadPtr; 28 | 29 | - (instancetype)initWithShaderValueInfo:(VFShaderValueInfo *)shaderValueInfo 30 | coordinateComsCount:(GLint)coordinateComsCount 31 | exchangeDataType:(GLboolean)exchangeDataType 32 | dataType:(GLenum)dataType 33 | dataStride:(GLsizei)dataStride 34 | dataLoadPtr:(const GLvoid *)dataLoadPtr; 35 | 36 | // CVOs 37 | - (instancetype)initWithShaderValueInfo:(VFShaderValueInfo *)shaderValueInfo 38 | dataLoadPtr:(const GLvoid *)dataLoadPtr; 39 | @end 40 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Datas/VFMaths/VFColor.c: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.c 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #include "VFColor.h" 10 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Datas/VFMaths/VFColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFColor_h 10 | #define VFColor_h 11 | 12 | #include 13 | 14 | #endif /* VFColor_h */ 15 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Datas/VFMaths/VFMath.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFMath.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | //#pragma once 10 | 11 | #ifndef VFMath_h 12 | #define VFMath_h 13 | 14 | #include "VFMathTypes.h" 15 | 16 | #include "VFMatrix.h" 17 | #include "VFVector.h" 18 | #include "VFColor.h" 19 | 20 | #endif /* VFMath_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Datas/VFVertexDatasManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertexDatasManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | typedef NS_ENUM(NSUInteger, VFDrawGeometryType) { 13 | 14 | VFDrawGeometryType_Test = 0, 15 | VFDrawGeometryType_Tree, 16 | VFDrawGeometryType_Card, 17 | VFDrawGeometryType_Grass, 18 | 19 | }; 20 | 21 | @interface VFVertexDatasManager : NSObject 22 | 23 | /** 24 | * 绘制的几何图形类型 25 | */ 26 | @property (assign, nonatomic) VFDrawGeometryType drawGeometry; 27 | 28 | /** 29 | * 默认的顶点数据管理者 30 | */ 31 | + (instancetype)defaultVertexManager; 32 | 33 | /** 34 | * 缩放使当前渲染内容适应当前显示屏幕 35 | */ 36 | - (void)makeScaleToFitCurrentWindowWithScale:(float)scale; 37 | 38 | /** 39 | * 装载数据 40 | */ 41 | - (void)attachVertexDatas; 42 | 43 | /** 44 | * 绘制图形 45 | */ 46 | - (void)draw; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Render/VFFrameBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFrameBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFFrameBufferManager : NSObject 13 | 14 | // 当前活跃的帧缓存的标识 15 | @property (assign, nonatomic, readonly) GLuint currentFBOIdentifier; 16 | 17 | /** 18 | * 默认的帧缓存对象管理者 19 | */ 20 | + (instancetype)defaultFrameManager; 21 | 22 | /** 23 | * 创建 FBO 24 | */ 25 | - (void)createFrameBufferObject; 26 | 27 | /** 28 | * 使用 FBO 29 | */ 30 | - (void)useFrameBufferObject; 31 | 32 | /** 33 | * 删除 FBO 34 | */ 35 | - (void)deleteFrameBufferObject; 36 | 37 | /** 38 | * 装载 Render Buffer 的内容到 Frame Buffer 内 39 | */ 40 | - (void)attachRenderBufferToFrameBuffer:(GLuint)renderBufferObjcetID; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Render/VFRenderBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFRenderBufferManager : NSObject 13 | // 当前活跃的渲染缓存的标识 14 | @property (assign, nonatomic, readonly) GLuint currentRBOIdentifier; 15 | 16 | /** 17 | * 默认的渲染缓存对象管理者 18 | */ 19 | + (instancetype)defaultRenderManager; 20 | 21 | /** 22 | * 创建 RBO 23 | */ 24 | - (void)createRenderBufferObject; 25 | 26 | /** 27 | * 使用 RBO 28 | */ 29 | - (void)useRenderBufferObject; 30 | 31 | /** 32 | * 删除 RBO 33 | */ 34 | - (void)deleteRenderBufferObject; 35 | 36 | /** 37 | * 渲染缓存的尺寸 38 | */ 39 | - (CGSize)renderBufferSize; 40 | 41 | /** 42 | * 当前显示屏幕的像素比 43 | * (因为屏幕 Y 像素 > X 像素, 所以要缩小,不然显示就会向 Y 方向拉伸) 44 | */ 45 | - (CGFloat)windowScaleFactor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Render/VFRenderContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFCommon.h" 10 | 11 | @interface VFRenderContext : EAGLContext 12 | 13 | /** 14 | * 绑定进行渲染的窗口 15 | * 16 | * @param deawableLayer 渲染的窗口 17 | */ 18 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer; 19 | 20 | /** 21 | * 设置渲染窗口的背景色 22 | * 23 | * @param color RGBA 颜色值 24 | */ 25 | - (void)setRenderBackgroundColor:(RGBAColor)color; 26 | 27 | /** 28 | * 重置(清空)渲染内存 29 | */ 30 | - (void)clearRenderBuffer; 31 | 32 | /** 33 | * 设置视窗 34 | */ 35 | - (void)setRenderViewPortWithCGRect:(CGRect)rect; 36 | 37 | /** 38 | * 开始渲染 39 | */ 40 | - (void)render; 41 | 42 | /** 43 | * 恢复渲染上下文 44 | */ 45 | - (void)resetContext; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Render/VFRenderWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderWindow.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFRenderContext.h" 11 | 12 | @interface VFRenderWindow : UIView 13 | 14 | /** 15 | * 返回当前活跃的渲染上下文 16 | * 17 | * @return VFRenderContext 继承于 EAGLContext 18 | */ 19 | - (VFRenderContext *)currentContext; 20 | 21 | /** 22 | * 显示前,准备顶点数据、着色器等 23 | */ 24 | - (void)prepareDisplay; 25 | 26 | /** 27 | * 显示图形 28 | */ 29 | - (void)display; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Shader/VFFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | varying mediump vec4 f_color; 5 | 6 | void main(void) { 7 | gl_FragColor = f_color; 8 | } -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Shader/VFShaderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFShaderManager : NSObject 13 | 14 | /** 15 | * 默认的着色器管理者 16 | */ 17 | + (instancetype)defaultShaderManager; 18 | 19 | /** 20 | * 装载着色器 21 | * 22 | * @param vertexStringFileName 顶点着色器代码文件 23 | * @param fragmentStringFileName 片元着色器代码文件 24 | */ 25 | - (void)attachVertexShader:(NSString *)vertexStringFileName fragmentShader:(NSString *)fragmentStringFileName; 26 | 27 | /** 28 | * 使用着色器 29 | */ 30 | - (void)useShader; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Shader/VFShaderValueInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueInfo.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/10. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFShaderValueLocation.h" 11 | 12 | @interface VFShaderValueInfo : NSObject 13 | 14 | /* 变量名 */ 15 | @property (assign, nonatomic) NSString *name; 16 | /* 变量的数据类型 */ 17 | @property (assign, nonatomic) NSString *type; 18 | /* 变量的精度 */ 19 | @property (assign, nonatomic) NSString *precision; 20 | /* 变量的存储类型 */ 21 | @property (assign, nonatomic) NSString *storage; 22 | 23 | /* 变量的内存标识符 */ 24 | @property (assign, nonatomic) NSInteger location; 25 | 26 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type precision:(NSString *)precision storage:(NSString *)storage; 27 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type storage:(NSString *)storage; 28 | 29 | - (NSString *)valueKey; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/Classes/Shader/VFVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | attribute vec4 v_Position; 5 | uniform mat4 v_Projection; 6 | 7 | attribute vec4 v_Color; 8 | varying mediump vec4 f_color; 9 | 10 | void main(void) { 11 | f_color = v_Color; 12 | gl_Position = v_Projection * v_Position; // True, Left Dot Mul 13 | } 14 | 15 | //void main(void) {uniform mat4 v_Translation; 16 | // f_color = v_Color; 17 | // // A · (B · v) === (A · B) · v (A、B is Matrix, v is Vector) 18 | // gl_Position = v_Translation * v_Projection * v_Position; // True, Left Dot Mul 19 | //// gl_Position = v_Projection * v_Translation * v_Position; // True, Left Dot Mul 20 | //// gl_Position = v_Position * v_Projection * v_Translation; // False, Right Dot Mul 21 | //// gl_Position = v_Position * v_Translation * v_Projection; // False, Right Dot Mul 22 | //} -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFRenderWindow.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | VFRenderWindow *renderWindow = [[VFRenderWindow alloc] initWithFrame:self.view.bounds]; 24 | [renderWindow prepareDisplay]; 25 | 26 | [self.view addSubview:renderWindow]; 27 | [renderWindow display]; 28 | 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Challenges/DrawGeometries_Challenges/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/1. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/24. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Common/VFFreeSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFreeSource.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFFreeSource_h 10 | #define VFFreeSource_h 11 | 12 | @protocol OpenGLESFreeSource 13 | 14 | - (void)releaseSource; 15 | 16 | @end 17 | 18 | #endif /* VFFreeSource_h */ 19 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Common/VFOpenGLES2XHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFOpenGLES2XHeader.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFOpenGLES2XHeader_h 10 | #define VFOpenGLES2XHeader_h 11 | 12 | #ifdef __OBJC__ // GL_ES_VERSION_2_0 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #endif 19 | 20 | #endif /* VFOpenGLES2XHeader_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Common/VFShaderValueLocation.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueLocation.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/11. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFShaderValueLocation_h 10 | #define VFShaderValueLocation_h 11 | 12 | /* Info Key */ 13 | static NSString * POSITION_STRING_KEY = @"Position"; 14 | static NSString * COLOR_STRING_KEY = @"Color"; 15 | static NSString * NORMAL_STRING_KEY = @"Normal"; 16 | static NSString * TEXTURE0_STRING_KEY = @"Texture0"; 17 | 18 | typedef enum { 19 | 20 | VFVertexPositionAttribute = 0, 21 | VFVertexColorAttribute, 22 | 23 | } VFVertexAttribute; 24 | 25 | #endif /* VFShaderValueLocation_h */ 26 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Datas/VFMaths/VFColor.c: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.c 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #include "VFColor.h" 10 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Datas/VFMaths/VFColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFColor_h 10 | #define VFColor_h 11 | 12 | #include 13 | 14 | #endif /* VFColor_h */ 15 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Datas/VFMaths/VFMath.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFMath.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | //#pragma once 10 | 11 | #ifndef VFMath_h 12 | #define VFMath_h 13 | 14 | #include "VFMathTypes.h" 15 | 16 | #include "VFMatrix.h" 17 | #include "VFVector.h" 18 | #include "VFColor.h" 19 | 20 | #endif /* VFMath_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Render/VFFrameBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFrameBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFFrameBufferManager : NSObject 13 | 14 | // 当前活跃的帧缓存的标识 15 | @property (assign, nonatomic, readonly) GLuint currentFBOIdentifier; 16 | 17 | /** 18 | * 默认的帧缓存对象管理者 19 | */ 20 | + (instancetype)defaultFrameManager; 21 | 22 | /** 23 | * 创建 FBO 24 | */ 25 | - (void)createFrameBufferObject; 26 | 27 | /** 28 | * 使用 FBO 29 | */ 30 | - (void)useFrameBufferObject; 31 | 32 | /** 33 | * 删除 FBO 34 | */ 35 | - (void)deleteFrameBufferObject; 36 | 37 | /** 38 | * 装载 Render Buffer 的内容到 Frame Buffer 内 39 | */ 40 | - (void)attachRenderBufferToFrameBuffer:(GLuint)renderBufferObjcetID; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Render/VFRenderBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFRenderBufferManager : NSObject 13 | // 当前活跃的渲染缓存的标识 14 | @property (assign, nonatomic, readonly) GLuint currentRBOIdentifier; 15 | 16 | /** 17 | * 默认的渲染缓存对象管理者 18 | */ 19 | + (instancetype)defaultRenderManager; 20 | 21 | /** 22 | * 创建 RBO 23 | */ 24 | - (void)createRenderBufferObject; 25 | 26 | /** 27 | * 使用 RBO 28 | */ 29 | - (void)useRenderBufferObject; 30 | 31 | /** 32 | * 删除 RBO 33 | */ 34 | - (void)deleteRenderBufferObject; 35 | 36 | /** 37 | * 渲染缓存的尺寸 38 | */ 39 | - (CGSize)renderBufferSize; 40 | 41 | /** 42 | * 当前显示屏幕的像素比 43 | * (因为屏幕 Y 像素 > X 像素, 所以要缩小,不然显示就会向 Y 方向拉伸) 44 | */ 45 | - (CGFloat)windowScaleFactor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Render/VFRenderContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFCommon.h" 10 | 11 | @interface VFRenderContext : EAGLContext 12 | 13 | /** 14 | * 绑定进行渲染的窗口 15 | * 16 | * @param deawableLayer 渲染的窗口 17 | */ 18 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer; 19 | 20 | /** 21 | * 设置渲染窗口的背景色 22 | * 23 | * @param color RGBA 颜色值 24 | */ 25 | - (void)setRenderBackgroundColor:(RGBAColor)color; 26 | 27 | /** 28 | * 重置(清空)渲染内存 29 | */ 30 | - (void)clearRenderBuffer; 31 | 32 | /** 33 | * 设置视窗 34 | */ 35 | - (void)setRenderViewPortWithCGRect:(CGRect)rect; 36 | 37 | /** 38 | * 开始渲染 39 | */ 40 | - (void)render; 41 | 42 | /** 43 | * 恢复渲染上下文 44 | */ 45 | - (void)resetContext; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Render/VFRenderWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderWindow.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFRenderContext.h" 11 | 12 | @interface VFRenderWindow : UIView 13 | 14 | /** 15 | * 返回当前活跃的渲染上下文 16 | * 17 | * @return VFRenderContext 继承于 EAGLContext 18 | */ 19 | - (VFRenderContext *)currentContext; 20 | 21 | /** 22 | * 显示前,准备顶点数据、着色器等 23 | */ 24 | - (void)prepareDisplay; 25 | 26 | /** 27 | * 显示图形 28 | */ 29 | - (void)display; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Shader/VFFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | varying mediump vec4 f_color; 5 | 6 | void main(void) { 7 | gl_FragColor = f_color; 8 | } -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Shader/VFShaderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFShaderManager : NSObject 13 | 14 | /** 15 | * 默认的着色器管理者 16 | */ 17 | + (instancetype)defaultShaderManager; 18 | 19 | /** 20 | * 装载着色器 21 | * 22 | * @param vertexStringFileName 顶点着色器代码文件 23 | * @param fragmentStringFileName 片元着色器代码文件 24 | */ 25 | - (void)attachVertexShader:(NSString *)vertexStringFileName fragmentShader:(NSString *)fragmentStringFileName; 26 | 27 | /** 28 | * 使用着色器 29 | */ 30 | - (void)useShader; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Shader/VFShaderValueInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueInfo.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/10. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFShaderValueLocation.h" 11 | 12 | @interface VFShaderValueInfo : NSObject 13 | 14 | /* 变量名 */ 15 | @property (assign, nonatomic) NSString *name; 16 | /* 变量的数据类型 */ 17 | @property (assign, nonatomic) NSString *type; 18 | /* 变量的精度 */ 19 | @property (assign, nonatomic) NSString *precision; 20 | /* 变量的存储类型 */ 21 | @property (assign, nonatomic) NSString *storage; 22 | 23 | /* 变量的内存标识符 */ 24 | @property (assign, nonatomic) NSInteger location; 25 | 26 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type precision:(NSString *)precision storage:(NSString *)storage; 27 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type storage:(NSString *)storage; 28 | 29 | - (NSString *)valueKey; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/Classes/Shader/VFVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | attribute vec4 v_Position; 5 | uniform mat4 v_Projection; 6 | 7 | attribute vec4 v_Color; 8 | varying mediump vec4 f_color; 9 | 10 | void main(void) { 11 | f_color = v_Color; 12 | gl_Position = v_Projection * v_Position; // True, Left Dot Mul 13 | } 14 | 15 | //void main(void) {uniform mat4 v_Translation; 16 | // f_color = v_Color; 17 | // // A · (B · v) === (A · B) · v (A、B is Matrix, v is Vector) 18 | // gl_Position = v_Translation * v_Projection * v_Position; // True, Left Dot Mul 19 | //// gl_Position = v_Projection * v_Translation * v_Position; // True, Left Dot Mul 20 | //// gl_Position = v_Position * v_Projection * v_Translation; // False, Right Dot Mul 21 | //// gl_Position = v_Position * v_Translation * v_Projection; // False, Right Dot Mul 22 | //} -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFRenderWindow.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | VFRenderWindow *renderWindow = [[VFRenderWindow alloc] initWithFrame:self.view.bounds]; 24 | [renderWindow prepareDisplay]; 25 | 26 | [self.view addSubview:renderWindow]; 27 | [renderWindow display]; 28 | 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Lines/DrawGeometries_Lines/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/24. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawGeometries_Triangles 4 | // 5 | // Created by windy on 16/11/28. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Common/VFFreeSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFreeSource.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFFreeSource_h 10 | #define VFFreeSource_h 11 | 12 | @protocol OpenGLESFreeSource 13 | 14 | - (void)releaseSource; 15 | 16 | @end 17 | 18 | #endif /* VFFreeSource_h */ 19 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Common/VFOpenGLES2XHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFOpenGLES2XHeader.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFOpenGLES2XHeader_h 10 | #define VFOpenGLES2XHeader_h 11 | 12 | #ifdef __OBJC__ // GL_ES_VERSION_2_0 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #endif 19 | 20 | #endif /* VFOpenGLES2XHeader_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Common/VFShaderValueLocation.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueLocation.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/11. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFShaderValueLocation_h 10 | #define VFShaderValueLocation_h 11 | 12 | /* Info Key */ 13 | static NSString * POSITION_STRING_KEY = @"Position"; 14 | static NSString * COLOR_STRING_KEY = @"Color"; 15 | static NSString * NORMAL_STRING_KEY = @"Normal"; 16 | static NSString * TEXTURE0_STRING_KEY = @"Texture0"; 17 | 18 | typedef enum { 19 | 20 | VFVertexPositionAttribute = 0, 21 | VFVertexColorAttribute, 22 | 23 | } VFVertexAttribute; 24 | 25 | #endif /* VFShaderValueLocation_h */ 26 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Datas/VFMaths/VFColor.c: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.c 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #include "VFColor.h" 10 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Datas/VFMaths/VFColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFColor_h 10 | #define VFColor_h 11 | 12 | #include 13 | 14 | #endif /* VFColor_h */ 15 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Datas/VFMaths/VFMath.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFMath.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | //#pragma once 10 | 11 | #ifndef VFMath_h 12 | #define VFMath_h 13 | 14 | #include "VFMathTypes.h" 15 | 16 | #include "VFMatrix.h" 17 | #include "VFVector.h" 18 | #include "VFColor.h" 19 | 20 | #endif /* VFMath_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Datas/VFVertexDatasManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertexDatasManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | typedef NS_ENUM(NSUInteger, VFDrawGeometryType) { 13 | 14 | VFDrawGeometryType_TriangleTriangles = 0, 15 | VFDrawGeometryType_RectangleTriangles, 16 | VFDrawGeometryType_PentagonsTriangles, 17 | VFDrawGeometryType_HexagonsTriangles, 18 | VFDrawGeometryType_TrapezoidTriangles, 19 | VFDrawGeometryType_PentagramTriangles, 20 | VFDrawGeometryType_RoundTriangles, 21 | 22 | }; 23 | 24 | @interface VFVertexDatasManager : NSObject 25 | 26 | /** 27 | * 绘制的几何图形类型 28 | */ 29 | @property (assign, nonatomic) VFDrawGeometryType drawGeometry; 30 | 31 | /** 32 | * 默认的顶点数据管理者 33 | */ 34 | + (instancetype)defaultVertexManager; 35 | 36 | /** 37 | * 缩放使当前渲染内容适应当前显示屏幕 38 | */ 39 | - (void)makeScaleToFitCurrentWindowWithScale:(float)scale; 40 | 41 | /** 42 | * 装载数据 43 | */ 44 | - (void)attachVertexDatas; 45 | 46 | /** 47 | * 绘制图形 48 | */ 49 | - (void)draw; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Render/VFFrameBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFrameBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFFrameBufferManager : NSObject 13 | 14 | // 当前活跃的帧缓存的标识 15 | @property (assign, nonatomic, readonly) GLuint currentFBOIdentifier; 16 | 17 | /** 18 | * 默认的帧缓存对象管理者 19 | */ 20 | + (instancetype)defaultFrameManager; 21 | 22 | /** 23 | * 创建 FBO 24 | */ 25 | - (void)createFrameBufferObject; 26 | 27 | /** 28 | * 使用 FBO 29 | */ 30 | - (void)useFrameBufferObject; 31 | 32 | /** 33 | * 删除 FBO 34 | */ 35 | - (void)deleteFrameBufferObject; 36 | 37 | /** 38 | * 装载 Render Buffer 的内容到 Frame Buffer 内 39 | */ 40 | - (void)attachRenderBufferToFrameBuffer:(GLuint)renderBufferObjcetID; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Render/VFRenderBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFRenderBufferManager : NSObject 13 | // 当前活跃的渲染缓存的标识 14 | @property (assign, nonatomic, readonly) GLuint currentRBOIdentifier; 15 | 16 | /** 17 | * 默认的渲染缓存对象管理者 18 | */ 19 | + (instancetype)defaultRenderManager; 20 | 21 | /** 22 | * 创建 RBO 23 | */ 24 | - (void)createRenderBufferObject; 25 | 26 | /** 27 | * 使用 RBO 28 | */ 29 | - (void)useRenderBufferObject; 30 | 31 | /** 32 | * 删除 RBO 33 | */ 34 | - (void)deleteRenderBufferObject; 35 | 36 | /** 37 | * 渲染缓存的尺寸 38 | */ 39 | - (CGSize)renderBufferSize; 40 | 41 | /** 42 | * 当前显示屏幕的像素比 43 | * (因为屏幕 Y 像素 > X 像素, 所以要缩小,不然显示就会向 Y 方向拉伸) 44 | */ 45 | - (CGFloat)windowScaleFactor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Render/VFRenderContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFCommon.h" 10 | 11 | @interface VFRenderContext : EAGLContext 12 | 13 | /** 14 | * 绑定进行渲染的窗口 15 | * 16 | * @param deawableLayer 渲染的窗口 17 | */ 18 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer; 19 | 20 | /** 21 | * 设置渲染窗口的背景色 22 | * 23 | * @param color RGBA 颜色值 24 | */ 25 | - (void)setRenderBackgroundColor:(RGBAColor)color; 26 | 27 | /** 28 | * 重置(清空)渲染内存 29 | */ 30 | - (void)clearRenderBuffer; 31 | 32 | /** 33 | * 设置视窗 34 | */ 35 | - (void)setRenderViewPortWithCGRect:(CGRect)rect; 36 | 37 | /** 38 | * 开始渲染 39 | */ 40 | - (void)render; 41 | 42 | /** 43 | * 恢复渲染上下文 44 | */ 45 | - (void)resetContext; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Render/VFRenderWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderWindow.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFRenderContext.h" 11 | 12 | @interface VFRenderWindow : UIView 13 | 14 | /** 15 | * 返回当前活跃的渲染上下文 16 | * 17 | * @return VFRenderContext 继承于 EAGLContext 18 | */ 19 | - (VFRenderContext *)currentContext; 20 | 21 | /** 22 | * 显示前,准备顶点数据、着色器等 23 | */ 24 | - (void)prepareDisplay; 25 | 26 | /** 27 | * 显示图形 28 | */ 29 | - (void)display; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Shader/VFFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | varying mediump vec4 f_color; 5 | 6 | void main(void) { 7 | gl_FragColor = f_color; 8 | } -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Shader/VFShaderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFShaderManager : NSObject 13 | 14 | /** 15 | * 默认的着色器管理者 16 | */ 17 | + (instancetype)defaultShaderManager; 18 | 19 | /** 20 | * 装载着色器 21 | * 22 | * @param vertexStringFileName 顶点着色器代码文件 23 | * @param fragmentStringFileName 片元着色器代码文件 24 | */ 25 | - (void)attachVertexShader:(NSString *)vertexStringFileName fragmentShader:(NSString *)fragmentStringFileName; 26 | 27 | /** 28 | * 使用着色器 29 | */ 30 | - (void)useShader; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Shader/VFShaderValueInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueInfo.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/10. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFShaderValueLocation.h" 11 | 12 | @interface VFShaderValueInfo : NSObject 13 | 14 | /* 变量名 */ 15 | @property (assign, nonatomic) NSString *name; 16 | /* 变量的数据类型 */ 17 | @property (assign, nonatomic) NSString *type; 18 | /* 变量的精度 */ 19 | @property (assign, nonatomic) NSString *precision; 20 | /* 变量的存储类型 */ 21 | @property (assign, nonatomic) NSString *storage; 22 | 23 | /* 变量的内存标识符 */ 24 | @property (assign, nonatomic) NSInteger location; 25 | 26 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type precision:(NSString *)precision storage:(NSString *)storage; 27 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type storage:(NSString *)storage; 28 | 29 | - (NSString *)valueKey; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/Classes/Shader/VFVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | attribute vec4 v_Position; 5 | uniform mat4 v_Projection; 6 | 7 | attribute vec4 v_Color; 8 | varying mediump vec4 f_color; 9 | 10 | void main(void) { 11 | f_color = v_Color; 12 | gl_Position = v_Projection * v_Position; // True, Left Dot Mul 13 | } 14 | 15 | //void main(void) {uniform mat4 v_Translation; 16 | // f_color = v_Color; 17 | // // A · (B · v) === (A · B) · v (A、B is Matrix, v is Vector) 18 | // gl_Position = v_Translation * v_Projection * v_Position; // True, Left Dot Mul 19 | //// gl_Position = v_Projection * v_Translation * v_Position; // True, Left Dot Mul 20 | //// gl_Position = v_Position * v_Projection * v_Translation; // False, Right Dot Mul 21 | //// gl_Position = v_Position * v_Translation * v_Projection; // False, Right Dot Mul 22 | //} -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFRenderWindow.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | VFRenderWindow *renderWindow = [[VFRenderWindow alloc] initWithFrame:self.view.bounds]; 24 | [renderWindow prepareDisplay]; 25 | 26 | [self.view addSubview:renderWindow]; 27 | [renderWindow display]; 28 | 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /03-DrawGeometries/DrawGeometries_Triangles/DrawGeometries_Triangles/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawGeometries_Triangles 4 | // 5 | // Created by windy on 16/11/28. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawGeometries_Points 4 | // 5 | // Created by windy on 16/12/5. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Common/NSValue+Struct2Value.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+Struct2Value.h 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSValue (Struct2Value) 12 | 13 | // 结构体转换成 NSValue 对象 14 | + (NSValue *)valueObjByStructPtr:(const void *)str objType:(const char * )objType; 15 | // NSValue 转换成 Struct 16 | + (void)structFromValueObj:(NSValue *)value structPtr:(void *)str; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Common/NSValue+Struct2Value.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+Struct2Value.m 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "NSValue+Struct2Value.h" 10 | 11 | @implementation NSValue (Struct2Value) 12 | 13 | #pragma mark - Struct & NSValue 14 | 15 | // 结构体转换成 NSValue 对象 16 | + (NSValue *)valueObjByStructPtr:(const void *)str objType:(const char * )objType { 17 | return [NSValue valueWithBytes:str objCType:objType]; 18 | } 19 | 20 | // NSValue 转换成 Struct 21 | + (void)structFromValueObj:(NSValue *)value structPtr:(void *)str { 22 | [value getValue:str]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Common/VFFreeSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFreeSource.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFFreeSource_h 10 | #define VFFreeSource_h 11 | 12 | @protocol OpenGLESFreeSource 13 | 14 | - (void)releaseSource; 15 | 16 | @end 17 | 18 | #endif /* VFFreeSource_h */ 19 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Common/VFOpenGLES2XHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFOpenGLES2XHeader.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFOpenGLES2XHeader_h 10 | #define VFOpenGLES2XHeader_h 11 | 12 | #ifdef __OBJC__ // GL_ES_VERSION_2_0 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #endif 19 | 20 | #endif /* VFOpenGLES2XHeader_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Common/VFShaderValueLocation.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueLocation.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/11. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFShaderValueLocation_h 10 | #define VFShaderValueLocation_h 11 | 12 | /* Info Key */ 13 | static NSString * POSITION_STRING_KEY = @"Position"; 14 | static NSString * COLOR_STRING_KEY = @"Color"; 15 | static NSString * NORMAL_STRING_KEY = @"Normal"; 16 | static NSString * TEXTURE0_STRING_KEY = @"Texture0"; 17 | 18 | typedef enum { 19 | 20 | VFVertexPositionAttribute = 0, 21 | VFVertexColorAttribute, 22 | 23 | } VFVertexAttribute; 24 | 25 | #endif /* VFShaderValueLocation_h */ 26 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Common/VFVertex.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertex.h 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFVertex_h 10 | #define VFVertex_h 11 | 12 | #import "NSValue+Struct2Value.h" 13 | 14 | #define PositionCoordinateCount (3) 15 | #define NormalCoordinateCount (3) 16 | #define TextureCoordinateCount (2) 17 | 18 | #define ColorCoordinateCount (4) 19 | 20 | #pragma mark - VFVertex 21 | 22 | typedef struct { 23 | 24 | GLfloat Position[PositionCoordinateCount]; // { x, y, z } 25 | GLfloat Color[ColorCoordinateCount]; 26 | 27 | } VFVertex; 28 | 29 | typedef NSValue VFVertexValue; 30 | 31 | static inline VFVertex VFVertexMake(GLfloat Position[PositionCoordinateCount], 32 | GLfloat Color[ColorCoordinateCount]) { 33 | 34 | VFVertex _ver; 35 | for (NSUInteger i = 0; i < PositionCoordinateCount; i++) { 36 | _ver.Position[i] = Position[i]; 37 | } 38 | 39 | for (NSUInteger i = 0; i < ColorCoordinateCount; i++) { 40 | _ver.Color[i] = Color[i]; 41 | } 42 | 43 | return _ver; 44 | 45 | }; 46 | 47 | /** 48 | * 把 VFVertex 点封装成 NSValue 对象 49 | */ 50 | VFVertexValue * VFVertexToValue(VFVertex *info) { 51 | return [NSValue valueObjByStructPtr:info objType:@encode(VFVertex)]; 52 | } 53 | 54 | /** 55 | * 把 VFVertex 点从 NSValue 对象中提取出来 56 | */ 57 | void valueToVFVertex(VFVertexValue *infoV, VFVertex *storedInfo) { 58 | [NSValue structFromValueObj:infoV structPtr:storedInfo]; 59 | } 60 | 61 | #endif /* VFVertex_h */ 62 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Datas/Models/VFAttachVertexInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFAttachVertexInfo.h 3 | // DrawGeometries_Challenges 4 | // 5 | // Created by windy on 16/12/2. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @class VFShaderValueInfo; 13 | 14 | @interface VFAttachVertexInfo : NSObject 15 | 16 | // 着色器的变量信息 17 | @property (strong, nonatomic) VFShaderValueInfo *shaderValueInfo; 18 | // 数据的坐标分量数 19 | @property (assign, nonatomic) GLint coordinateComsCount; 20 | // 数据类型转换 21 | @property (assign, nonatomic) GLboolean exchangeDataType; 22 | // 储存的数据单个变量的分量的数据类型 23 | @property (assign, nonatomic) GLenum dataType; 24 | // 相邻数据的间隔 25 | @property (assign, nonatomic) GLsizei dataStride; 26 | // 数据加载的内存首地址 27 | @property (assign, nonatomic) const GLvoid * dataLoadPtr; 28 | 29 | - (instancetype)initWithShaderValueInfo:(VFShaderValueInfo *)shaderValueInfo 30 | coordinateComsCount:(GLint)coordinateComsCount 31 | exchangeDataType:(GLboolean)exchangeDataType 32 | dataType:(GLenum)dataType 33 | dataStride:(GLsizei)dataStride 34 | dataLoadPtr:(const GLvoid *)dataLoadPtr; 35 | 36 | // CVOs 37 | - (instancetype)initWithShaderValueInfo:(VFShaderValueInfo *)shaderValueInfo 38 | dataLoadPtr:(const GLvoid *)dataLoadPtr; 39 | @end 40 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Datas/VFMaths/VFColor.c: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.c 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #include "VFColor.h" 10 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Datas/VFMaths/VFColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFColor.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #ifndef VFColor_h 10 | #define VFColor_h 11 | 12 | #include 13 | 14 | #endif /* VFColor_h */ 15 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Datas/VFMaths/VFMath.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFMath.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/15. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | //#pragma once 10 | 11 | #ifndef VFMath_h 12 | #define VFMath_h 13 | 14 | #include "VFMathTypes.h" 15 | 16 | #include "VFMatrix.h" 17 | #include "VFVector.h" 18 | #include "VFColor.h" 19 | 20 | #endif /* VFMath_h */ 21 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Datas/VFVertexDatasManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFVertexDatasManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | typedef NS_ENUM(NSUInteger, VFDrawGeometryType) { 13 | 14 | VFDrawGeometryType_Test = 0, 15 | VFDrawGeometryType_Tree, 16 | VFDrawGeometryType_Card, 17 | VFDrawGeometryType_Grass, 18 | 19 | }; 20 | 21 | @interface VFVertexDatasManager : NSObject 22 | 23 | /** 24 | * 绘制的几何图形类型 25 | */ 26 | @property (assign, nonatomic) VFDrawGeometryType drawGeometry; 27 | 28 | /** 29 | * 默认的顶点数据管理者 30 | */ 31 | + (instancetype)defaultVertexManager; 32 | 33 | /** 34 | * 缩放使当前渲染内容适应当前显示屏幕 35 | */ 36 | - (void)makeScaleToFitCurrentWindowWithScale:(float)scale; 37 | 38 | /** 39 | * 装载数据 40 | */ 41 | - (void)attachVertexDatas; 42 | 43 | /** 44 | * 绘制图形 45 | */ 46 | - (void)draw; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Render/VFFrameBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFFrameBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFFrameBufferManager : NSObject 13 | 14 | // 当前活跃的帧缓存的标识 15 | @property (assign, nonatomic, readonly) GLuint currentFBOIdentifier; 16 | 17 | /** 18 | * 默认的帧缓存对象管理者 19 | */ 20 | + (instancetype)defaultFrameManager; 21 | 22 | /** 23 | * 创建 FBO 24 | */ 25 | - (void)createFrameBufferObject; 26 | 27 | /** 28 | * 使用 FBO 29 | */ 30 | - (void)useFrameBufferObject; 31 | 32 | /** 33 | * 删除 FBO 34 | */ 35 | - (void)deleteFrameBufferObject; 36 | 37 | /** 38 | * 装载 Render Buffer 的内容到 Frame Buffer 内 39 | */ 40 | - (void)attachRenderBufferToFrameBuffer:(GLuint)renderBufferObjcetID; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Render/VFRenderBufferManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderBufferManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFRenderBufferManager : NSObject 13 | // 当前活跃的渲染缓存的标识 14 | @property (assign, nonatomic, readonly) GLuint currentRBOIdentifier; 15 | 16 | /** 17 | * 默认的渲染缓存对象管理者 18 | */ 19 | + (instancetype)defaultRenderManager; 20 | 21 | /** 22 | * 创建 RBO 23 | */ 24 | - (void)createRenderBufferObject; 25 | 26 | /** 27 | * 使用 RBO 28 | */ 29 | - (void)useRenderBufferObject; 30 | 31 | /** 32 | * 删除 RBO 33 | */ 34 | - (void)deleteRenderBufferObject; 35 | 36 | /** 37 | * 渲染缓存的尺寸 38 | */ 39 | - (CGSize)renderBufferSize; 40 | 41 | /** 42 | * 当前显示屏幕的像素比 43 | * (因为屏幕 Y 像素 > X 像素, 所以要缩小,不然显示就会向 Y 方向拉伸) 44 | */ 45 | - (CGFloat)windowScaleFactor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Render/VFRenderContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderContext.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "VFCommon.h" 10 | 11 | @interface VFRenderContext : EAGLContext 12 | 13 | /** 14 | * 绑定进行渲染的窗口 15 | * 16 | * @param deawableLayer 渲染的窗口 17 | */ 18 | - (void)bindDrawableLayer:(CAEAGLLayer *)drawableLayer; 19 | 20 | /** 21 | * 设置渲染窗口的背景色 22 | * 23 | * @param color RGBA 颜色值 24 | */ 25 | - (void)setRenderBackgroundColor:(RGBAColor)color; 26 | 27 | /** 28 | * 重置(清空)渲染内存 29 | */ 30 | - (void)clearRenderBuffer; 31 | 32 | /** 33 | * 设置视窗 34 | */ 35 | - (void)setRenderViewPortWithCGRect:(CGRect)rect; 36 | 37 | /** 38 | * 开始渲染 39 | */ 40 | - (void)render; 41 | 42 | /** 43 | * 恢复渲染上下文 44 | */ 45 | - (void)resetContext; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Render/VFRenderWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRenderWindow.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFRenderContext.h" 11 | 12 | @interface VFRenderWindow : UIView 13 | 14 | /** 15 | * 返回当前活跃的渲染上下文 16 | * 17 | * @return VFRenderContext 继承于 EAGLContext 18 | */ 19 | - (VFRenderContext *)currentContext; 20 | 21 | /** 22 | * 显示前,准备顶点数据、着色器等 23 | */ 24 | - (void)prepareDisplay; 25 | 26 | /** 27 | * 显示图形 28 | */ 29 | - (void)display; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Shader/VFFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | varying mediump vec4 f_color; 5 | 6 | void main(void) { 7 | gl_FragColor = f_color; 8 | } -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Shader/VFShaderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderManager.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCommon.h" 11 | 12 | @interface VFShaderManager : NSObject 13 | 14 | /** 15 | * 默认的着色器管理者 16 | */ 17 | + (instancetype)defaultShaderManager; 18 | 19 | /** 20 | * 装载着色器 21 | * 22 | * @param vertexStringFileName 顶点着色器代码文件 23 | * @param fragmentStringFileName 片元着色器代码文件 24 | */ 25 | - (void)attachVertexShader:(NSString *)vertexStringFileName fragmentShader:(NSString *)fragmentStringFileName; 26 | 27 | /** 28 | * 使用着色器 29 | */ 30 | - (void)useShader; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Shader/VFShaderValueInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFShaderValueInfo.h 3 | // DrawTriangle_Fix 4 | // 5 | // Created by windy on 16/11/10. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFShaderValueLocation.h" 11 | 12 | @interface VFShaderValueInfo : NSObject 13 | 14 | /* 变量名 */ 15 | @property (assign, nonatomic) NSString *name; 16 | /* 变量的数据类型 */ 17 | @property (assign, nonatomic) NSString *type; 18 | /* 变量的精度 */ 19 | @property (assign, nonatomic) NSString *precision; 20 | /* 变量的存储类型 */ 21 | @property (assign, nonatomic) NSString *storage; 22 | 23 | /* 变量的内存标识符 */ 24 | @property (assign, nonatomic) NSInteger location; 25 | 26 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type precision:(NSString *)precision storage:(NSString *)storage; 27 | - (instancetype)initWithName:(NSString *)name type:(NSString *)type storage:(NSString *)storage; 28 | 29 | - (NSString *)valueKey; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/Classes/Shader/VFVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | attribute vec4 v_Position; 5 | uniform mat4 v_Projection; 6 | 7 | attribute vec4 v_Color; 8 | varying mediump vec4 f_color; 9 | 10 | void main(void) { 11 | f_color = v_Color; 12 | gl_Position = v_Projection * v_Position; // True, Left Dot Mul 13 | } 14 | 15 | //void main(void) {uniform mat4 v_Translation; 16 | // f_color = v_Color; 17 | // // A · (B · v) === (A · B) · v (A、B is Matrix, v is Vector) 18 | // gl_Position = v_Translation * v_Projection * v_Position; // True, Left Dot Mul 19 | //// gl_Position = v_Projection * v_Translation * v_Position; // True, Left Dot Mul 20 | //// gl_Position = v_Position * v_Projection * v_Translation; // False, Right Dot Mul 21 | //// gl_Position = v_Position * v_Translation * v_Projection; // False, Right Dot Mul 22 | //} -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawGeometries_Lines 4 | // 5 | // Created by windy on 16/11/06. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFRenderWindow.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | VFRenderWindow *renderWindow = [[VFRenderWindow alloc] initWithFrame:self.view.bounds]; 24 | [renderWindow prepareDisplay]; 25 | 26 | [self.view addSubview:renderWindow]; 27 | [renderWindow display]; 28 | 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/DrawGeometries_Points/DrawGeometries_Points/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawGeometries_Points 4 | // 5 | // Created by windy on 16/12/5. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03-DrawGeometries/UIs/Geometries.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/03-DrawGeometries/UIs/Geometries.sketch -------------------------------------------------------------------------------- /03-DrawGeometries/VFDynamicCalculateGeoPoints/VFDynamicCalculateGeoPoints.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03-DrawGeometries/VFDynamicCalculateGeoPoints/VFDynamicCalculateGeoPoints/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // VFDynamicCalculateGeoPoints 4 | // 5 | // Created by windy on 16/11/26. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VFCalculatePoints.h" 11 | 12 | int main(int argc, const char * argv[]) { 13 | @autoreleasepool { 14 | // insert code here... 15 | 16 | VFCalculatePoints *pointMaker = [[VFCalculatePoints alloc] init]; 17 | 18 | CGFloat radii = 0.5f; 19 | NSArray *geos = @[@(3), @(4), @(5), @(6), @(10)]; 20 | [pointMaker makeRegularVertexPointsReadToFileWithRadii:radii geolines:geos]; 21 | 22 | NSArray *traPoints = [pointMaker makeTrapezoidVertexPointsWithWidth:0.7f 23 | height:0.5f 24 | topOffset:CGPointMake(0.f, 0.f) 25 | bottomOffet:CGPointMake(0.25f, 0.f)]; 26 | [pointMaker buildDatasInFileWithMode:AppendContent content:traPoints]; 27 | 28 | NSArray *starPoints = [pointMaker makeStarVertexPointsWithInnerRadii:0.3f outterRadii:0.5f]; 29 | [pointMaker buildDatasInFileWithMode:AppendContent content:starPoints]; 30 | 31 | NSArray *roundPoints = [pointMaker makeRegularVertexPointsWithRadii:0.5f lines:100]; 32 | [pointMaker buildDatasInFileWithMode:AppendContent content:roundPoints]; 33 | 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawCube 4 | // 5 | // Created by windy on 16/12/17. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/VFGLCubeView.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFGLTriangleView.h 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VFGLCubeView : UIView 12 | 13 | - (void)prepareDisplay; 14 | - (void)drawAndRender; 15 | 16 | - (void)update; 17 | - (void)pauseUpdate; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/VFRedisplay.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRedisplay.h 3 | // DrawCube 4 | // 5 | // Created by windy on 16/12/23. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol VFRedisplayDelegate 12 | 13 | - (void)updateContentsWithTimes:(NSTimeInterval)times; 14 | 15 | @end 16 | 17 | @interface VFRedisplay : NSObject 18 | 19 | @property (weak, nonatomic) id delegate; 20 | 21 | /* 22 | 帧速率,默认是 30 23 | */ 24 | @property (nonatomic) NSInteger preferredFramesPerSecond; 25 | 26 | /* 27 | 帧速率 28 | */ 29 | @property (nonatomic, readonly) NSInteger framesPerSecond; 30 | 31 | @property (nonatomic, assign) NSTimeInterval updateContentTimes; 32 | 33 | /* 34 | Time interval since properties. 35 | */ 36 | @property (nonatomic, readonly) NSTimeInterval timeSinceFirstResume; 37 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastResume; 38 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastUpdate; 39 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastDraw; 40 | 41 | - (void)startUpdate; 42 | - (void)pauseUpdate; 43 | - (void)endUpdate; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFGLCubeView.h" 12 | 13 | @interface ViewController () 14 | @property (strong, nonatomic) VFGLCubeView *cubeView; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | CGRect rect = CGRectOffset(self.view.frame, 0, 0); 24 | self.cubeView = [[VFGLCubeView alloc] initWithFrame:rect]; 25 | 26 | [_cubeView prepareDisplay]; 27 | [_cubeView drawAndRender]; 28 | 29 | [self.view addSubview:_cubeView]; 30 | 31 | } 32 | 33 | - (void)viewDidAppear:(BOOL)animated { 34 | 35 | [super viewDidAppear:animated]; 36 | 37 | [self.cubeView update]; 38 | 39 | } 40 | 41 | - (void)viewWillDisappear:(BOOL)animated { 42 | 43 | [super viewWillDisappear:animated]; 44 | 45 | [self.cubeView pauseUpdate]; 46 | 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube/DrawCube/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawCube 4 | // 5 | // Created by windy on 16/12/17. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawCube_Camera 4 | // 5 | // Created by windy on 17/1/21. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/Class/Display/VFRedisplay.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRedisplay.h 3 | // DrawCube 4 | // 5 | // Created by windy on 16/12/23. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol VFRedisplayDelegate 12 | 13 | - (void)updateContentsWithTimes:(NSTimeInterval)times; 14 | 15 | @end 16 | 17 | @interface VFRedisplay : NSObject 18 | 19 | @property (weak, nonatomic) id delegate; 20 | 21 | /* 22 | 帧速率,默认是 30 23 | */ 24 | @property (nonatomic) NSInteger preferredFramesPerSecond; 25 | 26 | /* 27 | 帧速率 28 | */ 29 | @property (nonatomic, readonly) NSInteger framesPerSecond; 30 | 31 | @property (nonatomic, assign) NSTimeInterval updateContentTimes; 32 | 33 | /* 34 | Time interval since properties. 35 | */ 36 | @property (nonatomic, readonly) NSTimeInterval timeSinceFirstResume; 37 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastResume; 38 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastUpdate; 39 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastDraw; 40 | 41 | - (instancetype)initWithUpdateTimes:(NSTimeInterval)updateContentTimes preferredFramesPerSecond:(NSInteger)preferredFramesPerSecond; 42 | 43 | - (void)startUpdate; 44 | - (void)pauseUpdate; 45 | - (void)endUpdate; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/Class/Shader/FragmentShader.glsl: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | varying highp vec4 v_Color; 4 | 5 | void main(void) { 6 | 7 | gl_FragColor = v_Color; 8 | 9 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/Class/Shader/VertexShader.glsl: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | uniform mat4 u_ProjectionMat4; 4 | uniform mat4 u_ModelViewMat4; 5 | 6 | attribute vec4 a_Position; 7 | attribute vec4 a_Color; 8 | 9 | varying highp vec4 v_Color; 10 | 11 | void main(void) { 12 | 13 | v_Color = a_Color; 14 | gl_Position = u_ProjectionMat4 * u_ModelViewMat4 * a_Position; 15 | 16 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/Class/VFDrawCubeView.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFTextureDrawView.h 3 | // Texture-Part1-OneStep 4 | // 5 | // Created by windy on 17/1/6. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VFDrawCubeView : UIView 12 | 13 | - (void)update; 14 | - (void)pauseUpdate; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Texture-Part1-OneStep 4 | // 5 | // Created by windy on 17/1/6. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // Texture-Part1-OneStep 4 | // 5 | // Created by windy on 17/1/6. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFDrawCubeView.h" 12 | 13 | @interface ViewController () 14 | @property (strong, nonatomic) VFDrawCubeView *cubeView; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | CGRect cubeViewRect = self.view.bounds; 24 | self.cubeView = [[VFDrawCubeView alloc] initWithFrame:cubeViewRect]; 25 | 26 | [self.view addSubview:self.cubeView]; 27 | 28 | } 29 | 30 | - (void)viewDidAppear:(BOOL)animated { 31 | 32 | [super viewDidAppear:animated]; 33 | 34 | [self.cubeView update]; 35 | 36 | } 37 | 38 | - (void)viewWillDisappear:(BOOL)animated { 39 | 40 | [super viewWillDisappear:animated]; 41 | 42 | [self.cubeView pauseUpdate]; 43 | 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_Camera/DrawCube_Camera/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawCube_Camera 4 | // 5 | // Created by windy on 17/1/21. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawCube_OneStep 4 | // 5 | // Created by windy on 17/1/13. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/Class/Display/VFRedisplay.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFRedisplay.h 3 | // DrawCube 4 | // 5 | // Created by windy on 16/12/23. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol VFRedisplayDelegate 12 | 13 | - (void)updateContentsWithTimes:(NSTimeInterval)times; 14 | 15 | @end 16 | 17 | @interface VFRedisplay : NSObject 18 | 19 | @property (weak, nonatomic) id delegate; 20 | 21 | /* 22 | 帧速率,默认是 30 23 | */ 24 | @property (nonatomic) NSInteger preferredFramesPerSecond; 25 | 26 | /* 27 | 帧速率 28 | */ 29 | @property (nonatomic, readonly) NSInteger framesPerSecond; 30 | 31 | @property (nonatomic, assign) NSTimeInterval updateContentTimes; 32 | 33 | /* 34 | Time interval since properties. 35 | */ 36 | @property (nonatomic, readonly) NSTimeInterval timeSinceFirstResume; 37 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastResume; 38 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastUpdate; 39 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastDraw; 40 | 41 | - (instancetype)initWithUpdateTimes:(NSTimeInterval)updateContentTimes preferredFramesPerSecond:(NSInteger)preferredFramesPerSecond; 42 | 43 | - (void)startUpdate; 44 | - (void)pauseUpdate; 45 | - (void)endUpdate; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/Class/Shader/FragmentShader.glsl: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | varying highp vec4 v_Color; 4 | 5 | void main(void) { 6 | 7 | gl_FragColor = v_Color; 8 | 9 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/Class/Shader/VertexShader.glsl: -------------------------------------------------------------------------------- 1 | #version 100 2 | 3 | uniform mat4 u_ProjectionMat4; 4 | uniform mat4 u_ModelViewMat4; 5 | 6 | attribute vec4 a_Position; 7 | attribute vec4 a_Color; 8 | 9 | varying highp vec4 v_Color; 10 | 11 | void main(void) { 12 | 13 | v_Color = a_Color; 14 | gl_Position = u_ProjectionMat4 * u_ModelViewMat4 * a_Position; 15 | 16 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/Class/VFDrawCubeView.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFTextureDrawView.h 3 | // Texture-Part1-OneStep 4 | // 5 | // Created by windy on 17/1/6. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VFDrawCubeView : UIView 12 | 13 | - (void)update; 14 | - (void)pauseUpdate; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Texture-Part1-OneStep 4 | // 5 | // Created by windy on 17/1/6. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // Texture-Part1-OneStep 4 | // 5 | // Created by windy on 17/1/6. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFDrawCubeView.h" 12 | 13 | @interface ViewController () 14 | @property (strong, nonatomic) VFDrawCubeView *cubeView; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | CGRect cubeViewRect = self.view.bounds; 24 | self.cubeView = [[VFDrawCubeView alloc] initWithFrame:cubeViewRect]; 25 | 26 | [self.view addSubview:self.cubeView]; 27 | 28 | } 29 | 30 | - (void)viewDidAppear:(BOOL)animated { 31 | 32 | [super viewDidAppear:animated]; 33 | 34 | [self.cubeView update]; 35 | 36 | } 37 | 38 | - (void)viewWillDisappear:(BOOL)animated { 39 | 40 | [super viewWillDisappear:animated]; 41 | 42 | [self.cubeView pauseUpdate]; 43 | 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawCube_OneStep/DrawCube_OneStep/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawCube_OneStep 4 | // 5 | // Created by windy on 17/1/13. 6 | // Copyright © 2017年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DrawSquare_3DFix 4 | // 5 | // Created by windy on 16/12/23. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix/VFGLSquareView.h: -------------------------------------------------------------------------------- 1 | // 2 | // VFGLTriangleView.h 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, VertexDataMode) { 12 | VertexDataMode_VAO = 0, 13 | VertexDataMode_VBO, 14 | }; 15 | 16 | @interface VFGLSquareView : UIView 17 | 18 | - (void)setVertexMode:(VertexDataMode)vertexMode; 19 | 20 | - (void)prepareDisplay; 21 | - (void)drawAndRender; 22 | 23 | - (void)updateContentsWithSeconds:(NSTimeInterval)seconds; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DrawTriangle_OneStep 4 | // 5 | // Created by windy on 16/10/25. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "VFGLSquareView.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | CGRect rect = CGRectOffset(self.view.frame, 0, 0); 24 | VFGLSquareView *glView = [[VFGLSquareView alloc] initWithFrame:rect]; 25 | [glView setVertexMode:VertexDataMode_VBO]; 26 | 27 | [glView prepareDisplay]; 28 | [glView drawAndRender]; 29 | 30 | [glView updateContentsWithSeconds:2]; 31 | 32 | [self.view addSubview:glView]; 33 | 34 | } 35 | 36 | - (void)didReceiveMemoryWarning { 37 | [super didReceiveMemoryWarning]; 38 | // Dispose of any resources that can be recreated. 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /04-Draw3DGeometries/DrawSquare_3DFix/DrawSquare_3DFix/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DrawSquare_3DFix 4 | // 5 | // Created by windy on 16/12/23. 6 | // Copyright © 2016年 windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /05Texture X821/SketchFiles/TextureSource.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/SketchFiles/TextureSource.sketch -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/13. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/Commom/VYDisplayLoop.h: -------------------------------------------------------------------------------- 1 | // 2 | // VYDisplayLoop.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol VYDisplayLoopDelegate 12 | 13 | - (void)updateContents; 14 | 15 | @end 16 | 17 | @interface VYDisplayLoop : NSObject 18 | 19 | @property (weak, nonatomic) id delegate; 20 | 21 | /* 22 | * 1 秒内链接[显示]的帧数,默认是 30 23 | */ 24 | @property (assign, nonatomic) NSInteger preferredFramesPerSecond; 25 | 26 | /** 27 | * 帧速率 28 | */ 29 | @property (assign, nonatomic, readonly) NSTimeInterval frameRates; 30 | 31 | /* 32 | * 链接更新的各个时间间隔 33 | */ 34 | @property (nonatomic, readonly) NSTimeInterval timeSinceFirstResume; 35 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastResume; 36 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastUpdate; 37 | 38 | - (instancetype)initWithPreferredFramesPerSecond:(NSInteger)preferredFramesPerSecond; 39 | 40 | - (void)startUpdate; 41 | - (void)pauseUpdate; 42 | - (void)stopUpdate; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/Commom/VYLoadTextureImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // VYLoadTextureImage.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @import CoreGraphics; 12 | @import UIKit; 13 | 14 | @interface VYLoadTextureImage : NSObject 15 | 16 | - (NSData *)textureDataWithResizedCGImageBytes:(CGImageRef)cgImage 17 | widthPtr:(size_t *)widthPtr 18 | heightPtr:(size_t *)heightPtr; 19 | 20 | - (void)textureDataWithResizedCGImageBytes:(CGImageRef)cgImage 21 | completion:(void (^)(NSData *imageData, size_t newWidth, size_t newHeight))completionBlock; 22 | 23 | - (void)textureDatasWithResizedUIImages:(NSArray *)uiImages 24 | completion:(void (^)(NSArray *imageDatas, size_t newWidth, size_t newHeight))completionBlock; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/Commom/VYTransforms.m: -------------------------------------------------------------------------------- 1 | // 2 | // VYTransforms.m 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import "VYTransforms.h" 10 | 11 | @implementation VYTransforms 12 | 13 | - (instancetype)init { 14 | if (self = [super init]) { 15 | [self settingDefault]; 16 | } 17 | return self; 18 | } 19 | 20 | - (void)settingDefault { 21 | 22 | self.PositionVec3Make = GLKVector3Make; 23 | self.RotationVec3Make = self.PositionVec3Make; 24 | self.ScalingVec3Make = self.PositionVec3Make; 25 | 26 | self.EyeVec3Make = self.PositionVec3Make; 27 | self.CenterVec3Make = self.PositionVec3Make; 28 | self.UpVec3Make = self.PositionVec3Make; 29 | 30 | self.modelUpdate = NO; 31 | self.viewUpdate = self.modelUpdate; 32 | self.lookAtUpdate = self.modelUpdate; 33 | self.projectionUpdate = self.modelUpdate; 34 | 35 | } 36 | 37 | - (void)releaseAllVec3MakeFunPtr { 38 | 39 | Vector3Make funPtr[] = {self.PositionVec3Make, self.RotationVec3Make, self.ScalingVec3Make, 40 | self.EyeVec3Make, self.CenterVec3Make, self.UpVec3Make, NULL}; 41 | 42 | for (NSUInteger i = 0; funPtr[i] != NULL; i++) { 43 | free(funPtr[i]); 44 | } 45 | 46 | } 47 | 48 | @end 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/Shader/VYTex2DFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform sampler2D us2d_texture; 5 | 6 | varying highp vec2 v_texCoord; 7 | 8 | void main(void) { 9 | // gl_FragColor = vec4(1, 1, 0.5, 1); 10 | gl_FragColor = texture2D(us2d_texture, v_texCoord); 11 | } 12 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/Shader/VYTex2DVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform mat4 u_modelViewMat4; 5 | uniform mat4 u_projectionMat4; 6 | 7 | attribute vec4 a_position; 8 | attribute vec2 a_texCoord; 9 | 10 | varying highp vec2 v_texCoord; 11 | 12 | void main(void) { 13 | gl_Position = u_projectionMat4 * u_modelViewMat4 * a_position; 14 | v_texCoord = a_texCoord; 15 | } 16 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/Shader/VYTexCubemapFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | //ERROR: Writed To sampler2D 5 | uniform samplerCube us2d_texture; 6 | //ERROR: Writed To vec4 7 | varying highp vec3 v_normalCoord; 8 | 9 | void main(void) { 10 | // gl_FragColor = vec4(1, 1, 0.5, 1); 11 | gl_FragColor = textureCube(us2d_texture, v_normalCoord); 12 | } 13 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/Shader/VYTexCubemapVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform mat4 u_modelViewMat4; 5 | uniform mat4 u_projectionMat4; 6 | 7 | attribute vec4 a_position; 8 | //ERROR: Writed To vec4 9 | attribute vec3 a_normalCoord; 10 | //ERROR: Writed To vec4 11 | varying highp vec3 v_normalCoord; 12 | 13 | void main(void) { 14 | gl_Position = u_projectionMat4 * u_modelViewMat4 * a_position; 15 | v_normalCoord = a_normalCoord; 16 | } 17 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/128_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/128_128.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/2DCubeElong/HDR湖泊.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/2DCubeElong/HDR湖泊.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/2DCubeElong/L_768_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/2DCubeElong/L_768_512.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/2DCubeElong/Rubik's cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/2DCubeElong/Rubik's cube.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/512_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/512_512.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_01.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_02.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_03.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_04.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_05.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Classes/TextureSources/Cubemap/512_512_06.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleIdentifier 8 | $(PRODUCT_BUNDLE_IDENTIFIER) 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundleName 12 | $(PRODUCT_NAME) 13 | CFBundlePackageType 14 | APPL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleVersion 18 | 1 19 | LSRequiresIPhoneOS 20 | 21 | CFBundleExecutable 22 | $(EXECUTABLE_NAME) 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/13. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Base-OneStep/Texture-Base-OneStep/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/13. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Texture-Depth-BiuBiuBiu 4 | // 5 | // Created by Windy on 2017/2/17. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/Commom/VYDisplayLoop.h: -------------------------------------------------------------------------------- 1 | // 2 | // VYDisplayLoop.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol VYDisplayLoopDelegate 12 | 13 | - (void)updateContents; 14 | 15 | @end 16 | 17 | @interface VYDisplayLoop : NSObject 18 | 19 | @property (weak, nonatomic) id delegate; 20 | 21 | /* 22 | * 1 秒内链接[显示]的帧数,默认是 30 23 | */ 24 | @property (assign, nonatomic) NSInteger preferredFramesPerSecond; 25 | 26 | /** 27 | * 帧速率 28 | */ 29 | @property (assign, nonatomic, readonly) NSTimeInterval frameRates; 30 | 31 | /* 32 | * 链接更新的各个时间间隔 33 | */ 34 | @property (nonatomic, readonly) NSTimeInterval timeSinceFirstResume; 35 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastResume; 36 | @property (nonatomic, readonly) NSTimeInterval timeSinceLastUpdate; 37 | 38 | - (instancetype)initWithPreferredFramesPerSecond:(NSInteger)preferredFramesPerSecond; 39 | 40 | - (void)startUpdate; 41 | - (void)pauseUpdate; 42 | - (void)stopUpdate; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/Commom/VYLoadTextureImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // VYLoadTextureImage.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @import CoreGraphics; 12 | @import UIKit; 13 | 14 | @interface VYLoadTextureImage : NSObject 15 | 16 | - (NSData *)textureDataWithResizedCGImageBytes:(CGImageRef)cgImage 17 | widthPtr:(size_t *)widthPtr 18 | heightPtr:(size_t *)heightPtr; 19 | 20 | - (void)textureDataWithResizedCGImageBytes:(CGImageRef)cgImage 21 | completion:(void (^)(NSData *imageData, size_t newWidth, size_t newHeight))completionBlock; 22 | 23 | - (void)textureDatasWithResizedUIImages:(NSArray *)uiImages 24 | completion:(void (^)(NSArray *imageDatas, size_t newWidth, size_t newHeight))completionBlock; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/Commom/VYTransforms.m: -------------------------------------------------------------------------------- 1 | // 2 | // VYTransforms.m 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import "VYTransforms.h" 10 | 11 | @implementation VYTransforms 12 | 13 | - (instancetype)init { 14 | if (self = [super init]) { 15 | [self settingDefault]; 16 | } 17 | return self; 18 | } 19 | 20 | - (void)settingDefault { 21 | 22 | self.PositionVec3Make = GLKVector3Make; 23 | self.RotationVec3Make = self.PositionVec3Make; 24 | self.ScalingVec3Make = self.PositionVec3Make; 25 | 26 | self.EyeVec3Make = self.PositionVec3Make; 27 | self.CenterVec3Make = self.PositionVec3Make; 28 | self.UpVec3Make = self.PositionVec3Make; 29 | 30 | self.modelUpdate = NO; 31 | self.viewUpdate = self.modelUpdate; 32 | self.lookAtUpdate = self.modelUpdate; 33 | self.projectionUpdate = self.modelUpdate; 34 | 35 | } 36 | 37 | - (void)releaseAllVec3MakeFunPtr { 38 | 39 | Vector3Make funPtr[] = {self.PositionVec3Make, self.RotationVec3Make, self.ScalingVec3Make, 40 | self.EyeVec3Make, self.CenterVec3Make, self.UpVec3Make, NULL}; 41 | 42 | for (NSUInteger i = 0; funPtr[i] != NULL; i++) { 43 | free(funPtr[i]); 44 | } 45 | 46 | } 47 | 48 | @end 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/Shader/VYTex2DFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform sampler2D us2d_texture; 5 | 6 | varying highp vec2 v_texCoord; 7 | 8 | void main(void) { 9 | // gl_FragColor = vec4(1, 1, 0.5, 1); 10 | gl_FragColor = texture2D(us2d_texture, v_texCoord); 11 | } 12 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/Shader/VYTex2DVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform mat4 u_modelViewMat4; 5 | uniform mat4 u_projectionMat4; 6 | 7 | attribute vec4 a_position; 8 | attribute vec2 a_texCoord; 9 | 10 | varying highp vec2 v_texCoord; 11 | 12 | void main(void) { 13 | gl_Position = u_projectionMat4 * u_modelViewMat4 * a_position; 14 | v_texCoord = a_texCoord; 15 | } 16 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/Shader/VYTexCubemapFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | //ERROR: Writed To sampler2D 5 | uniform samplerCube us2d_texture; 6 | //ERROR: Writed To vec4 7 | varying highp vec3 v_normalCoord; 8 | 9 | void main(void) { 10 | // gl_FragColor = vec4(1, 1, 0.5, 1); 11 | gl_FragColor = textureCube(us2d_texture, v_normalCoord); 12 | } 13 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/Shader/VYTexCubemapVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform mat4 u_modelViewMat4; 5 | uniform mat4 u_projectionMat4; 6 | 7 | attribute vec4 a_position; 8 | //ERROR: Writed To vec4 9 | attribute vec3 a_normalCoord; 10 | //ERROR: Writed To vec4 11 | varying highp vec3 v_normalCoord; 12 | 13 | void main(void) { 14 | gl_Position = u_projectionMat4 * u_modelViewMat4 * a_position; 15 | v_normalCoord = a_normalCoord; 16 | } 17 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/128_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/128_128.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/2DCubeElong/HDR湖泊.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/2DCubeElong/HDR湖泊.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/2DCubeElong/L_768_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/2DCubeElong/L_768_512.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/2DCubeElong/Rubik's cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/2DCubeElong/Rubik's cube.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/512_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/512_512.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_01.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_02.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_03.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_04.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_05.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Classes/TextureSources/Cubemap/512_512_06.png -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/13. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /05Texture X821/Texture-Depth-BiuBiuBiu/Texture-Depth-BiuBiuBiu/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Texture-Depth-BiuBiuBiu 4 | // 5 | // Created by Windy on 2017/2/17. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Texture-OneStep-Starter 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Commom/VYTransforms.m: -------------------------------------------------------------------------------- 1 | // 2 | // VYTransforms.m 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import "VYTransforms.h" 10 | 11 | @implementation VYTransforms 12 | 13 | - (instancetype)init { 14 | if (self = [super init]) { 15 | [self settingDefault]; 16 | } 17 | return self; 18 | } 19 | 20 | - (void)settingDefault { 21 | 22 | self.PositionVec3Make = GLKVector3Make; 23 | self.RotationVec3Make = self.PositionVec3Make; 24 | self.ScalingVec3Make = self.PositionVec3Make; 25 | 26 | self.EyeVec3Make = self.PositionVec3Make; 27 | self.CenterVec3Make = self.PositionVec3Make; 28 | self.UpVec3Make = self.PositionVec3Make; 29 | 30 | } 31 | 32 | - (void)releaseAllVec3MakeFunPtr { 33 | 34 | Vector3Make funPtr[] = {self.PositionVec3Make, self.RotationVec3Make, self.ScalingVec3Make, 35 | self.EyeVec3Make, self.CenterVec3Make, self.UpVec3Make, NULL}; 36 | 37 | for (NSUInteger i = 0; funPtr[i] != NULL; i++) { 38 | free(funPtr[i]); 39 | } 40 | 41 | } 42 | 43 | @end 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Datas/TextureDatas.h: -------------------------------------------------------------------------------- 1 | // 2 | // TextureDatas.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/14. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #ifndef TextureDatas_h 10 | #define TextureDatas_h 11 | 12 | #import 13 | 14 | typedef struct { 15 | GLfloat position[3]; 16 | GLfloat texCoord[2]; 17 | }VYVertex; 18 | 19 | // MARK: Square 20 | 21 | static const VYVertex tex2DSquareDatas[] = { 22 | {{-1.0, -1.0, 0.0}, {0.0, 0.0}}, 23 | {{ 1.0, -1.0, 0.0}, {1.0, 0.0}}, 24 | {{ 1.0, 1.0, 0.0}, {1.0, 1.0}}, 25 | {{-1.0, 1.0, 0.0}, {0.0, 1.0}}, 26 | }; 27 | 28 | static const GLubyte squareIndices[] = { 29 | 0, 1, 2, 30 | 2, 3, 0, 31 | }; 32 | 33 | static const GLfloat tex2DSquarePixelDatas[] = { 34 | 255, 0.0, 255, 35 | 0.0, 255, 0.0, 36 | 255, 255, 0.0, 37 | 0.0, 255, 255, 38 | }; 39 | 40 | // MARK: Cube 41 | 42 | static const VYVertex tex2DCubeDatas[] = { 43 | 44 | }; 45 | 46 | static const GLubyte cubeIndices[] = { 47 | 48 | }; 49 | 50 | #endif /* TextureDatas_h */ 51 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Shader/VYTex2DFragmentShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform sampler2D us2d_texture; 5 | 6 | varying highp vec2 v_texCoord; 7 | 8 | void main(void) { 9 | gl_FragColor = vec4(1, 1, 0.5, 1);//texture2D(us2d_texture, v_texCoord); 10 | } 11 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Shader/VYTex2DVertexShader.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 100 3 | 4 | uniform mat4 u_modelViewMat4; 5 | uniform mat4 u_projectionMat4; 6 | 7 | attribute vec4 a_position; 8 | attribute vec2 a_texCoord; 9 | 10 | varying highp vec2 v_texCoord; 11 | 12 | void main(void) { 13 | gl_Position = u_projectionMat4 * u_modelViewMat4 * a_position; 14 | v_texCoord = a_texCoord; 15 | } 16 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Shader/VYTexCubemapFragmentShader.glsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Shader/VYTexCubemapFragmentShader.glsl -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Shader/VYTexCubemapVertexShader.glsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangwenfei/OpenGLES2Learning/7edd17187f3b12bce7b95caebd6edf9f2f5a2820/05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Classes/Shader/VYTexCubemapVertexShader.glsl -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Texture-Base-OneStep 4 | // 5 | // Created by Windy on 2017/2/13. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /05Texture X821/Texture-OneStep-Starter/Texture-OneStep-Starter/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Texture-OneStep-Starter 4 | // 5 | // Created by Windy on 2017/2/15. 6 | // Copyright © 2017年 Windy. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenGLES2Learning 2 | __ Just For Learning OpenGL ES 2 ~ ~ ~ __ 3 | --------------------------------------------------------------------------------