Skip to content

Commit 73cad44

Browse files
committed
FBO/Render Target Example
1 parent ec8a108 commit 73cad44

46 files changed

Lines changed: 11291 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK_RTExample", "OpenTK_RTExample\OpenTK_RTExample.csproj", "{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x64.ActiveCfg = Debug|x64
17+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x64.Build.0 = Debug|x64
18+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x86.ActiveCfg = Debug|x86
19+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x86.Build.0 = Debug|x86
20+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x64.ActiveCfg = Release|x64
21+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x64.Build.0 = Release|x64
22+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x86.ActiveCfg = Release|x86
23+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x86.Build.0 = Release|x86
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using OpenTK;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace OpenTK_RTExample
8+
{
9+
class Camera
10+
{
11+
public Vector3 Position = Vector3.Zero;
12+
public Vector3 Orientation = new Vector3((float)Math.PI, 0f, 0f);
13+
public float MoveSpeed = 0.2f;
14+
public float MouseSensitivity = 0.01f;
15+
public Vector3 UpVector = Vector3.UnitY;
16+
17+
public Matrix4 GetViewMatrix()
18+
{
19+
Vector3 lookat = new Vector3();
20+
21+
lookat.X = (float)(Math.Sin((float)Orientation.X) * Math.Cos((float)Orientation.Y));
22+
lookat.Y = (float)Math.Sin((float)Orientation.Y);
23+
lookat.Z = (float)(Math.Cos((float)Orientation.X) * Math.Cos((float)Orientation.Y));
24+
25+
return Matrix4.LookAt(Position, Position + lookat, UpVector);
26+
}
27+
28+
public void Move(float x, float y, float z)
29+
{
30+
Vector3 offset = new Vector3();
31+
32+
Vector3 forward = new Vector3((float)Math.Sin((float)Orientation.X), 0, (float)Math.Cos((float)Orientation.X));
33+
Vector3 right = new Vector3(-forward.Z, 0, forward.X);
34+
35+
offset += x * right;
36+
offset += y * forward;
37+
offset.Y += z;
38+
39+
offset.NormalizeFast();
40+
offset = Vector3.Multiply(offset, MoveSpeed);
41+
42+
Position += offset;
43+
}
44+
45+
public void AddRotation(float x, float y)
46+
{
47+
x = x * MouseSensitivity;
48+
y = y * MouseSensitivity;
49+
50+
Orientation.X = (Orientation.X + x) % ((float)Math.PI * 2.0f);
51+
Orientation.Y = Math.Max(Math.Min(Orientation.Y + y, (float)Math.PI / 2.0f - 0.1f), (float)-Math.PI / 2.0f + 0.1f);
52+
}
53+
}
54+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using OpenTK;
3+
4+
namespace OpenTK_RTExample
5+
{
6+
class Cube : Volume
7+
{
8+
public Cube()
9+
{
10+
VertCount = 8;
11+
IndiceCount = 36;
12+
ColorDataCount = 8;
13+
}
14+
15+
public override Vector3[] GetVerts()
16+
{
17+
return new Vector3[] {new Vector3(-0.5f, -0.5f, -0.5f),
18+
new Vector3(0.5f, -0.5f, -0.5f),
19+
new Vector3(0.5f, 0.5f, -0.5f),
20+
new Vector3(-0.5f, 0.5f, -0.5f),
21+
new Vector3(-0.5f, -0.5f, 0.5f),
22+
new Vector3(0.5f, -0.5f, 0.5f),
23+
new Vector3(0.5f, 0.5f, 0.5f),
24+
new Vector3(-0.5f, 0.5f, 0.5f),
25+
};
26+
}
27+
28+
public override int[] GetIndices(int offset = 0)
29+
{
30+
int[] inds = new int[] {
31+
//left
32+
0, 2, 1,
33+
0, 3, 2,
34+
//back
35+
1, 2, 6,
36+
6, 5, 1,
37+
//right
38+
4, 5, 6,
39+
6, 7, 4,
40+
//top
41+
2, 3, 6,
42+
6, 3, 7,
43+
//front
44+
0, 7, 3,
45+
0, 4, 7,
46+
//bottom
47+
0, 1, 5,
48+
0, 5, 4
49+
};
50+
51+
if (offset != 0)
52+
{
53+
for (int i = 0; i < inds.Length; i++)
54+
{
55+
inds[i] += offset;
56+
}
57+
}
58+
59+
return inds;
60+
}
61+
62+
public override Vector3[] GetColorData()
63+
{
64+
Random r = new Random(42);
65+
66+
Vector3[] colors = new Vector3[VertCount];
67+
68+
for (int i = 0; i < colors.Length; i++)
69+
{
70+
colors[i] = new Vector3((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble());
71+
}
72+
73+
return colors;
74+
}
75+
76+
public override void CalculateModelMatrix()
77+
{
78+
ModelMatrix = Matrix4.CreateScale(Scale) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position);
79+
}
80+
81+
public override Vector2[] GetTextureCoords()
82+
{
83+
return new Vector2[] { };
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)