Perfectly Fitting a Texture

Blitz3D Forums/Blitz3D Programming/Perfectly Fitting a Texture

Jay Mattis(Posted 2004) [#1]
Okay. If I do:

somecube=CreateCube() or somecube=CreateQuad() or something
ScaleMesh somecube,2,4,1

How can I create a texture so that 0,0 on the texture will correspond to the upperleft of the front face and texturewidth,textureheight will correspond to the lowerright of the front face?


jfk EO-11110(Posted 2004) [#2]
You can parse the vertices and set the UVs of every vertex. See VertexTexCoords.


Idiot(Posted 2004) [#3]
I'd also like to know more about how to position textures, but I don't understand all this vertex/surface/brush stuff.

If you have a cube, how do you get a handle for each side of the cube to move/scale the texture on?

Would it be easier just to create a cube and texture it in a modeling program?

I'd like to be able to create walls of any length and have the textures on the sides and top look correct no matter how long the wall is.


jfk EO-11110(Posted 2004) [#4]
The problem with the CreatCube cubes is: they use shared vertices. Imagine, every side is built on 2 Triangles. you could build a cube from 6*2 Triangles. This would be 6*2*3 Triangle-Corners or Vertices, which is 36. THis way you can define each side completely independently.

Meshes are organised by a list of Vertices, containing the exact position, plus a list of triangles, containing information about which vertices are used by each Triangle, also known as indexed triangles.

So when you have a cube, you could also store only 6 corner points, insteat of 36. This will probably be rendered faster, or at least it will use less memory.

Unfortunately the Texture Coords are stored for each Vertex, so if you use only 6 Vertices for a cube, multiple Triangles use shared Vertices and therefore you cannot position every Vertexes UV independently.

Hmm - all a bit confusing.

If you want a cube withindividual sides, you can create it using the createmesh, addvertex and addtriangle commands ,and of course the vertextexcoords commands and so on, or you could also use an external app to build a cube with 6 sides using unshared vertices.

you could use Lithuwrap for example to place the 6 sides onthe texture to be able to use one texture that contains 6 Cubeside gfx.

I recommand you create a quad made of 2 Triangles and texture it manually. If you have once understood this, the rest is easy.

You'll find an example on how to create a quad in the skybox function from the castle demo in the samples (markio)