Unigine C# integration
Hola/Hello there
i am trying to integrate NoesisGUI with Unigine but i am failing miserably, i tried looking at the unoficial unigine+noesis integration of C++ and the DirectX integration, but i have not been able to get it working because of my lack of knowledge.
i have only been able to import the libraries and initialize it but after that i dont know how to render it or show it on screen.
i created a simple component called GUI.cs and made a button, then i try to place all the NOESIS code and it all goes well but i cannot make it render on screen.
i use the code from this example: https://github.com/Noesis/Tutorials/blo ... Program.cs
but i cannot get past line 70 i understand it expects me to include the DX11 libraries so i can define these:
everything is loading in correctly i just need a small push to make it show on screen
If anybody has time, please help me, i am just a beginner at this and i don't really know what i am doing here.
i am trying to integrate NoesisGUI with Unigine but i am failing miserably, i tried looking at the unoficial unigine+noesis integration of C++ and the DirectX integration, but i have not been able to get it working because of my lack of knowledge.
i have only been able to import the libraries and initialize it but after that i dont know how to render it or show it on screen.
i created a simple component called GUI.cs and made a button, then i try to place all the NOESIS code and it all goes well but i cannot make it render on screen.
Code: Select all
using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;
using Noesis;
using NoesisApp;
using NoesisGUIExtensions;
[Component(PropertyGuid = "97d16d320d756ae924bf3734ae37790300c24a86")]
public class GUI : Component
{
[ShowInEditor]
[Parameter(Tooltip = "The GUI")]
private ObjectGui lui = null;
public int x = 250;
public int y = 50;
public int width = 100;
public int height = 50;
public string text = "Press Me";
public int fontSize = 16;
private WidgetButton button = null;
private void Init()
{
Gui gui = Gui.Get();
// create button
button = new WidgetButton(gui, text);
button.SetPosition(x, y);
button.Width = width;
button.Height = height;
button.FontSize = fontSize;
button.AddCallback(Gui.CALLBACK_INDEX.CLICKED, () => Unigine.Console.OnscreenMessageLine("Button Clicked!"));
// add button to current gui
gui.AddChild(button, Gui.ALIGN_OVERLAP);
Unigine.Console.Onscreen = true;
Unigine.Console.Message("----------NOESISGUI----------\n");
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] : " ";
Unigine.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
Noesis.View view = Noesis.GUI.CreateView(xaml);
view.SetFlags(Noesis.RenderFlags.PPAA | Noesis.RenderFlags.LCD);
view.SetSize(gui.Width, gui.Height);
}
private void Update()
{
}
private void Shutdown()
{
// remove button from current gui
Gui.Get().RemoveChild(button);
Unigine.Console.Onscreen = false;
}
}
but i cannot get past line 70 i understand it expects me to include the DX11 libraries so i can define these:
- SwapChainDescription
- Device
- SwapChain
- Factory
Code: Select all
// Creation of the system window
RenderForm form = new RenderForm("NoesisGUI - IntegrationSharpDX D3D11")
{
Width = 1000,
Height = 600,
Icon = new System.Drawing.Icon("Noesis.ico")
};
view.SetSize(form.ClientSize.Width, form.ClientSize.Height);
// SwapChain description
SwapChainDescription desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create Device and SwapChain
Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
DeviceContext context = device.ImmediateContext;
Factory factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
factory.Dispose();
// Renderer initialization with a Direct3D11 device
view.Renderer.Init(new Noesis.RenderDeviceD3D11(context.NativePointer));
// New RenderTargetView from the backbuffer
Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
RenderTargetView renderView = new RenderTargetView(device, backBuffer);
backBuffer.Dispose();
// Register window events
form.SizeChanged += (s, e) =>
{
context.OutputMerger.SetRenderTargets(null, (RenderTargetView)null);
renderView.Dispose();
swapChain.ResizeBuffers(0, 0, 0, Format.Unknown, SwapChainFlags.None);
backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer);
backBuffer.Dispose();
view.SetSize(form.ClientSize.Width, form.ClientSize.Height);
};
form.MouseMove += (s, e) => { view.MouseMove(e.X, e.Y); };
form.MouseDown += (s, e) =>
{
if (e.Button == MouseButtons.Left)
{
view.MouseButtonDown(e.X, e.Y, Noesis.MouseButton.Left);
}
};
form.MouseUp += (s, e) =>
{
if (e.Button == MouseButtons.Left)
{
view.MouseButtonUp(e.X, e.Y, Noesis.MouseButton.Left);
}
};
// Main loop
DateTime start = DateTime.Now;
RenderLoop.Run(form, () =>
{
// Update view (layout, animations, ...)
view.Update((DateTime.Now - start).TotalSeconds);
// 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
context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
context.OutputMerger.SetTargets(renderView);
context.ClearRenderTargetView(renderView, Color.Black);
// Rendering is done in the active framebuffer
view.Renderer.Render();
// Present and swap buffers
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
renderView.Dispose();
context.ClearState();
context.Flush();
device.Dispose();
context.Dispose();
swapChain.Dispose();
If anybody has time, please help me, i am just a beginner at this and i don't really know what i am doing here.
Re: Unigine C# integration
The integration guide and minimal examples for GLUT and D3D should provide enough information to create a new integration. It seems you have problems with fundamental concepts related to DirectX and C# and I would say you will probably receive more help in specific forums for those topics.
Re: Unigine C# integration
i was able to make it run but it was not exactly an integration, it was opening the noesis window outside of the project instead of in the game itself (
from what was explained to me i can only use a specific class called Ffp that renders pure Geometry (https://developer.unigine.com/en/docs/2 ... #highlight) and to make it render in unigine noesis would need to able to send pure geometry. although im not exactly sure if it works like that.
from what was explained to me i can only use a specific class called Ffp that renders pure Geometry (https://developer.unigine.com/en/docs/2 ... #highlight) and to make it render in unigine noesis would need to able to send pure geometry. although im not exactly sure if it works like that.
Re: Unigine C# integration
yes but unfortunatly the ExternClass is not avaiable in the c# API. and the goal is to make it work in there :S
Who is online
Users browsing this forum: No registered users and 14 guests