Page 1 of 1
RenderTexture
Posted: 05 Feb 2014, 04:15
by jsantos
A sample showing how to integrate render to texture inside noesisGUI. The details are described at the end of the
Image Tutorial .
Sample Source Code
After opening the Unity project, you would need to import NoesisGUI 1.2 (available from our forums:
viewtopic.php?f=3&t=91 ) to make it work.
VIDEO
Older version compatible with NoesisGUI 1.1 can be downloaded
here .
Re: RenderTexture
Posted: 15 Jan 2015, 19:52
by elusive52
Hi
is it possible to download the 'duck shoot' game scene in the demo video? with the full working GUi?
thanks.
Re: RenderTexture
Posted: 15 Jul 2015, 19:13
by kguner
Hello,
I was trying to use the spaceboy example with the latest version of noesisgui and ran into compile errors.
I updated the Start() code in spaceboy.cs to the following
// Find the rectangle where texture will be drawn
var gui = GetComponent<NoesisGUIPanel>();
var root = (Noesis.FrameworkElement)gui.GetContent();
var rect = (Noesis.Rectangle)root.FindName("rtRect");
// Create render texture
UnityEngine.RenderTexture renderTexture = new RenderTexture(
512, 512, 1, UnityEngine.RenderTextureFormat.RGB565);
UnityEngine.RenderTexture.active = renderTexture;
// Set render texture as camera target
this._offscreenCamera.targetTexture = renderTexture;
this._offscreenCamera.aspect = 1;
...
The compile time errors are gone but i get a runtime error: RenderTexture.Create failed: format unsupported.
Re: RenderTexture
Posted: 16 Jul 2015, 01:52
by kguner
I got this working by changing the following line:
UnityEngine.RenderTexture renderTexture = new RenderTexture(512, 512, 1, UnityEngine.RenderTextureFormat.Default);
This sample now works.
Here is my whole SpaceBoy.cs file.
using UnityEngine;
using System;
public class SpaceBoy : MonoBehaviour
{
public UnityEngine.Camera _offscreenCamera;
public UnityEngine.GameObject _spaceBoy;
Noesis.Border _titleBar;
Noesis.TranslateTransform _panelPosition;
void Start()
{
// Find the rectangle where texture will be drawn
var gui = GetComponent<NoesisGUIPanel>();
var root = (Noesis.FrameworkElement)gui.GetContent();
var rect = (Noesis.Rectangle)root.FindName("rtRect");
// Create render texture
UnityEngine.RenderTexture renderTexture = new RenderTexture(512, 512, 1, UnityEngine.RenderTextureFormat.Default);
UnityEngine.RenderTexture.active = renderTexture;
// Set render texture as camera target
this._offscreenCamera.targetTexture = renderTexture;
this._offscreenCamera.aspect = 1;
// Create brush to store render texture
var texBrush = new Noesis.ImageBrush();
texBrush.ImageSource = (new Noesis.TextureSource(renderTexture));
texBrush.Stretch = (Noesis.Stretch.UniformToFill);
texBrush.Opacity = (0.9f);
// Set the rectangle fill brush to use texture
rect.Fill = (texBrush);
// Title bar drag to move
this._titleBar = (Noesis.Border)root.FindName("titleBar");
this._titleBar.MouseLeftButtonDown += this.OnTitleBarMouseDown;
this._titleBar.MouseLeftButtonUp += this.OnTitleBarMouseUp;
this._titleBar.MouseMove += this.OnTitleBarMouseMove;
var panel = (Noesis.Panel)root.FindName("panel");
this._panelPosition = (Noesis.TranslateTransform)panel.RenderTransform;
// Model rotation
var rotateLeft = (Noesis.RepeatButton)root.FindName("rotateLeft");
rotateLeft.Click += this.OnRotateLeft;
var rotateRight = (Noesis.RepeatButton)root.FindName("rotateRight");
rotateRight.Click += this.OnRotateRight;
}
Noesis.Point _lastPosition;
void OnTitleBarMouseDown(object sender, Noesis.MouseButtonEventArgs e)
{
this._titleBar.CaptureMouse();
this._lastPosition = new Noesis.Point(Input.mousePosition.x, - Input.mousePosition.y);
}
void OnTitleBarMouseUp(object sender, Noesis.MouseButtonEventArgs e)
{
this._titleBar.ReleaseMouseCapture();
}
void OnTitleBarMouseMove(object sender, Noesis.MouseEventArgs e)
{
if (this._titleBar.GetMouse().Captured == this._titleBar)
{
var pos = new Noesis.Point(Input.mousePosition.x, - Input.mousePosition.y);
Noesis.Point delta = pos - this._lastPosition;
this._lastPosition = pos;
this._panelPosition.X = (this._panelPosition.X + delta.X);
this._panelPosition.Y = (this._panelPosition.Y + delta.Y);
}
}
void OnRotateLeft(object sender, Noesis.RoutedEventArgs e)
{
this._spaceBoy.transform.Rotate(Vector3.up, 2.0f);
}
void OnRotateRight(object sender, Noesis.RoutedEventArgs e)
{
this._spaceBoy.transform.Rotate(Vector3.up, -2.0f);
}
}
Re: RenderTexture
Posted: 16 Jul 2015, 18:40
by jsantos
I was going to inform you how to solve the RenderTarget issue but I see that you already solved it.
Thanks for the fix! We will update our sample and upload it to github.
Re: RenderTexture
Posted: 16 Jul 2015, 22:22
by sfernandez
Sample updated to NoesisGUI 1.2 and ready for Unity 5.1 is now available from GitHub
Re: RenderTexture
Posted: 16 Jul 2015, 23:51
by kguner
I looked at the github code. I see that you can pass null to MouseButtonEventArgs.GetPosition(). Useful to know, thanks!
Re: RenderTexture
Posted: 17 Jul 2015, 11:31
by sfernandez
Passing null means that mouse position is relative to the root element (usually the screen).