Texture mapping on polygons?
in
Programming Questions
•
3 years ago
Hi everyone, this is my first post here.
I've been working on a project where I have a bunch of geometric objects in 3d space that are made up of groups of polygons kind of mashed together. I got everything working fine, and wanted to take the next step and start playing with texture maps, but I was unable to get the texture mapping to work. The color of the object would change but the texture would just not show up.
any ideas?
Here's the code, thanks!
PImage tmap;
void setup() {
size(640, 360, P3D);
tmap = loadImage("texture1.jpg");
noStroke();
}
void draw() {
background(0);
translate(width / 2, height / 2);
rotateY(map(mouseX, 0, width, -PI, PI));
rotateZ(PI/6);
drawPoly(5,200);
}
void drawPoly(int numSides, float radius){
float angle = 2*PI/numSides;
float[][] pointArray = new float[numSides][2];
for(int i=0; i<numSides; i++){
pointArray[i][0] = radius * sin(angle*i);
}
for(int i=0; i<numSides; i++){
pointArray[i][1] = radius * cos(angle*i);
}
beginShape();
for(int i=0; i<numSides; i++){
texture(tmap);
vertex(pointArray[i][0], pointArray[i][1]);
}
endShape();
}
1