/
Program.cs
136 lines (115 loc) · 5.38 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
namespace IntegrationGLUT
{
// This is a minimal integration example. For simplification purposes only basic input events are
// handled, no resource providers are used and the shutdown procedure is omitted.
class Program
{
static void Main(string[] args)
{
int argc = args.Length;
GLUT.Init(ref argc, args);
GLUT.InitDisplayMode(GLUT.RGB | GLUT.DOUBLE | GLUT.STENCIL);
GLUT.InitWindowSize(1000, 600);
GLUT.CreateWindow("NoesisGUI - GLUT integration");
NoesisInit();
GLUT.SetDisplayFunc(OnDisplay);
GLUT.SetReshapeFunc(OnReshape);
GLUT.SetPassiveMotionFunc(OnMouseMove);
GLUT.SetMouseFunc(OnMouseButton);
GLUT.MainLoop();
}
static void NoesisInit()
{
Noesis.Log.SetLogCallback((level, channel, message) =>
{
if (channel == "")
{
// [TRACE] [DEBUG] [INFO] [WARNING] [ERROR]
string[] prefixes = new string[] { "T", "D", "I", "W", "E" };
string prefix = (int)level < prefixes.Length ? prefixes[(int)level] : " ";
Console.WriteLine("[NOESIS/" + prefix + "] " + message);
}
});
// Noesis initialization. This must be the first step before using any NoesisGUI functionality
Noesis.GUI.Init("LICENSE_NAME", "LICENSE_KEY");
// Setup theme
NoesisApp.Application.SetThemeProviders();
Noesis.GUI.LoadApplicationResources("Theme/NoesisTheme.DarkBlue.xaml");
// For simplicity purposes we are not using resource providers in this sample. ParseXaml() is
// enough if there is no extra XAML dependencies
Noesis.Grid xaml = (Noesis.Grid)Noesis.GUI.ParseXaml(@"
<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<Grid.Background>
<LinearGradientBrush StartPoint=""0,0"" EndPoint=""0,1"">
<GradientStop Offset=""0"" Color=""#FF123F61""/>
<GradientStop Offset=""0.6"" Color=""#FF0E4B79""/>
<GradientStop Offset=""0.7"" Color=""#FF106097""/>
</LinearGradientBrush>
</Grid.Background>
<Viewbox>
<StackPanel Margin=""50"">
<Button Content=""Hello World!"" Margin=""0,30,0,0""/>
<Rectangle Height=""5"" Margin=""-10,20,-10,0"">
<Rectangle.Fill>
<RadialGradientBrush>
<GradientStop Offset=""0"" Color=""#40000000""/>
<GradientStop Offset=""1"" Color=""#00000000""/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
</Viewbox>
</Grid>");
// View creation to render and interact with the user interface
// We transfer the ownership to a global pointer instead of a Ptr<> because there is no way
// in GLUT to do shutdown and we don't want the Ptr<> to be released at global time
_view = Noesis.GUI.CreateView(xaml);
_view.SetFlags(Noesis.RenderFlags.PPAA | Noesis.RenderFlags.LCD);
// Renderer initialization with an OpenGL device
_view.Renderer.Init(new Noesis.RenderDeviceGL());
}
static void OnDisplay()
{
// Update view (layout, animations, ...)
_view.Update(GLUT.Get(GLUT.ELAPSED_TIME) / 1000.0);
// Offscreen rendering phase populates textures needed by the on-screen rendering
_view.Renderer.UpdateRenderTree();
_view.Renderer.RenderOffscreen();
// If you are going to render here with your own engine you need to restore the GPU state
// because noesis changes it. In this case only framebuffer and viewport need to be restored
GL.BindFramebuffer(GL.FRAMEBUFFER, 0);
GL.Viewport(0, 0, (uint)GLUT.Get(GLUT.WINDOW_WIDTH), (uint)GLUT.Get(GLUT.WINDOW_HEIGHT));
GL.ClearColor(0.0f, 0.0f, 0.25f, 0.0f);
GL.ClearStencil(0);
GL.Clear(GL.COLOR_BUFFER_BIT | GL.STENCIL_BUFFER_BIT);
// Rendering is done in the active framebuffer
_view.Renderer.Render();
GLUT.SwapBuffers();
GLUT.PostRedisplay();
}
static void OnReshape(int width, int height)
{
_view.SetSize(width, height);
}
static void OnMouseMove(int x, int y)
{
_view.MouseMove(x, y);
}
static void OnMouseButton(int button, int state, int x, int y)
{
if (button == GLUT.LEFT_BUTTON)
{
if (state == GLUT.DOWN)
{
_view.MouseButtonDown(x, y, Noesis.MouseButton.Left);
}
else
{
_view.MouseButtonUp(x, y, Noesis.MouseButton.Left);
}
}
}
static Noesis.View _view = null;
}
}