# Map image onto shape

**URL:** <https://discourse.processing.org/t/map-image-onto-shape/29879>\
**Category:** Coding Questions\
**Created:** [May 5, 2021, 12:51pm UTC](https://discourse.processing.org/t/map-image-onto-shape/29879 "2021-05-05T12:51:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frinkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/frinkel/32/13051_2.png) [@Frinkel](https://discourse.processing.org/u/Frinkel)\
**Post date:** [May 5, 2021, 12:51pm UTC](https://discourse.processing.org/t/map-image-onto-shape/29879/1 "2021-05-05T12:51:51Z")

</div>

Hi I’m working with the processing library for Java, and are having some issues giving my shapes a texture, right now, the texture isn’t showing. I hope some of you guys might have an idea, of what I’m doing wrong.

IDE is eclipse.

Heres my code:

```auto
public class View extends PApplet {
     PImage img;
     PShape myShape;

     public void setup() {
         img = loadImage("assets\\images\\test.jpg");
     }

     public void settings() {
        size(displayHeight*3>>2, displayHeight*3>>2);
     }

     public void draw() {
         background(175);

         myShape = createShape();
         textureMode(NORMAL);
         myShape.beginShape();
         myShape.texture(img);
         myShape.vertex(0, 0, 0, 0);
         myShape.vertex(100, 0, 1, 0);
         myShape.vertex(100, 100, 1, 1);
         myShape.vertex(0, 100, 0, 1);
         myShape.endShape(CLOSE);
         shape(myShape);
     }
 }

```

The image:

 ![DPI](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2d3d4112bd30a871528c81fc0d76cd0510f9a1b4.jpeg)

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [May 5, 2021, 1:05pm UTC](https://discourse.processing.org/t/map-image-onto-shape/29879/3 "2021-05-05T13:05:40Z")

</div>

Hi! Welcome to the forum!

It seems the problem is that you need to use P3D for texture mapping

```auto
        size(displayHeight*3>>2, displayHeight*3>>2,P3D);

```

I learned that by dropping `myShape` and drew in immediate mode - in that case there is an error that `vertex(x,y,u,v)` is not available in this renderer.

also `PShape` is not meant to be instantiated in `draw` loop. Although you can do it, the performance is not as good, so you should move it to `setup` or use the immediate mode if you want to constantly change vertex coordinates etc.

---

<div class="post-metadata">

**Author:** ![Frinkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/frinkel/32/13051_2.png) [@Frinkel](https://discourse.processing.org/u/Frinkel)\
**Post date:** [May 5, 2021, 1:15pm UTC](https://discourse.processing.org/t/map-image-onto-shape/29879/4 "2021-05-05T13:15:46Z")

</div>

Thank you so much! I had previously tried with P3D, but it gave me an error, so I anbandoned it. But I just now found out, that I had only imported the core.jar, but was missing both jogl and gluegen jars, after importing those, it seems to work as intended! 😃

(as to instantiating it in the draw loop, it was only for testing purposes 🙂 )
