# Setting texture to POLYGON_ARRAY

No replies
vdavidovski
Offline
Joined: 2007-05-30

Hello!

I have a square (terrain) containing 9 equal sized squares. I would like to set a an image as a texture that will be stretched over all 9 squares. What I currently have is that each square takes the image and applies it as a texture, but the texture is not divided between the squares.

A little bit of help would be highly appreciated.

Here is the code:

GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
Point3f[] coordinates = new Point3f[36];

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
coordinates[counter] = new Point3f(i, j, (float) coordsScaled[i][j]);
counter++;
coordinates[counter] = new Point3f(i + 1, j, (float) coordsScaled[i + 1][j]);
counter++;
coordinates[counter] = new Point3f(i + 1, j + 1, (float) coordsScaled[i + 1][j + 1]);
counter++;
coordinates[counter] = new Point3f(i, j + 1, (float) coordsScaled[i][j + 1]);
counter++;
}
}
int[] stripCounts = new int[9];
for (int i = 0; i < 9; i++)
stripCounts[i] = 4;

int[] contourCount = new int[9];
for (int i = 0; i < 9; i++)
contourCount[i] = 1;

gi.setCoordinates(coordinates);
gi.setStripCounts(stripCounts);
gi.setContourCounts(contourCount);

// The number of texture coordinate sets that will be specified for this
// GeometryInfo object
int numSets = 1;

// The dimensionality of the texture coordinates
int dim = 2;

gi.setTextureCoordinateParams(numSets, dim);

// The float array of texture coordinates
float[] texCoords = new float[72];

float lenUnit = 1f;
float widUnit = 1f;

for (int v = 0; v < 72; v++) {
texCoords[v] = 0.0f;
texCoords[++v] = 0.0f;
texCoords[++v] = 0.0f;
texCoords[++v] = widUnit;
texCoords[++v] = lenUnit;
texCoords[++v] = widUnit;
texCoords[++v] = lenUnit;
texCoords[++v] = 0.0f;
}

int texCoordSet = 0;

gi.setTextureCoordinates(texCoordSet, texCoords);

NormalGenerator ng = new NormalGenerator();
ng.generateNormals(gi);

Geometry geometry = gi.getGeometryArray();
Shape3D shape = new Shape3D(geometry, appearance);