Search Unity

Camera view to GUI texture

Discussion in 'Scripting' started by acme3D, Dec 1, 2010.

  1. acme3D

    acme3D

    Joined:
    Feb 4, 2009
    Posts:
    203
    Hi, would it be possible to render a camera (pointed on a rotating object) to a Texture2D that would then be used by GUI.Drawtexture ?

    I've tried using RenderTexture, but how can I convert this to a usable Texture2D ?

    Basically I need to display the rotation of a 3D object over a UnityGUI interface (the normally is on top of anything else)... any other trick is welcome !
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can not convert render textures to texture2d, they are not compatible to each other (rendertexture exists only on graphics ram, texture2d is a system ram thing that also exists on the gpu). That being said, GUI.DrawTexture expects a Texture, not a Texture2D so thats no problem cause Texture2D as well as RenderTexture extend from Texture :)
     
  3. acme3D

    acme3D

    Joined:
    Feb 4, 2009
    Posts:
    203
    OK, then.... is there a trick so that I can take a view from a camera and display that view on a GUI thing ?
    (for example it could be a rear view mirror in a car you're driving....
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    just draw the rendertexture.

    As mentioned, DrawTexture does not need a Texture2D, it needs a Texture and RenderTexture as well as Texture2D are both fine when only Texture is required
     
  5. acme3D

    acme3D

    Joined:
    Feb 4, 2009
    Posts:
    203
    Ummm...... how can you draw the rendertexture ? I know how to display things with UnityGUI, texture over 3D meshes... is there a third way ? if yes, then code please.... (at least 1 line !)
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You just need to call GUI.DrawTexture passing a RenderTexture in place of a Texture2D. The function expects a Texture object, which is the superclass of both RenderTexture and Texture2D, so they are both compatible.