Skip to content

Commit

Permalink
OpenTK version
Browse files Browse the repository at this point in the history
  • Loading branch information
nikvoronin committed Jan 13, 2019
1 parent 730fb75 commit ac42fc5
Show file tree
Hide file tree
Showing 12 changed files with 598 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# .oO@ ClooToOpenGL @Oo.

Live rendering of Mandelbrot fractal with help of .NET, Cloo and SharpGL. Actually, collaboration of OpenCL and OpenGL.
Live rendering of Mandelbrot fractal with help of .NET, Cloo and OpenTK/SharpGL. Actually, collaboration of OpenCL and OpenGL.

![cloo2opengl_v11](https://cloud.githubusercontent.com/assets/11328666/20339873/ceb54ac6-abef-11e6-9663-ff9e42c66538.png)

Expand Down
23 changes: 21 additions & 2 deletions src/ClooToOpenGL.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClooToOpenGL", "ClooToOpenGL\ClooToOpenGL.csproj", "{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClooToOpenTK", "ClooToOpenTK\ClooToOpenTK.csproj", "{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Debug|x86.ActiveCfg = Debug|Any CPU
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Debug|x86.Build.0 = Debug|Any CPU
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Release|Any CPU.Build.0 = Release|Any CPU
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Release|x86.ActiveCfg = Release|Any CPU
{6CB8FB90-2B29-4D3D-BBD1-638FD9E74B79}.Release|x86.Build.0 = Release|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Debug|x86.ActiveCfg = Debug|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Debug|x86.Build.0 = Debug|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Release|Any CPU.Build.0 = Release|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Release|x86.ActiveCfg = Release|Any CPU
{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {420A1BB7-9D79-4B90-8E9D-3E8A994C1731}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions src/ClooToOpenTK/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
61 changes: 61 additions & 0 deletions src/ClooToOpenTK/ClooToOpenTK.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{68283EE8-6F5E-4D85-A2F7-7E86529BC6B9}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ClooToOpenTK</RootNamespace>
<AssemblyName>ClooToOpenTK</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\</OutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cloo.clSharp, Version=0.9.2.7, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Cloo.clSharp.0.9.2.7\lib\net20\Cloo.clSharp.dll</HintPath>
</Reference>
<Reference Include="OpenTK, Version=3.0.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\packages\OpenTK.3.0.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Const.cs" />
<Compile Include="MainWindow.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Render.cs" />
<Compile Include="TypeDef.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
19 changes: 19 additions & 0 deletions src/ClooToOpenTK/Const.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using OpenTK.Input;

namespace ClooToOpenTK
{
public static class Const
{
public const string APP_NAME = "Cloo to OpenTK";
public const string RELEASE_DATE = "13 Jan 2019";

public const string KERNEL_FILENAME = "kernels/Mandelbrot.c";

public const int DISPLAY_BITPERPIXEL = 32;
public const int DISPLAY_REFRESH_RATE = 60;
public const int DISPLAY_FULLHD_W = 1920;
public const int DISPLAY_FULLHD_H = 1080;
public const int DISPLAY_XGA_W = 1024;
public const int DISPLAY_XGA_H = 768;
}
}
181 changes: 181 additions & 0 deletions src/ClooToOpenTK/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
using OpenTK;
using OpenTK.Graphics.OpenGL;
using OpenTK.Input;
using System;

namespace ClooToOpenTK
{
public class MainWindow : GameWindow
{
Render cloo;

public MainWindow()
{
Title = Const.APP_NAME;
VSync = VSyncMode.Off;
Width = Const.DISPLAY_XGA_W;
Height = Const.DISPLAY_XGA_H;

KeyUp += MainWindow_KeyUp;
KeyDown += MainWindow_KeyDown;
MouseWheel += MainWindow_MouseWheel;
MouseUp += MainWindow_MouseUp;
}

private void MainWindow_KeyDown(object sender, KeyboardKeyEventArgs e)
{
switch (e.Key)
{
case Key.Up:
cloo.maxIter += e.Shift ? 10u : 1u;
break;
case Key.Down:
if (e.Shift)
{
if (cloo.maxIter > 10)
cloo.maxIter -= 10;
}
else
{
if (cloo.maxIter > 1)
cloo.maxIter--;
}
break;
}
}

private void MainWindow_KeyUp(object sender, KeyboardKeyEventArgs e)
{
switch (e.Key)
{
case Key.Escape:
Exit();
break;
case Key.F11:
ToggleFullscreen();
break;
}
}

private void ToggleFullscreen()
{
DisplayDevice defaultDisplayDevice = DisplayDevice.GetDisplay(DisplayIndex.Default);

if (WindowState == WindowState.Fullscreen)
{
WindowState = WindowState.Normal;
CursorVisible = true;
defaultDisplayDevice.RestoreResolution();
}
else
{
WindowState = WindowState.Fullscreen;
CursorVisible = false;
defaultDisplayDevice
.ChangeResolution(
Const.DISPLAY_FULLHD_W, Const.DISPLAY_FULLHD_H,
Const.DISPLAY_BITPERPIXEL,
Const.DISPLAY_REFRESH_RATE);
}
}

private void MainWindow_MouseUp(object sender, MouseButtonEventArgs e)
{
float dx = ((float)e.X / Width - 0.5f) * 2.0f;
float dy = ((float)e.Y / Height - 0.5f) * 2.0f;

float lx2 = Math.Abs(cloo.reMax - cloo.reMin) / 2.0f * dx;
float ly2 = Math.Abs(cloo.imMax - cloo.imMin) / 2.0f * dy;
cloo.reMin += lx2;
cloo.reMax += lx2;
cloo.imMin += ly2;
cloo.imMax += ly2;
}

private void MainWindow_MouseWheel(object sender, MouseWheelEventArgs e)
{
// positive Delta - zoom in
// negative Delta - zoom out
float ax = Math.Abs(cloo.reMax - cloo.reMin) * (e.Delta > 0 ? -0.1f : 0.1f);
float ay = Math.Abs(cloo.imMax - cloo.imMin) * (e.Delta > 0 ? -0.1f : 0.1f);

cloo.reMin -= ax;
cloo.reMax += ax;
cloo.imMin -= ay;
cloo.imMax += ay;
}

internal void UpdateCloo()
{
cloo = Render.CreateCloo((uint)Width, (uint)Height, cloo);
}

protected override void OnLoad(EventArgs e)
{
UpdateCloo();
GL.Enable(EnableCap.Texture2D);
GL.Disable(EnableCap.DepthTest);
}

protected override void OnResize(EventArgs e)
{
UpdateCloo();
GL.Viewport(0, 0, Width, Height);
}

double s1_timer = 0; // smooth fps printing

protected override void OnRenderFrame(FrameEventArgs e)
{
float delta = (float)e.Time;

s1_timer += e.Time;
if (s1_timer > 1f)
{
Title = $"{Const.APP_NAME}, {Const.RELEASE_DATE}{cloo?.ComputePlatformName}: {(delta * 1000).ToString("0.")}ms, {(1.0 / delta).ToString("0")}fps // i{cloo?.maxIter}";
s1_timer = 0;
}

cloo.ConfigureKernel();
cloo.ExecuteKernel();
cloo.ReadResult();

GL.BindTexture(TextureTarget.Texture2D, 1);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Four, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, cloo.h_resultBuf);

GL.ClearColor(0f, 0f, 0f, 0f);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1f, 1f, 1f, -1f, 1f, 100f);
GL.MatrixMode(MatrixMode.Modelview);

GL.LoadIdentity();
GL.Begin(PrimitiveType.Quads);
GL.TexCoord2(0f, 1f);
GL.Vertex3(-1f, -1f, -1f);

GL.TexCoord2(0f, 0f);
GL.Vertex3(-1f, 1f, -1f);

GL.TexCoord2(1f, 0f);
GL.Vertex3(1f, 1f, -1f);

GL.TexCoord2(1f, 1f);
GL.Vertex3(1f, -1f, -1f);
GL.End();

GL.Flush();

SwapBuffers();
}

protected override void OnUnload(EventArgs e)
{
base.OnClosed(e);
}
}
}
25 changes: 25 additions & 0 deletions src/ClooToOpenTK/OpenTK.dll.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<configuration>
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
<!-- XQuartz compatibility (X11 on Mac) -->
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
</configuration>
16 changes: 16 additions & 0 deletions src/ClooToOpenTK/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace ClooToOpenTK
{
static class Program
{
[STAThread]
static void Main()
{
using (MainWindow mainWindow = new MainWindow())
{
mainWindow.Run();
}
}
}
}
10 changes: 10 additions & 0 deletions src/ClooToOpenTK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Reflection;
[assembly: AssemblyTitle("ClooToOpenTK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nikolai Voronin")]
[assembly: AssemblyProduct("ClooToOpenTK")]
[assembly: AssemblyCopyright("Copyright © Nikolai Voronin 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("19.1.13")]
Loading

0 comments on commit ac42fc5

Please sign in to comment.