# How to overlay an image over another in P3D

**URL:** https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959
**Category:** Coding Questions
**Created:** [June 14, 2018, 11:26am UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959 "2018-06-14T11:26:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rainfox](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rainfox](https://discourse.processing.org/u/rainfox)
#### Post date: [June 14, 2018, 11:26am UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/1 "2018-06-14T11:26:57Z")

</div>

In processing.js, how would you overlay an image over another one in P3D mode?

Here is my code:

```auto
    /* @pjs preload="duck.jpg"; */
    /* @pjs preload="a.png"; */ 
    PImage imageDuck;
    PImage imageA;
    
    void setup() {
     	size(500, 500, P3D);
    	imageDuck = loadImage("duck.jpg");
    	imageA = loadImage("a.png");
    }
    
    void draw() {
    	background(255);
    	noStroke();
        image(imageDuck, 0, 0);
    	image(imageA, 0, 0);
    }

```

So what the code trying to do is to display a duck image, then overlay another image name a.png (with transparent background) on top of it.

When I use the normal **size(500, 500);** without the P3D mode, the image overlay works perfectly.

However, I am using P3D because the next thing I am going to do is to rotate my images together.

So in this **size(500, 500, P3D)** mode, I can see my a.png flashed once, then only my duck image shows. If I comment out duck, a.png will show. If I comment out a.png, my duck shows. If I reorder the image() call, still only the duck image shows. I added translate(0,0,-1) or translate(0,0,1) in between my image() calls, no luck, only my duck image shows.

Is this even possible?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [June 14, 2018, 11:31am UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/2 "2018-06-14T11:31:56Z")

</div>

translate(0,0,1); between the 2 images

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [June 14, 2018, 1:38pm UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/3 "2018-06-14T13:38:51Z")

</div>

What about `hint(DISABLE_DEPTH_TEST);`?

---

<div class="post-metadata">

### Author: ![nicolaskellum](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nicolaskellum/32/15860_2.png) [@nicolaskellum](https://discourse.processing.org/u/nicolaskellum)
#### Post date: [June 14, 2018, 3:36pm UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/4 "2018-06-14T15:36:21Z")

</div>

Hey @rainfox !

Do you mind uploading those images so we can test it out?

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 14, 2018, 6:54pm UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/5 "2018-06-14T18:54:16Z")

</div>

> [@rainfox](#):
>
> ```auto
> /* @pjs preload="duck.jpg"; */
> /* @pjs preload="a.png"; */
> 
> ```

Once Pjs spots the 1st `/*@pjs */` directive comment block within a sketch, it skips the others! ☠⚠💀  
[http://ProcessingJS.org/reference/pjs%20directive/](http://ProcessingJS.org/reference/pjs%20directive/)

---

<div class="post-metadata">

### Author: ![rainfox](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rainfox](https://discourse.processing.org/u/rainfox)
#### Post date: [June 14, 2018, 7:13pm UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/6 "2018-06-14T19:13:06Z")

</div>

I have tried that with no luck as mentioned in the description. Always only duck shows.

---

<div class="post-metadata">

### Author: ![rainfox](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rainfox](https://discourse.processing.org/u/rainfox)
#### Post date: [June 14, 2018, 7:14pm UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/7 "2018-06-14T19:14:27Z")

</div>

Thanks for the help. My full testing code is in openprocessing:

[https://www.openprocessing.org/sketch/554591](https://www.openprocessing.org/sketch/554591)

---

<div class="post-metadata">

### Author: ![rainfox](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@rainfox](https://discourse.processing.org/u/rainfox)
#### Post date: [June 14, 2018, 7:17pm UTC](https://discourse.processing.org/t/how-to-overlay-an-image-over-another-in-p3d/959/8 "2018-06-14T19:17:11Z")

</div>

Wow, I move them into 1 line, then add a translate(0,0,1) in between, now they show as expected!! Thanks!
