0
\$\begingroup\$

I'm getting some trouble using the texture() method inside beginShape()/endShape() clause.

In the display()-method of my class TowerElement (a bar which is DYNAMIC), I draw the object like following:

void display(){
    Vec2 pos = level.getLevel().getBodyPixelCoord(body);
    float a = body.getAngle(); // needed for rotation

    pushMatrix();

    translate(pos.x, pos.y);
    rotate(-a); 

    fill(temp);    // temp is a color defined in the constructor
    stroke(0);

    beginShape();
    vertex(-w/2,-h/2);
    vertex(w/2,-h/2);
    vertex(w/2,h-h/2);
    vertex(-w/2,h-h/2);
    endShape(CLOSE);

    popMatrix();

}

Now, according to the API, I can use the texture() method inside the shape definition. Now when I remove the fill(temp) and put texture(img) (img is a PImage defined in the constructor), the stroke gets drawn, but the bar isn't filled and I get the warning

texture() is not available with this renderer

What can I do in order to use textures anyway? I don't even understand the error message, since I do not know much about different renderers.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I post this as an answer since I "reach the goal", but I don't know if it is good practice.

Instead of trying to attach a texture to a shape, I just draw an image(...) instead of a rect. In above code, before I tried to work with own shapes and texture, I simply had

void display(){
    //(...)
    rectMode(CENTER);
    pushMatrix();
    translate(pos.x, pos.y);
    rotate(-a);
    fill(temp);
    rect(0,0,w,h);
    popMatrix();
}

Now I tried to just remove rectMode(CENTER) and replacing rect(0,0,w,h) with

image(tex, -w/2, -h/2, w, h);

and it results in a "textured bar". Nevertheless I'm not sure if this is a good approach.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .