Advertisement

Texture coords

Started by June 20, 2004 03:38 AM
3 comments, last by Hamster 20 years, 5 months ago
Hi, I have 4096X4096 texture and x X y height_map. I need to strech the texture on my height_map (x*y vertices, (x-1)*(y-1)*2 polygons) what are the u v coords to do so? maybe this will help to understand how the polygons and vertices set at: num_verts = MapSizeX * MapSizeZ; num_polys = (MapSizeX - 1) * (MapSizeZ - 1) * 2; for (kk = 0; kk < MapSizeX - 1; kk++) { for (ll = 0; ll < MapSizeZ - 1; ll++) { //--------------- // vertex indices vert1 = base_vert + kk * MapSizeZ + ll; // kk , ll vert2 = vert1 + 1; // kk , ll+1 vert3 = vert1 + MapSizeZ; // kk+1, ll vert4 = vert3 + 1; // kk+1, ll+1 //--------------- // texture coords u1 = u2 = u3 = u4 = v1 = v2 = v3 = v4 = //----- first poly // vertices Polygons[poly].P1 = vert1; Polygons[poly].P2 = vert2; Polygons[poly].P3 = vert3; // texture coords Polygons[poly].U1 = u1; Polygons[poly].U2 = u2; Polygons[poly].U3 = u3; Polygons[poly].V1 = v1; Polygons[poly].V2 = v2; Polygons[poly].V3 = v3; poly++; //----- second poly // vertices Polygons[poly].P1 = vert2; Polygons[poly].P2 = vert4; Polygons[poly].P3 = vert3; // texture coords Polygons[poly].U1 = u2; Polygons[poly].U2 = u4; Polygons[poly].U3 = u3; Polygons[poly].V1 = v2; Polygons[poly].V2 = v4; Polygons[poly].V3 = v3; poly++; } } I need to fill in the u1...u4,v1...v4.. i'm using quads as you can see. Using c/c++ with opengl . Thanks
Keep in mind that 4096x4096-textures are not supported by all cards. You can get an overview of how large textures diffrent cards support by visiting this page.
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
Advertisement
what about 1024X1024 ?

What will be the texture coords then?

Thanks
My card is: NVIDIA GeForce FX 5900
it support 4096X4096
This is some simple code to give you a rough idea of what needs to be done.

//create space for the texture coordsfloat *texcoords = new float[ num_verts * 2 ];//be sure to delete these when you're finished with themfor( unsigned int z = 0; z < MapSizeZ; z++ ){  for( unsigned int x = 0; x < MapSizeX; x++ )  {    //fill u coord    texcoords[(x + z * MapSizeZ) * 2] = (float)x/(float)(MapSizeX-1);    //fill v coord    texcoords[(x + z * MapSizeZ) * 2 + 1] = (float)z/(float)(MapSizeZ-1);  }}


That should give you an array of u and v coords that tiles the whole texture across the terrain once.

I *think*, though can't be sure by looking at your code, that you should then be able to assign texture coords to the poly as follows, (assuming that P1, P2, and P3 in the poly store indices into an array of type Vertex).

//----- first poly// verticesPolygons[poly].P1 = vert1;Polygons[poly].P2 = vert2;Polygons[poly].P3 = vert3;// texture coordsPolygons[poly].U1 = vert1*2;Polygons[poly].U2 = vert2*2;Polygons[poly].U3 = vert3*2;Polygons[poly].V1 = vert1*2 + 1;Polygons[poly].V2 = vert2*2 + 1Polygons[poly].V3 = vert3*2 + 1;poly++;//and so on and so forth


This would fill U1 and V1 (and the others) with the appropriate indices to the texcoords array.

This topic is closed to new replies.

Advertisement