Map image onto shape

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:

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:

Hi! Welcome to the forum!

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

        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.

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! :smiley:

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