Author Topic: NGUI Camera targetTexture to GUI.DrawTexture  (Read 7557 times)

jkaris

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
NGUI Camera targetTexture to GUI.DrawTexture
« on: November 07, 2012, 12:54:05 AM »
Hi,

I'm attempting to draw the view of the camera to the GUI and I can't get it working.

This is basically what I have tried:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class s_guiCam : MonoBehaviour
  5. {
  6.         RenderTexture rt;
  7.         public Camera guiCamera;
  8.        
  9.         void Start ()
  10.         {
  11.                 rt = new RenderTexture (Screen.width, Screen.height, 24);              
  12.                 guiCamera.targetTexture = rt;
  13.         }
  14.        
  15.         void OnGUI ()
  16.         {
  17.                 GUI.depth = -5001;
  18.                 GUI.DrawTexture (new Rect (40, 0f, (float)Screen.width, (float)Screen.height), rt);
  19.         }
  20. }
  21.  


Can someone let me know if this is even possible or what I'm missing.

Much thanks,
JK.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Camera targetTexture to GUI.DrawTexture
« Reply #1 on: November 07, 2012, 04:25:48 AM »
OnGUI is Unity's GUI. It's not NGUI. Get rid of the OnGUI function and use a UITexture to display the render texture you're rendering the camera into.

jkaris

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI Camera targetTexture to GUI.DrawTexture
« Reply #2 on: November 07, 2012, 05:54:47 AM »
Hi ArenMook,

Thanks for the speedy response - I've only had NGUI for a couple days and I'm not exactly sure how to do what you said.  Could you please explain a bit further how to achieve this?  Sorry for the noob-ness...

J.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Camera targetTexture to GUI.DrawTexture
« Reply #3 on: November 07, 2012, 08:44:52 AM »
Add a Simple Texture (aka UITexture). Set uiTexture.mainTexture = rt;

jkaris

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI Camera targetTexture to GUI.DrawTexture
« Reply #4 on: November 07, 2012, 05:45:48 PM »
Hi ArenMook,

I have attempted the following:

I have a game object in the Hierarchy named "NGUIObject" - I have attached a component UITexture to it.

I have created a UI Root (2D) and it simply contains 1 single label.

I have attached the following script to "NGUIObject"

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraToTexture : MonoBehaviour {
  5.        
  6.         public Camera NGUICamera;
  7.        
  8.         RenderTexture rt;
  9.         UITexture uiTexture;
  10.        
  11.         void Start () {
  12.                
  13.                 uiTexture = gameObject.GetComponent<UITexture>();
  14.                
  15.                 rt = new RenderTexture (Screen.width, Screen.height, 24);
  16.                 NGUICamera.targetTexture = rt;
  17.                
  18.                 uiTexture.mainTexture = rt;
  19.         }
  20. }
  21.  

When I run it, I can see in the Inspector for "NGUIObject" that the texture is being assigned to the Texture in UITexture - but I am seeing nothing on the screen.

Am I missing a step somewhere?

Thanks again,
J.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Camera targetTexture to GUI.DrawTexture
« Reply #5 on: November 08, 2012, 04:21:38 AM »
... NGUI camera shouldn't have a render texture. That's what draws your UI. You should assign the render texture to your camera that you want to do the rendering -- like a camera set to view your character's model, for example.