Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.