- Home /
Why is Graphics.DrawTexture textures is rendered outside of Editor Window ?
Hi, I opted to draw texture images in my Editor Window using Graphics.DrawTexture instead of GUI.DrawTexture because . Graphic.DrawTexture i faster.
However it will be rendered outside of the editor window and of course outside any scroll view . but why and how can I let that not happen ?
Here are an examples
if this were the GUI are of an EditorWindow.
Texture2D MyTextureImage;
void OnGUI()
{
//
//MyTextureImage = .... some texture
//
Graphics.DrawTexture(new Rect(-10,-10,40,40),MyTextureImage);
}
10 pixels of the box will be rendered outside of the editor window but if I use GUI.DrawTexture it doesn't.
How can I prevent this from happening
Answer by MCudlitz · Jan 17, 2017 at 01:20 AM
Graphics.drawTexture is done in screen coordinates. Based on your rectangle, it should be rendering in the bottom left corner of the editor window, with only 30 pixels visible. There's a chance that you just missed it at that small size.
it will render 10 pixels -y of the Editor window, be clipped on the -x and render 30 in the editor window.
The editor window drawing begins about 22 pixels above the (0,0) position in the Editor window.
After looking through the RenderDoc process of rendering a scene, it appears that this is just how Unity works. It draws overlays, and then the frame, onto the same texture for rendering so the pixel units will be a bit off. The good news is that the edges are a constant size that you can make a simple method to account for.
Your answer
![](https://koobas.hobune.stream/wayback/20220612104942im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object turns pink when changing material at real time: 1 Answer
How to mask 3D game object or 2D sprite? 1 Answer
Multiple Cars not working 1 Answer
Skybox material not working 1 Answer
Distribute terrain in zones 3 Answers