|
texture - texture handle coords - which vertex texture coordinate set the texture reads: 0: first coordinate set (default) 1: second coordinate set |
|
Selects which of the two vertex texture coordinate sets a texture uses. Every vertex carries two independent u,v pairs (set with AddVertex and VertexTexCoords). By default every texture reads set 0; TextureCoords texture,1 switches that texture to set 1. The classic use is lightmapping: the base texture tiles across the mesh using set 0, while the lightmap uses set 1 to cover the whole mesh exactly once - two different mappings on the same geometry at the same time. See also: VertexTexCoords, TextureBlend, EntityTexture, BrushTexture. |
; TextureCoords Example
; ---------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
; Build a single quad whose vertices carry TWO sets of UV coordinates
mesh=CreateMesh()
surf=CreateSurface(mesh)
v0=AddVertex(surf,-1.5,-1,0)
v1=AddVertex(surf,-1.5,1,0)
v2=AddVertex(surf,1.5,1,0)
v3=AddVertex(surf,1.5,-1,0)
AddTriangle surf,v0,v1,v2
AddTriangle surf,v0,v2,v3
; First UV set (coord_set 0): the texture mapped normally
VertexTexCoords surf,v0,0,1,0,0
VertexTexCoords surf,v1,0,0,0,0
VertexTexCoords surf,v2,1,0,0,0
VertexTexCoords surf,v3,1,1,0,0
; Second UV set (coord_set 1): flipped upside-down and tiled twice
VertexTexCoords surf,v0,0,0,0,1
VertexTexCoords surf,v1,0,2,0,1
VertexTexCoords surf,v2,2,2,0,1
VertexTexCoords surf,v3,2,0,0,1
tex=LoadTexture("media/b3dlogo.jpg")
EntityTexture mesh,tex
; Full-bright and double-sided, so the quad is easy to see from anywhere
EntityFX mesh,17
PositionEntity mesh,0,0,4
coords=0
While Not KeyDown(1)
; Space toggles which UV set the texture uses
If KeyHit(57) Then coords=1-coords
; Tell the texture which vertex UV set to read
TextureCoords tex,coords
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"Space: toggle UV set Arrows: camera Esc: exit"
Text 0,20,"TextureCoords tex,"+coords
Flip
Wend
End