Blitz3D+ Command Reference

VertexTexCoords surface,index,u#,v#[,w#][,coord_set]

Parameters

surface - surface handle
index - index of the vertex, from 0 to CountVertices( surface )-1
u# - u texture coordinate
v# - v texture coordinate

w# (optional) - w texture coordinate; 1 (default). Accepted for compatibility but not used by the renderer.

coord_set (optional) - which texture coordinate set to write:
0: first coordinate set (default)
1: second coordinate set

Description

Sets the texture coordinates of an existing vertex.

Texture coordinates map an image onto geometry: u 0, v 0 is the image's top-left, 1,1 its bottom-right, and values outside 0-1 tile it. Changing them at runtime scrolls or stretches the texture over the mesh - though for whole-texture effects ScaleTexture and PositionTexture are usually easier.

Each vertex carries two independent coordinate sets, 0 and 1. A texture reads set 0 unless you switch it to set 1 with TextureCoords. The standard trick is lightmapping: the base texture tiles using set 0 while a lightmap covers the mesh once using set 1. AddVertex writes its u,v into both sets; this command lets you set them separately.

See also: TextureCoords, VertexU, VertexV, AddVertex, ScaleTexture.

Example

; VertexTexCoords Example
; -----------------------

; VertexTexCoords changes which part of the texture a vertex pins to.
; Scrolling the uv coordinates each frame slides the texture across
; the quad like a conveyor belt - the geometry itself never changes.

Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,0,-4

belt=CreateMesh()
surf=CreateSurface(belt)

; A simple quad facing the camera
v0=AddVertex(surf,-2,1,0)
v1=AddVertex(surf,2,1,0)
v2=AddVertex(surf,2,-1,0)
v3=AddVertex(surf,-2,-1,0)
AddTriangle surf,v0,v1,v2
AddTriangle surf,v0,v2,v3

; A tileable ground texture shows the scrolling clearly
tex=LoadTexture("media/MossyGround.BMP")
EntityTexture belt,tex

; Fullbright so no lighting setup is needed
EntityFX belt,1

offset#=0
tile#=2

While Not KeyDown(1)

    ; [ and ] change how many times the texture tiles across the quad
    If KeyDown(26) And tile>0.5 Then tile=tile-0.02
    If KeyDown(27) And tile<6 Then tile=tile+0.02

    ; Scroll steadily to the left
    offset=offset+0.004

    ; Re-pin all four corners - the documented command
    VertexTexCoords surf,v0,offset,0
    VertexTexCoords surf,v1,offset+tile,0
    VertexTexCoords surf,v2,offset+tile,tile
    VertexTexCoords surf,v3,offset,tile

    ; 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,"[ / ] : change tiling   Arrow keys: move camera   Esc: exit"
    Text 0,20,"VertexTexCoords surf,v0,"+offset+",0   (tiling "+tile+")"

    Flip

Wend

End

Index