Quote: "Never heard of the convert object fvf command before, but it sounds like it is a shader command? Sounds very complicated to me"
Not really.
Three dimensional models are made from triangles - "polys". The polys are made from vertices; the points that make up the corners of the triangles. The verts are comprised of data.
One piece of data the verts must have (as far as I know) is the location of the vertex. If you've added limbs to the model, the limb vertex positions will be in relation to the limb position; otherwise they'll be in relation to the object position.
Another piece of data that I can't imagine a vertex not having is/are the UV coordinates. The UV coordinates determine how a texture (image) is mapped onto a 3D object. For example, let's say you place a brick wall in your level but the bricks are too big. How do you make the bricks smaller? By adjusting the UV coordinates so that the texture is repeated more times in the same space, thus making the texture - and the bricks - smaller.
So how do you map two textures onto the same object differently? You add a second set of UV coordinates with different settings. The first thing you have to do is make sure you’re using the correct Flexible Vertex Format, or FVF. There are all kinds of things you can add to your vertex data and you can pick and choose what you want. Here are some examples:
Position (XYZ) 2
Normal 16
Diffuse 64
Specular 128
One set of UV coordinates 256
Two sets of UV coordinates 512
Three sets of UV coordinates 768
Four sets of UV coordinates 1024
Five sets of UV coordinates 1280
Six sets of UV coordinates 1536
Seven sets of UV coordinates 1792
Eight sets of UV coordinates 2048
You choose the data you want and add the numbers up. So, if you want position and two sets of UV coordinates, the FVF would be 514 - 2 for position plus 512 for two sets of UV coordinates. If you wanted to add a diffuse color to that, it’d be 578. To change the FVF of the 3D model, you use the CONVERT OBJECT FVF command.
Once you have the correct FVF, you can change the UV coordinates. One thing that I found confusing in the documentation is the use of the term “texture stage.” It seems to be used to mean both the different textures that are applied to a model and the UV coordinates.
These are not the same thing. You can apply several textures to a model that has only one set of UV coordinates (if they don‘t need to be different) or you can have a different set of UV coordinates for each texture. There isn’t any reason I’m aware of for having more sets of UV coordinates than textures.
To change the UV coordinates, you lock the vertex data, change it, then unlock it. Nothing will explain this better than an example:
set display mode 1024, 768, 32
sync on
sync rate 60
autocam off
color backdrop 0, 0
hide mouse
hide light 0
set ambient light 100
` Make a plain.
make object plain 1, 10.0, 10.0
position object 1, 0.0, 0.0, 10.0
convert object fvf 1, 514
lock vertexdata for limb 1, 0
PositionU1# = 0.0
PositionV1# = 0.0
PositionU2# = 1.0
PositionV2# = 1.0
set vertexdata uv 0, 0, PositionU2#, PositionV1#
set vertexdata uv 1, 0, PositionU1#, PositionV1#
set vertexdata uv 2, 0, PositionU2#, PositionV2#
set vertexdata uv 3, 0, PositionU1#, PositionV1#
set vertexdata uv 4, 0, PositionU1#, PositionV2#
set vertexdata uv 5, 0, PositionU2#, PositionV2#
PositionU1# = 0.0
PositionV1# = 0.0
PositionU2# = 5.0
PositionV2# = 5.0
set vertexdata uv 0, 1, PositionU2#, PositionV1#
set vertexdata uv 1, 1, PositionU1#, PositionV1#
set vertexdata uv 2, 1, PositionU2#, PositionV2#
set vertexdata uv 3, 1, PositionU1#, PositionV1#
set vertexdata uv 4, 1, PositionU1#, PositionV2#
set vertexdata uv 5, 1, PositionU2#, PositionV2#
unlock vertexdata
` Load the textures.
load image "Sand.png", 1, 0
load image "LightMap.png", 2, 0
` Apply the textures using SET BLEND MAPPING ON.
set blend mapping on 1, 0, 1, 11, 26
set blend mapping on 1, 1, 2, 3, 4
` Program loop.
do
sync
loop
end
In the example, a plain is made and the FVF is changed to 514 (position with two sets of UV coordinates). The vertex data is then locked and the UV coordinates are set for both sets of UV coordinates (I‘m trying not to use the term “texture stage”). Setting the UV coordinates for the first set (0) wasn’t necessary, since that’s the default; but I thought it made the example more clear. Note that the numbering for both UV coordinate sets and texture layers begin with zero. The textures were then applied using the SET BLEND MAPPING ON command. If you were going to use a shader, you’d just use the TEXTURE OBJECT command then apply the shader.
You can’t really see it in the picture, but the sand texture is tiled five times across and five times down while the light map is only applied once.
Anticipating one question, there are six vertices in a DBPro plain object because the verts aren’t welded. See the diagram.
Hopefully, this will give you an idea of how to apply a detail texture to your terrain. If you have any questions, just post them here.
Good luck.
- Jane
Edit: You wouldn't have to apply the textures using the TEXTURE OBJECT command, if you're using a shader, if the textures are specified in the shader.