Archived

This topic is now archived and is closed to further replies.

Chaucer

texturing, one large texture

Recommended Posts

Chaucer    122
Hi. I was wondering how one might go about using one large texture that is a combination of all the smaller textures they''d like to use (grass, dirt, rock, etc.) When it comes to blending, that is, the vertex buffer would have to contain different texture coords for each texture that is going to be blended on a vertex (using vertex alpha blending). So you''d have to have a tex coord for each texture type, then use diffuse and specular rgb and alpha for blending weights? If you only wanted to blend 2 textures at a time, 3 passes for 6 textures, how could you specify which pass uses which tex coords? Thanks

Share this post


Link to post
Share on other sites
Xsist10    122

#define TILES_X 4 // number of columns of tiles
#define TILES_Y 4 // number of rows of tiles
#define MAX_TILES 16 // number of textures in one texture

#define TILE_WIDTH 1.0f / TILES_X // width of tiles (0.25f)
#define TILE_HEIGHT 1.0f / TILES_Y // height of tiles (0.25f)

#define BORDER 0.0035f // border of tiles (linear filtering creates problems)

#define TRANS_MAX 7
#define NORMAL 0
#define FLIP_X 1
#define FLIP_Y 2
#define FLIP_XY 3
#define ROTATE_90 4
#define ROTATE_180 5
#define ROTATE_270 6


struct tTexCoord {
float u,v;
};

tTexCoord TexCoord[4][MAX_TILES*MAX_TRANS];


void swap(float &a, float &b) { float temp=a; a=b; b=temp; }

void generateTexCoord()
{
int i,j;
for (j=0; j<MAX_TRANS; j++)
for (i=0; i<MAX_TILES; i++)
{
TexCoord[0][i+(j*MAX_TILES)].u = (i % TILES_X) * TILES_WIDTH + BORDER;
TexCoord[0][i+(j*MAX_TILES)].v = (i / TILES_X) * TILES_HEIGHT + BORDER;

TexCoord[1][i+(j*MAX_TILES)].u = (i % TILES_X) * TILES_WIDTH + TILES_WIDTH + BORDER;
TexCoord[1][i+(j*MAX_TILES)].v = (i / TILES_X) * TILES_HEIGHT + BORDER;

TexCoord[2][i+(j*MAX_TILES)].u = (i % TILES_X) * TILES_WIDTH + TILES_WIDTH + BORDER;
TexCoord[2][i+(j*MAX_TILES)].v = (i / TILES_X) * TILES_HEIGHT + TILES_HEIGHT + BORDER;

TexCoord[3][i+(j*MAX_TILES)].u = (i % TILES_X) * TILES_WIDTH + BORDER;
TexCoord[3][i+(j*MAX_TILES)].v = (i / TILES_X) * TILES_HEIGHT + TILES_HEIGHT + BORDER;

swith (j) {
case (FLIP_X) {
swap(TexCoord[0][i+(j*MAX_TILES)].u, TexCoord[1][i+(j*MAX_TILES)].u);
swap(TexCoord[2][i+(j*MAX_TILES)].u, TexCoord[3][i+(j*MAX_TILES)].u);
} break;
case (FLIP_Y) {
swap(TexCoord[0][i+(j*MAX_TILES)].v, TexCoord[1][i+(j*MAX_TILES)].v);
swap(TexCoord[2][i+(j*MAX_TILES)].v, TexCoord[3][i+(j*MAX_TILES)].v);
} break;
case (FLIP_XY) {
swap(TexCoord[0][i+(j*MAX_TILES)].u, TexCoord[1][i+(j*MAX_TILES)].u);
swap(TexCoord[2][i+(j*MAX_TILES)].u, TexCoord[3][i+(j*MAX_TILES)].u);
swap(TexCoord[0][i+(j*MAX_TILES)].v, TexCoord[1][i+(j*MAX_TILES)].v);
swap(TexCoord[2][i+(j*MAX_TILES)].v, TexCoord[3][i+(j*MAX_TILES)].v);
} break;
case (ROTATE_90) {
tTexCoord temp = TexCoord[0][i+(j*MAX_TILES)];
TexCoord[0][i+(j*MAX_TILES)] = TexCoord[1][i+(j*MAX_TILES)];
TexCoord[1][i+(j*MAX_TILES)] = TexCoord[2][i+(j*MAX_TILES)];
TexCoord[2][i+(j*MAX_TILES)] = TexCoord[3][i+(j*MAX_TILES)];
TexCoord[3][i+(j*MAX_TILES)] = temp;
} break;
case (ROTATE_180) {
tTexCoord temp = TexCoord[0][i+(j*MAX_TILES)];
TexCoord[0][i+(j*MAX_TILES)] = TexCoord[2][i+(j*MAX_TILES)];
TexCoord[2][i+(j*MAX_TILES)] = temp;
temp = TexCoord[1][i+(j*MAX_TILES)];
TexCoord[1][i+(j*MAX_TILES)] = TexCoord[3][i+(j*MAX_TILES)]
TexCoord[3][i+(j*MAX_TILES)] = temp;
} break;
case (ROTATE_270) {
tTexCoord temp = TexCoord[0][i+(j*MAX_TILES)];
TexCoord[0][i+(j*MAX_TILES)] = TexCoord[3][i+(j*MAX_TILES)];
TexCoord[3][i+(j*MAX_TILES)] = TexCoord[2][i+(j*MAX_TILES)];
TexCoord[2][i+(j*MAX_TILES)] = TexCoord[1][i+(j*MAX_TILES)];
TexCoord[1][i+(j*MAX_TILES)] = temp;
} break;
}
}
}
}



Now all you have to do to assign a tile to a block on your terrain is:


Terrain[x][y].tile = 5 + (FLIP_X * MAX_TILES);


[edited by - xsist10 on July 9, 2003 7:03:41 AM]

Share this post


Link to post
Share on other sites