# Use the texture of a render target in a polygon \[SOLVED\]

**URL:** <https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770>\
**Category:** Questions\
**Created:** [March 1, 2023, 10:05pm UTC](https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770 "2023-03-01T22:05:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caue-Aron](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/caue-aron/32/41954_2.png) [@Caue-Aron](https://forum.defold.com/u/Caue-Aron)\
**Post date:** [March 1, 2023, 10:05pm UTC](https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770/1 "2023-03-01T22:05:06Z")

</div>

I have this code which draws the whole game world into a render target:

```lua
render.set_render_target(self.pp_game_world)

default_renderer()

draw_game_world()

render.enable_texture(0, self.pp_game_world, render.BUFFER_COLOR_BIT)

```

But how do i actually use the texture of this render target? I need to attach it to a quad i will be using to do post processing.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [March 1, 2023, 10:17pm UTC](https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770/2 "2023-03-01T22:17:03Z")

</div>

> [@Caue-Aron](#):
>
> But how do i actually use the texture of this render target?

When you call `render.enable_texture(0, self.pp_game_world, render.BUFFER_COLOR_BIT)` it means that the color buffer of the render target will be available as texture 0 in the shader of whatever you `render.draw()` next.

---

<div class="post-metadata">

**Author:** ![Caue-Aron](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/caue-aron/32/41954_2.png) [@Caue-Aron](https://forum.defold.com/u/Caue-Aron)\
**Post date:** [March 1, 2023, 10:20pm UTC](https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770/3 "2023-03-01T22:20:29Z")

</div>

I’m sorry, i didnt understand what i should do with that information. What does it mean that it will be the texture 0 in the shader? How do i access this texture in the shader?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [March 1, 2023, 10:34pm UTC](https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770/4 "2023-03-01T22:34:15Z")

</div>

> [@Caue-Aron](#):
>
> How do i access this texture in the shader?

It will be available as `tex0` in your fragment program:

```lua
uniform lowp sampler2D tex0;

```

---

<div class="post-metadata">

**Author:** ![Caue-Aron](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/caue-aron/32/41954_2.png) [@Caue-Aron](https://forum.defold.com/u/Caue-Aron)\
**Post date:** [March 1, 2023, 10:35pm UTC](https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770/5 "2023-03-01T22:35:27Z")

</div>

much thanks, i will try it

---

<div class="post-metadata">

**Author:** ![Caue-Aron](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/caue-aron/32/41954_2.png) [@Caue-Aron](https://forum.defold.com/u/Caue-Aron)\
**Post date:** [March 1, 2023, 10:44pm UTC](https://forum.defold.com/t/use-the-texture-of-a-render-target-in-a-polygon-solved/72770/6 "2023-03-01T22:44:25Z")

</div>

It works, kinda. With this code:

```lua
render.set_render_target(self.pp_game_world)

  default_renderer()
  draw_game_world()

  render.enable_texture(0, self.pp_game_world, render.BUFFER_COLOR_BIT)

  render.set_render_target(render.RENDER_TARGET_DEFAULT)
  default_renderer()
  draw_post_processing()

  render.disable_texture(0)

```

in the quad shader:

```glsl
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D tex0;
//---------------------------------------------------------------------------
void main()
{
    gl_FragColor=texture2D(tex0, var_texcoord0);
}

```

i get this result:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/1/0/1094b314a1c145d09007660d85ddd8dc6df75d45.png)

it should be just the defold logo, but its all wrong.
