Skip to content

Commit d7cc965

Browse files
committed
[GLTriangle30] OpenTK 3.0 version of GLTriangle
1 parent 0252711 commit d7cc965

File tree

27 files changed

+652
-0
lines changed

27 files changed

+652
-0
lines changed

GLTriangle30/GLTriangle30.csproj

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{73A74ADF-6308-42A0-8BA6-2B5D53238546}</ProjectGuid>
9+
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>Mono.Samples.GLTriangle30</RootNamespace>
13+
<AssemblyName>GLTriangle20</AssemblyName>
14+
<FileAlignment>512</FileAlignment>
15+
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
16+
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
17+
<AndroidApplication>true</AndroidApplication>
18+
<TargetFrameworkVersion>v4.2</TargetFrameworkVersion>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>True</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>False</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
<MonoDroidLinkMode>None</MonoDroidLinkMode>
29+
<AndroidLinkMode>None</AndroidLinkMode>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>True</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
39+
<MonoDroidLinkMode>Full</MonoDroidLinkMode>
40+
</PropertyGroup>
41+
<ItemGroup>
42+
<Reference Include="Mono.Android" />
43+
<Reference Include="System" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="OpenTK" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="PaintingView.cs" />
49+
<Compile Include="Resources\Resource.Designer.cs" />
50+
<Compile Include="GLTriangle30Activity.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<None Include="Properties\AndroidManifest.xml">
54+
<SubType>Designer</SubType>
55+
</None>
56+
</ItemGroup>
57+
<ItemGroup>
58+
<AndroidResource Include="Resources\drawable\app_gltriangle.png" />
59+
<AndroidResource Include="Resources\layout\main.xml" />
60+
<AndroidResource Include="Resources\values\strings.xml">
61+
<SubType>Designer</SubType>
62+
</AndroidResource>
63+
<AndroidResource Include="Resources\drawable-hdpi\icon.png" />
64+
<AndroidResource Include="Resources\drawable-ldpi\icon.png" />
65+
<AndroidResource Include="Resources\drawable-mdpi\icon.png" />
66+
<AndroidResource Include="Resources\drawable-xhdpi\icon.png" />
67+
<AndroidResource Include="Resources\drawable-xxhdpi\icon.png" />
68+
</ItemGroup>
69+
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
70+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
71+
Other similar extension points exist, see Microsoft.Common.targets.
72+
<Target Name="BeforeBuild">
73+
</Target>
74+
<Target Name="AfterBuild">
75+
</Target>
76+
-->
77+
<ItemGroup>
78+
<Folder Include="Resources\drawable-hdpi\" />
79+
<Folder Include="Resources\drawable-ldpi\" />
80+
<Folder Include="Resources\drawable-mdpi\" />
81+
<Folder Include="Resources\drawable-xhdpi\" />
82+
<Folder Include="Resources\drawable-xxhdpi\" />
83+
</ItemGroup>
84+
</Project>

GLTriangle30/GLTriangle30.sln

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GLTriangle30", "GLTriangle30.csproj", "{73A74ADF-6308-42A0-8BA6-2B5D53238546}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{73A74ADF-6308-42A0-8BA6-2B5D53238546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{73A74ADF-6308-42A0-8BA6-2B5D53238546}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{73A74ADF-6308-42A0-8BA6-2B5D53238546}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{73A74ADF-6308-42A0-8BA6-2B5D53238546}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(MonoDevelopProperties) = preSolution
18+
StartupItem = GLTriangle30.csproj
19+
EndGlobalSection
20+
GlobalSection(SolutionProperties) = preSolution
21+
HideSolutionNode = FALSE
22+
EndGlobalSection
23+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");

GLTriangle30/GLTriangle30/GLView1.cs

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using OpenTK;
3+
using OpenTK.Graphics;
4+
using OpenTK.Graphics.ES11;
5+
using OpenTK.Platform;
6+
using OpenTK.Platform.Android;
7+
using Android.Views;
8+
using Android.Content;
9+
using Android.Util;
10+
11+
namespace GLTriangle30
12+
{
13+
class GLView1 : AndroidGameView
14+
{
15+
public GLView1 (Context context) : base (context)
16+
{
17+
}
18+
// This gets called when the drawing surface is ready
19+
protected override void OnLoad (EventArgs e)
20+
{
21+
base.OnLoad (e);
22+
23+
// Run the render loop
24+
Run ();
25+
}
26+
// This method is called everytime the context needs
27+
// to be recreated. Use it to set any egl-specific settings
28+
// prior to context creation
29+
//
30+
// In this particular case, we demonstrate how to set
31+
// the graphics mode and fallback in case the device doesn't
32+
// support the defaults
33+
protected override void CreateFrameBuffer ()
34+
{
35+
// the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
36+
try {
37+
Log.Verbose ("GLCube", "Loading with default settings");
38+
39+
// if you don't call this, the context won't be created
40+
base.CreateFrameBuffer ();
41+
return;
42+
} catch (Exception ex) {
43+
Log.Verbose ("GLCube", "{0}", ex);
44+
}
45+
46+
// this is a graphics setting that sets everything to the lowest mode possible so
47+
// the device returns a reliable graphics setting.
48+
try {
49+
Log.Verbose ("GLCube", "Loading with custom Android settings (low mode)");
50+
GraphicsMode = new AndroidGraphicsMode (0, 0, 0, 0, 0, false);
51+
52+
// if you don't call this, the context won't be created
53+
base.CreateFrameBuffer ();
54+
return;
55+
} catch (Exception ex) {
56+
Log.Verbose ("GLCube", "{0}", ex);
57+
}
58+
throw new Exception ("Can't load egl, aborting");
59+
}
60+
// This gets called on each frame render
61+
protected override void OnRenderFrame (FrameEventArgs e)
62+
{
63+
// you only need to call this if you have delegates
64+
// registered that you want to have called
65+
base.OnRenderFrame (e);
66+
67+
GL.MatrixMode (All.Projection);
68+
GL.LoadIdentity ();
69+
GL.Ortho (-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
70+
GL.MatrixMode (All.Modelview);
71+
GL.Rotate (3.0f, 0.0f, 0.0f, 1.0f);
72+
73+
GL.ClearColor (0.5f, 0.5f, 0.5f, 1.0f);
74+
GL.Clear (ClearBufferMask.ColorBufferBit);
75+
76+
GL.VertexPointer (2, All.Float, 0, square_vertices);
77+
GL.EnableClientState (All.VertexArray);
78+
GL.ColorPointer (4, All.UnsignedByte, 0, square_colors);
79+
GL.EnableClientState (All.ColorArray);
80+
81+
GL.DrawArrays (All.TriangleStrip, 0, 4);
82+
83+
SwapBuffers ();
84+
}
85+
86+
float[] square_vertices = {
87+
-0.5f, -0.5f,
88+
0.5f, -0.5f,
89+
-0.5f, 0.5f,
90+
0.5f, 0.5f,
91+
};
92+
byte[] square_colors = {
93+
255, 255, 0, 255,
94+
0, 255, 255, 255,
95+
0, 0, 0, 0,
96+
255, 0, 255, 255,
97+
};
98+
}
99+
}
100+
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using Android.App;
3+
using Android.Content;
4+
using Android.Runtime;
5+
using Android.Views;
6+
using Android.Widget;
7+
using Android.OS;
8+
using Android.Content.PM;
9+
10+
namespace GLTriangle30
11+
{
12+
// the ConfigurationChanges flags set here keep the EGL context
13+
// from being destroyed whenever the device is rotated or the
14+
// keyboard is shown (highly recommended for all GL apps)
15+
[Activity (Label = "GLTriangle30",
16+
#if __ANDROID_11__
17+
HardwareAccelerated=false,
18+
#endif
19+
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
20+
MainLauncher = true)]
21+
public class MainActivity : Activity
22+
{
23+
GLView1 view;
24+
25+
protected override void OnCreate (Bundle bundle)
26+
{
27+
base.OnCreate (bundle);
28+
29+
// Create our OpenGL view, and display it
30+
view = new GLView1 (this);
31+
SetContentView (view);
32+
}
33+
34+
protected override void OnPause ()
35+
{
36+
// never forget to do this!
37+
base.OnPause ();
38+
view.Pause ();
39+
}
40+
41+
protected override void OnResume ()
42+
{
43+
// never forget to do this!
44+
base.OnResume ();
45+
view.Resume ();
46+
}
47+
}
48+
}
49+
50+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using Android.App;
4+
5+
// Information about this assembly is defined by the following attributes.
6+
// Change them to the values specific to your project.
7+
[assembly: AssemblyTitle ("GLTriangle30")]
8+
[assembly: AssemblyDescription ("")]
9+
[assembly: AssemblyConfiguration ("")]
10+
[assembly: AssemblyCompany ("")]
11+
[assembly: AssemblyProduct ("")]
12+
[assembly: AssemblyCopyright ("mak")]
13+
[assembly: AssemblyTrademark ("")]
14+
[assembly: AssemblyCulture ("")]
15+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
16+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
17+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
18+
[assembly: AssemblyVersion ("1.0.0")]
19+
// The following attributes are used to specify the signing key for the assembly,
20+
// if desired. See the Mono documentation for more information about signing.
21+
//[assembly: AssemblyDelaySign(false)]
22+
//[assembly: AssemblyKeyFile("")]
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.axml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable/
12+
icon.png
13+
14+
layout/
15+
main.axml
16+
17+
values/
18+
strings.xml
19+
20+
In order to get the build system to recognize Android resources, set the build action to
21+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
22+
instead operate on resource IDs. When you compile an Android application that uses resources,
23+
the build system will package the resources for distribution and generate a class called "R"
24+
(this is an Android convention) that contains the tokens for each one of the resources
25+
included. For example, for the above Resources layout, this is what the R class would expose:
26+
27+
public class R {
28+
public class drawable {
29+
public const int icon = 0x123;
30+
}
31+
32+
public class layout {
33+
public const int main = 0x456;
34+
}
35+
36+
public class strings {
37+
public const int first_string = 0xabc;
38+
public const int second_string = 0xbcd;
39+
}
40+
}
41+
42+
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main
43+
to reference the layout/main.axml file, or R.strings.first_string to reference the first
44+
string in the dictionary file values/strings.xml.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent"
6+
>
7+
</LinearLayout>
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="app_name">GLTriangle30</string>
4+
</resources>

GLTriangle30/GLTriangle30Activity.cs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
3+
using Android.App;
4+
using Android.OS;
5+
using Android.Util;
6+
using Android.Views;
7+
using Android.Widget;
8+
using Android.Content.PM;
9+
10+
namespace Mono.Samples.GLTriangle30
11+
{
12+
[Activity (Label = "@string/app_name", MainLauncher = true, Icon = "@drawable/app_gltriangle",
13+
#if __ANDROID_11__
14+
HardwareAccelerated=false,
15+
#endif
16+
ConfigurationChanges = ConfigChanges.KeyboardHidden, LaunchMode = LaunchMode.SingleTask)]
17+
public class GLTriangle30Activity : Activity
18+
{
19+
protected override void OnCreate (Bundle savedInstanceState)
20+
{
21+
base.OnCreate (savedInstanceState);
22+
23+
// Inflate our UI from its XML layout description
24+
// - should match filename res/layout/main.xml ?
25+
SetContentView (Resource.Layout.main);
26+
27+
// Load the view
28+
FindViewById (Resource.Id.paintingview);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)