Skip to content

Commit ed06504

Browse files
committed
Minor improvements to FBO example
1 parent 73cad44 commit ed06504

7 files changed

Lines changed: 217 additions & 29 deletions

File tree

OpenTK_RTExample/OpenTK_RTExample/Camera.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using OpenTK;
22
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
63

74
namespace OpenTK_RTExample
85
{
@@ -16,11 +13,13 @@ class Camera
1613

1714
public Matrix4 GetViewMatrix()
1815
{
19-
Vector3 lookat = new Vector3();
16+
Vector3 lookat = new Vector3
17+
{
18+
X = (float) (Math.Sin(Orientation.X)*Math.Cos(Orientation.Y)),
19+
Y = (float) Math.Sin(Orientation.Y),
20+
Z = (float) (Math.Cos(Orientation.X)*Math.Cos(Orientation.Y))
21+
};
2022

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));
2423

2524
return Matrix4.LookAt(Position, Position + lookat, UpVector);
2625
}

OpenTK_RTExample/OpenTK_RTExample/Game.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ private void setupScreen()
124124
GL.BindFramebuffer(FramebufferTarget.FramebufferExt, fbo_screen);
125125
GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, textures["screen"], 0); // Color info goes into a texture
126126
GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, textures["screendepth"], 0); // Depth info goes into a texture
127+
128+
// Check for error
129+
FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.FramebufferExt);
130+
if (status != FramebufferErrorCode.FramebufferComplete &&
131+
status != FramebufferErrorCode.FramebufferCompleteExt)
132+
{
133+
Console.WriteLine("Error creating framebuffer: {0}", status);
134+
}
135+
127136
}
128137

129138
private void initScene()
@@ -189,6 +198,7 @@ private void initScene()
189198
private void loadResources()
190199
{
191200
// Create shaders
201+
shaders.Add("default", new ShaderProgram("vs.glsl", "fs.glsl", true));
192202
shaders.Add("lit_advanced", new ShaderProgram("vs_lit.glsl", "fs_lit_advanced.glsl", true));
193203
shaders.Add("screen", new ShaderProgram("vs_lit.glsl", "fs_lit_advanced_screen.glsl", true));
194204

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>OpenTK_RTExample</RootNamespace>
12+
<AssemblyName>OpenTK_RTExample</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
15+
<FileAlignment>512</FileAlignment>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18+
<PlatformTarget>x86</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
<Prefer32Bit>false</Prefer32Bit>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
29+
<PlatformTarget>x86</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
<Prefer32Bit>false</Prefer32Bit>
37+
</PropertyGroup>
38+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
39+
<DebugSymbols>true</DebugSymbols>
40+
<OutputPath>bin\x64\Debug\</OutputPath>
41+
<DefineConstants>DEBUG;TRACE</DefineConstants>
42+
<DebugType>full</DebugType>
43+
<PlatformTarget>x64</PlatformTarget>
44+
<ErrorReport>prompt</ErrorReport>
45+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
46+
<Prefer32Bit>false</Prefer32Bit>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
49+
<OutputPath>bin\x64\Release\</OutputPath>
50+
<DefineConstants>TRACE</DefineConstants>
51+
<Optimize>true</Optimize>
52+
<DebugType>pdbonly</DebugType>
53+
<PlatformTarget>x64</PlatformTarget>
54+
<ErrorReport>prompt</ErrorReport>
55+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
56+
<Prefer32Bit>false</Prefer32Bit>
57+
</PropertyGroup>
58+
<PropertyGroup>
59+
<StartupObject>OpenTK_RTExample.Program</StartupObject>
60+
</PropertyGroup>
61+
<ItemGroup>
62+
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
63+
<HintPath>..\packages\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>
64+
<Private>True</Private>
65+
</Reference>
66+
<Reference Include="System" />
67+
<Reference Include="System.Core" />
68+
<Reference Include="System.Drawing" />
69+
<Reference Include="System.Windows.Forms" />
70+
<Reference Include="System.Xml.Linq" />
71+
<Reference Include="System.Data.DataSetExtensions" />
72+
<Reference Include="Microsoft.CSharp" />
73+
<Reference Include="System.Data" />
74+
<Reference Include="System.Xml" />
75+
</ItemGroup>
76+
<ItemGroup>
77+
<Compile Include="Camera.cs" />
78+
<Compile Include="Cube.cs" />
79+
<Compile Include="Game.cs" />
80+
<Compile Include="Light.cs" />
81+
<Compile Include="Material.cs" />
82+
<Compile Include="ObjVolume.cs" />
83+
<Compile Include="Program.cs" />
84+
<Compile Include="Properties\AssemblyInfo.cs" />
85+
<Compile Include="ShaderProgram.cs" />
86+
<Compile Include="TexturedCube.cs" />
87+
<Compile Include="Volume.cs" />
88+
</ItemGroup>
89+
<ItemGroup>
90+
<None Include="app.config" />
91+
<None Include="arrow.obj">
92+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
93+
</None>
94+
<None Include="earth.mtl">
95+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
96+
</None>
97+
<None Include="fs_lit_advanced_screen.glsl">
98+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
99+
</None>
100+
<None Include="fs_lit_multiple.glsl">
101+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
102+
</None>
103+
<None Include="OpenTK.dll.config" />
104+
<None Include="packages.config" />
105+
<None Include="tv.mtl">
106+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
107+
</None>
108+
<None Include="tv.obj">
109+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
110+
</None>
111+
<None Include="tvscreen.mtl">
112+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
113+
</None>
114+
<None Include="tvscreen.obj">
115+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
116+
</None>
117+
<None Include="vs_lit_multiple.glsl">
118+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
119+
</None>
120+
<None Include="vs_lit_advanced.glsl">
121+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
122+
</None>
123+
<None Include="fs_lit_advanced.glsl">
124+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
125+
</None>
126+
<None Include="cubedie.mtl">
127+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
128+
</None>
129+
<None Include="cubedie.obj">
130+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
131+
</None>
132+
<None Include="earth.obj">
133+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
134+
</None>
135+
<None Include="fs_lit.glsl">
136+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
137+
</None>
138+
<None Include="fs_norm.glsl">
139+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
140+
</None>
141+
<None Include="fs_tex.glsl">
142+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
143+
</None>
144+
<None Include="sphere.obj">
145+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
146+
</None>
147+
<None Include="vs_lit.glsl">
148+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
149+
</None>
150+
<None Include="vs_norm.glsl">
151+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
152+
</None>
153+
<None Include="vs_tex.glsl">
154+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
155+
</None>
156+
<None Include="fs.glsl">
157+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
158+
</None>
159+
<None Include="vs.glsl">
160+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
161+
</None>
162+
</ItemGroup>
163+
<ItemGroup>
164+
<Content Include="blank.png">
165+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
166+
</Content>
167+
<Content Include="cubedie.png">
168+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
169+
</Content>
170+
<Content Include="earth.png">
171+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
172+
</Content>
173+
<Content Include="earthspec.png">
174+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
175+
</Content>
176+
<Content Include="opentksquare.png">
177+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
178+
</Content>
179+
<Content Include="opentksquare2.png">
180+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
181+
</Content>
182+
<Content Include="planet.png">
183+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
184+
</Content>
185+
<Content Include="tvtexture.png">
186+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
187+
</Content>
188+
</ItemGroup>
189+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
190+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
191+
Other similar extension points exist, see Microsoft.Common.targets.
192+
<Target Name="BeforeBuild">
193+
</Target>
194+
<Target Name="AfterBuild">
195+
</Target>
196+
-->
197+
</Project>

OpenTK_RTExample/OpenTK_RTExample/Program.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Windows.Forms;
6-
7-
namespace OpenTK_RTExample
1+
namespace OpenTK_RTExample
82
{
93
class Program
104
{

OpenTK_RTExample/OpenTK_RTExample/ShaderProgram.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public ShaderProgram(String vshader, String fshader, bool fromFile = false)
4040
}
4141

4242
Link();
43-
GL.UseProgram(ProgramID);
4443
GenBuffers();
4544
}
4645

@@ -84,10 +83,10 @@ public void LoadShaderFromFile(String filename, ShaderType type)
8483
public void Link()
8584
{
8685
GL.LinkProgram(ProgramID);
86+
GL.UseProgram(ProgramID);
8787

8888
Console.WriteLine(GL.GetProgramInfoLog(ProgramID));
89-
90-
89+
9190
GL.GetProgram(ProgramID, GetProgramParameterName.ActiveAttributes, out AttributeCount);
9291
GL.GetProgram(ProgramID, GetProgramParameterName.ActiveUniforms, out UniformCount);
9392

@@ -103,7 +102,6 @@ public void Link()
103102
info.name = name.ToString();
104103
info.address = GL.GetAttribLocation(ProgramID, info.name);
105104
Attributes.Add(name.ToString(), info);
106-
//Console.WriteLine(name + " " + info.address);
107105
}
108106

109107
for (int i = 0; i < UniformCount; i++)
@@ -118,7 +116,6 @@ public void Link()
118116
info.name = name.ToString();
119117
Uniforms.Add(name.ToString(), info);
120118
info.address = GL.GetUniformLocation(ProgramID, info.name);
121-
//Console.WriteLine(name + " " + info.address);
122119
}
123120
}
124121

OpenTK_RTExample/OpenTK_RTExample/TexturedCube.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
using OpenTK;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
62

73
namespace OpenTK_RTExample
84
{
95
class TexturedCube : Cube
106
{
117
public TexturedCube()
12-
: base()
138
{
149
VertCount = 24;
1510
IndiceCount = 36;

OpenTK_RTExample/OpenTK_RTExample/Volume.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using OpenTK;
1+
using OpenTK;
62

73
namespace OpenTK_RTExample
84
{

0 commit comments

Comments
 (0)