RenderTexture
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.
Older version compatible with NoesisGUI 1.1 can be downloaded here.
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.
Older version compatible with NoesisGUI 1.1 can be downloaded here.
Re: RenderTexture
Hi
is it possible to download the 'duck shoot' game scene in the demo video? with the full working GUi?
thanks.
is it possible to download the 'duck shoot' game scene in the demo video? with the full working GUi?
thanks.
Re: RenderTexture
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
The compile time errors are gone but i get a runtime error: RenderTexture.Create failed: format unsupported.
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
Code: Select all
// 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;
...
Re: RenderTexture
I got this working by changing the following line:
This sample now works.
Here is my whole SpaceBoy.cs file.
Code: Select all
UnityEngine.RenderTexture renderTexture = new RenderTexture(512, 512, 1, UnityEngine.RenderTextureFormat.Default);
Here is my whole SpaceBoy.cs file.
Code: Select all
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
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.
Thanks for the fix! We will update our sample and upload it to github.
-
sfernandez
Site Admin
- Posts: 3188
- Joined:
Re: RenderTexture
Sample updated to NoesisGUI 1.2 and ready for Unity 5.1 is now available from GitHub
Re: RenderTexture
I looked at the github code. I see that you can pass null to MouseButtonEventArgs.GetPosition(). Useful to know, thanks!
-
sfernandez
Site Admin
- Posts: 3188
- Joined:
Re: RenderTexture
Passing null means that mouse position is relative to the root element (usually the screen).
Who is online
Users browsing this forum: No registered users and 0 guests