Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GLKBaseEffectDrawing GLKBaseEffectDrawingTexture GLKReflectionMapEffectSkybox OpenGLES20Example PerVertexDirectionalLighting
- Loading branch information
Timothy Risi
committed
Jun 19, 2013
1 parent
b7ec0be
commit 922de6e
Showing
57 changed files
with
11,830 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using MonoTouch.Foundation; | ||
using MonoTouch.UIKit; | ||
|
||
namespace GLKBaseEffectDrawing | ||
{ | ||
[Register ("AppDelegate")] | ||
public partial class AppDelegate : UIApplicationDelegate | ||
{ | ||
UIWindow window; | ||
MCViewController controller; | ||
|
||
public override bool FinishedLaunching (UIApplication app, NSDictionary options) | ||
{ | ||
window = new UIWindow (UIScreen.MainScreen.Bounds); | ||
|
||
controller = new MCViewController (); | ||
window.RootViewController = controller; | ||
|
||
window.MakeKeyAndVisible (); | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform> | ||
<ProductVersion>10.0.0</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{F17A7552-709F-4109-AFD2-FE557F0C4CD7}</ProjectGuid> | ||
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>GLKBaseEffectDrawing</RootNamespace> | ||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix> | ||
<AssemblyName>GLKBaseEffectDrawing</AssemblyName> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
<MtouchLink>None</MtouchLink> | ||
<MtouchDebug>true</MtouchDebug> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' "> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
<MtouchLink>None</MtouchLink> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\iPhone\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
<MtouchDebug>true</MtouchDebug> | ||
<CodesignKey>iPhone Developer</CodesignKey> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' "> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\iPhone\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
<CodesignKey>iPhone Developer</CodesignKey> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' "> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\iPhone\Ad-Hoc</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<BuildIpa>true</BuildIpa> | ||
<CodesignKey>iPhone Distribution</CodesignKey> | ||
<ConsolePause>false</ConsolePause> | ||
<CodesignProvision>Automatic:AdHoc</CodesignProvision> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' "> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\iPhone\AppStore</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
<CodesignKey>iPhone Distribution</CodesignKey> | ||
<CodesignProvision>Automatic:AppStore</CodesignProvision> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="monotouch" /> | ||
<Reference Include="OpenTK-1.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Folder Include="Resources\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Info.plist" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Main.cs" /> | ||
<Compile Include="AppDelegate.cs" /> | ||
<Compile Include="MCViewController.cs" /> | ||
<Compile Include="Monkey.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>UIDeviceFamily</key> | ||
<array> | ||
<integer>2</integer> | ||
</array> | ||
<key>UISupportedInterfaceOrientations~ipad</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
<key>MinimumOSVersion</key> | ||
<string>3.2</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using System; | ||
using MonoTouch.UIKit; | ||
using OpenTK; | ||
using MonoTouch.OpenGLES; | ||
using MonoTouch.GLKit; | ||
using MonoTouch; | ||
using OpenTK.Graphics.ES20; | ||
using MonoTouch.CoreGraphics; | ||
using System.Drawing; | ||
|
||
namespace GLKBaseEffectDrawing | ||
{ | ||
public class MCViewController : GLKViewController | ||
{ | ||
float rotation; | ||
uint vertexArray; | ||
uint vertexBuffer; | ||
EAGLContext context; | ||
GLKBaseEffect effect; | ||
|
||
public MCViewController () | ||
{ | ||
|
||
} | ||
|
||
public override void ViewDidLoad () | ||
{ | ||
base.ViewDidLoad (); | ||
|
||
context = new EAGLContext (EAGLRenderingAPI.OpenGLES2); | ||
|
||
if (context == null) | ||
Console.WriteLine ("Failed to create ES context"); | ||
|
||
GLKView view = View as GLKView; | ||
view.Context = context; | ||
view.DrawableDepthFormat = GLKViewDrawableDepthFormat.Format24; | ||
view.DrawInRect += Draw; | ||
|
||
setupGL (); | ||
} | ||
|
||
void setupGL () | ||
{ | ||
EAGLContext.SetCurrentContext (context); | ||
|
||
effect = new GLKBaseEffect (); | ||
effect.LightingType = GLKLightingType.PerPixel; | ||
|
||
effect.Light0.Enabled = true; | ||
effect.Light0.DiffuseColor = new Vector4 (1.0f, 0.4f, 0.4f, 1.0f); | ||
effect.Light0.Position = new Vector4 (-5f, -5f, 10f, 1f); | ||
effect.Light0.SpecularColor = new Vector4 (1f, 0f, 0f, 1f); | ||
|
||
effect.Light1.Enabled = true; | ||
effect.Light1.DiffuseColor = new Vector4 (1f, 0.4f, 0.4f, 1f); | ||
effect.Light1.Position = new Vector4 (15f, 15f, 10f, 1f); | ||
effect.Light1.SpecularColor = new Vector4 (1f, 0f, 0f, 1f); | ||
|
||
effect.Material.DiffuseColor = new Vector4 (0f, 0.5f, 1f, 1f); | ||
effect.Material.AmbientColor = new Vector4 (0f, 0.5f, 0f, 1f); | ||
effect.Material.SpecularColor = new Vector4 (1f, 0f, 0f, 1f); | ||
effect.Material.Shininess = 20f; | ||
effect.Material.EmissiveColor = new Vector4 (0.2f, 0f, 0.2f, 1f); | ||
|
||
GL.Enable (EnableCap.DepthTest); | ||
|
||
GL.Oes.GenVertexArrays (1, out vertexArray); | ||
GL.Oes.BindVertexArray (vertexArray); | ||
|
||
GL.GenBuffers (1, out vertexBuffer); | ||
GL.BindBuffer (BufferTarget.ArrayBuffer, vertexBuffer); | ||
GL.BufferData (BufferTarget.ArrayBuffer, (IntPtr)(Monkey.MeshVertexData.Length * sizeof(float)), | ||
Monkey.MeshVertexData, BufferUsage.StaticDraw); | ||
|
||
GL.EnableVertexAttribArray ((int) GLKVertexAttrib.Position); | ||
GL.VertexAttribPointer ((int) GLKVertexAttrib.Position, 3, VertexAttribPointerType.Float, | ||
false, 6 * sizeof(float), 0); | ||
|
||
GL.EnableVertexAttribArray ((int) GLKVertexAttrib.Normal); | ||
GL.VertexAttribPointer ((int) GLKVertexAttrib.Normal, 3, VertexAttribPointerType.Float, | ||
false, 6 * sizeof(float), 12); | ||
|
||
GL.Oes.BindVertexArray (0); | ||
} | ||
|
||
public override void Update () | ||
{ | ||
float aspect = (float)Math.Abs (View.Bounds.Size.Width / View.Bounds.Size.Height); | ||
|
||
Matrix4 projectionMatrix = | ||
Matrix4.CreatePerspectiveFieldOfView ((float) (Math.PI * 65f / 180.0f), | ||
aspect, 0.1f, 100.0f); | ||
|
||
effect.Transform.ProjectionMatrix = projectionMatrix; | ||
|
||
Matrix4 modelViewMatrix = Matrix4.CreateTranslation (new Vector3 (0f, 0f, -3.5f)); | ||
modelViewMatrix = Matrix4.Mult (Matrix4.CreateFromAxisAngle (new Vector3 (1f, 1f, 1f), rotation), modelViewMatrix); | ||
|
||
effect.Transform.ModelViewMatrix = modelViewMatrix; | ||
|
||
rotation += (float)TimeSinceLastUpdate * 0.5f; | ||
} | ||
|
||
public void Draw (object sender, GLKViewDrawEventArgs args) | ||
{ | ||
GL.ClearColor (0.65f, 0.65f, 0.65f, 1f); | ||
GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); | ||
|
||
GL.Oes.BindVertexArray (vertexArray); | ||
|
||
effect.PrepareToDraw (); | ||
|
||
GL.DrawArrays (BeginMode.Triangles, 0, Monkey.MeshVertexData.Length / 6); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using MonoTouch.Foundation; | ||
using MonoTouch.UIKit; | ||
|
||
namespace GLKBaseEffectDrawing | ||
{ | ||
public class Application | ||
{ | ||
// This is the main entry point of the application. | ||
static void Main (string[] args) | ||
{ | ||
// if you want to use a different Application Delegate class from "AppDelegate" | ||
// you can specify it here. | ||
UIApplication.Main (args, null, "AppDelegate"); | ||
} | ||
} | ||
} |
Oops, something went wrong.