# Text node incorrectly clipped with stencil (SOLVED)

**URL:** <https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096>\
**Category:** Questions\
**Created:** [March 9, 2017, 12:11pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096 "2017-03-09T12:11:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cartwright.samuel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cartwright.samuel/32/3545_2.png) [@cartwright.samuel](https://forum.defold.com/u/cartwright.samuel)\
**Post date:** [March 9, 2017, 12:11pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/1 "2017-03-09T12:11:34Z")

</div>

I’m not sure if this is a bug, or if I’m just doing this wrong, but it looks like a bug.

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/2/2c3fd04278c545811c455c3de8ba09b62c90789e.png)

I have some GUI components and I wanted to create a scrolling text box.  
I created a stencil and added the text node as a child.

It appears to clip will upon launch. But I’ve also written code to allow the user to drag the dialog (my hierarchy of GUI nodes) using the mouse.  
After the dialog is dragged, the text is no longer clipped properly.

As you can see, the first 5 characters are not clipped at all, the next 5 are (incorrectly) clipped, while the last three are correctly clipped (these last three show where the supper bound of the stencil should be).

I’ve read a few other posts were people were having trouble with stencils and text nodes, I’m wondering if this is also a known problem.

---

<div class="post-metadata">

**Author:** ![Ivan\_Lytkin](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ivan_lytkin/32/2654_2.png) [@Ivan\_Lytkin](https://forum.defold.com/u/Ivan_Lytkin)\
**Post date:** [March 9, 2017, 1:51pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/2 "2017-03-09T13:51:43Z")

</div>

Sometimes it helps to place your clipped node inside bigger clipped node. (in your case - make dialog node also clipped, or create a full-screen clipped box) - but not sure it will work.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [March 9, 2017, 3:12pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/3 "2017-03-09T15:12:44Z")

</div>

Hi @cartwright.samuel!

Is the light gray box the clipping (parent) node?  
And is each character a separate gui node? Do you have them created up front?

Although your screenshot doesn’t have that many nodes in it, I’m wondering if there’s something related to the maximum number of clipping nodes etc. This is described in more detail in the first section in the [Clipping manual](http://www.defold.com/manuals/clipping/).

---

<div class="post-metadata">

**Author:** ![cartwright.samuel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cartwright.samuel/32/3545_2.png) [@cartwright.samuel](https://forum.defold.com/u/cartwright.samuel)\
**Post date:** [March 9, 2017, 9:49pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/4 "2017-03-09T21:49:49Z")

</div>

It’s just the one clip node (textClipArea) with all the text in a single text node attached as a child

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/b/b8fbe80c18502eb2b218988825920b01a8d06307.png)

---

<div class="post-metadata">

**Author:** ![cartwright.samuel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cartwright.samuel/32/3545_2.png) [@cartwright.samuel](https://forum.defold.com/u/cartwright.samuel)\
**Post date:** [March 9, 2017, 9:58pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/5 "2017-03-09T21:58:11Z")

</div>

Thanks @Ivan_Lytkin  
Adding another clipped box worked

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [March 10, 2017, 8:26am UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/6 "2017-03-10T08:26:22Z")

</div>

I wonder, do you use a custom render script?  
If so, in the last release, we fixed a few stencil clipping issues, and one fix was to add an extra line to the render script. Perhaps this is something that could work for you:

```lua
render.set_stencil_mask(0xff)

```

(Add it before the `render.clear()` commands)

See release notes [here](https://forum.defold.com/t/defold-1-2-99-has-been-released/5974)

---

<div class="post-metadata">

**Author:** ![cartwright.samuel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cartwright.samuel/32/3545_2.png) [@cartwright.samuel](https://forum.defold.com/u/cartwright.samuel)\
**Post date:** [March 10, 2017, 10:03am UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/7 "2017-03-10T10:03:17Z")

</div>

Yeah, I do use a custom render - its very similar to the default render.

I was missing that line of code, and it did fix the problem.

Thanks heaps for your help.

---

<div class="post-metadata">

**Author:** ![cartwright.samuel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cartwright.samuel/32/3545_2.png) [@cartwright.samuel](https://forum.defold.com/u/cartwright.samuel)\
**Post date:** [March 10, 2017, 12:14pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/8 "2017-03-10T12:14:10Z")

</div>

Just curios,  
Now any text drawn with the draw\_text message seems to be clipped and not displaying unless its within a stencil node  
Was that the intent?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [March 10, 2017, 12:59pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/9 "2017-03-10T12:59:02Z")

</div>

Ah, no I don’t think so ☹ I could replicate it here too.

---

<div class="post-metadata">

**Author:** ![Andreas\_Tadic](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@Andreas\_Tadic](https://forum.defold.com/u/Andreas_Tadic)\
**Post date:** [March 10, 2017, 12:59pm UTC](https://forum.defold.com/t/text-node-incorrectly-clipped-with-stencil-solved/6096/10 "2017-03-10T12:59:52Z")

</div>

The default renderscript looks like this, drawing the ‘gui’ and the ‘text’ predicate within the scope of having stencil test enable:

```
render.enable_state(render.STATE_STENCIL_TEST)
render.draw(self.gui_pred)
render.draw(self.text_pred)
render.disable_state(render.STATE_STENCIL_TEST)

```

The text render uses the system font which have the ‘text’ predicate. You can create another material for the system font with another predicate (for example ‘render\_text’) and render that (predicate) after you disable the stencil test.

The fact that the stencil test effects this text predicate in this case is unfortunate and a special case / buger scripts.  
I’ve created DEF-2562 and we’ll see how we approach this later on.
