Hello Guest

Author Topic: Render Testure of Tk2d Camera Clipped  (Read 4129 times)

gonzalez.martin90

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 24
    • View Profile
Render Testure of Tk2d Camera Clipped
« on: January 16, 2015, 04:27:29 pm »
Hey! I'm trying to make a screenshot of a certain camera (tk2d Cam clipped) and something strage is giving me as texture.
Seems that what the camera sees its ok but its doing like something strange around.
Any idea? I'm using RenderTexture

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Render Testure of Tk2d Camera Clipped
« Reply #1 on: January 16, 2015, 04:40:41 pm »
If its clipped then the rt won't be filled, i.e. you'll have whatever was left over. You'll need a second camera drawing into this RT to fill in the parts of the texture outside.

gonzalez.martin90

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Render Testure of Tk2d Camera Clipped
« Reply #2 on: January 16, 2015, 04:54:33 pm »
Thanks for answering.
 Yes i understood it, but what i want is to take a screenshot of that clipped camera and have a "full screen" screenshot.
I did a new method that works like this:

Code: [Select]
public Texture2D TakeScreenShot(Camera camera, Bounds bound)
{
#if UNITY_ANDROID
Texture2D snapShot = new Texture2D((int)camera.pixelWidth , (int)camera.pixelHeight, TextureFormat.RGB24, false );
snapShot.ReadPixels( new Rect( camera.pixelRect.xMin, camera.pixelRect.xMin, (int)camera.pixelWidth, (int)camera.pixelHeight), 0, 0, false );
snapShot.Apply();
return snapShot;
#endif
return new Texture2D(100,100);
}

The code seems to be ok, but the height of the screenshot is more than expected

« Last Edit: January 16, 2015, 05:04:01 pm by gonzalez.martin90 »

gonzalez.martin90

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Render Testure of Tk2d Camera Clipped
« Reply #3 on: January 16, 2015, 05:11:27 pm »
it seems to be offset because if i modify this

Code: [Select]
snapShot.ReadPixels( new Rect( camera.pixelRect.xMin, camera.pixelRect.xMin-40, (int)camera.pixelWidth, (int)camera.pixelHeight), 0, 0, false );
that 40 modify the Y offset but depends on the resolution. I cant know which calculation i have to do to have the exactly point and size

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Render Testure of Tk2d Camera Clipped
« Reply #4 on: January 16, 2015, 10:54:26 pm »
I don't understand why you're not reading all the pixels in the render texture? If xMin != 0 you won't be reading into all pixels in the texture2D, and be left with random pixels in there.