Texturing a Quadmesh

Blitz3D Forums/Blitz3D Programming/Texturing a Quadmesh

BlackJumper(Posted 2003) [#1]
The code which follows is cobbled together from a couple of examples... I am trying to create a square and then texture it (ultimately with a masked texture) - I found the restrictions on sprites to be a problem, so abandoned that strategy.

What am I missing to allow the quad to be painted (or textured directly) in the way that the cube is ?

Graphics3D 640, 480
SetBuffer BackBuffer()

Global gamecam = CreateCamera()
Global alight = CreateLight()
Global acube = CreateCube()

CameraViewport gamecam, 0, 0, GraphicsWidth(), GraphicsHeight()
PositionEntity alight, 0, 0, -10
PositionEntity acube, 6,0,8, True

MyTexture = LoadTexture("a_256_image.jpg")
MyBrush = CreateBrush(255, 255, 255) ;
;MyBrush = LoadBrush("a_256_image.jpg")

Global quadmesh = CreateMesh()
surf = CreateSurface( quadmesh, MyBrush)
AddVertex surf, -1, 1, 0
AddVertex surf, 1, 1, 0
AddVertex surf, 1, -1, 0
AddVertex surf, -1, -1, 0

AddTriangle surf, 0, 1, 2
AddTriangle surf, 0, 2, 3

UpdateNormals quadmesh

PositionMesh quadmesh, -1, 0, 8

; Set initial uv scale values 
u_scale#=1 
v_scale#=1 

While Not KeyDown( 1 ) 

; Change uv scale values depending on key pressed 
If KeyDown( 208 )=True Then u_scale#=u_scale#-0.01 
If KeyDown( 200 )=True Then u_scale#=u_scale#+0.01 
If KeyDown( 203 )=True Then v_scale#=v_scale#-0.01 
If KeyDown( 205 )=True Then v_scale#=v_scale#+0.01 

PaintMesh quadmesh, MyBrush
PaintMesh acube, MyBrush

ScaleTexture MyTexture,u_scale#,v_scale# 
BrushTexture MyBrush, MyTexture

UpdateWorld
RenderWorld
Flip

Wend


I have messed around with EntityTexture, various texture flags and trying to scale the brush directly, all without success.

Any advice ?


Sunteam Software(Posted 2003) [#2]
In your AddVertex commands you need to specify U and V coords so that Blitz knows how to position the texture.


BlackJumper(Posted 2003) [#3]
Thanks SunTeam, got it sorted now !!

In case its any use to others, the modified code looks like this:

Global quadmesh = CreateMesh()
surf = CreateSurface( quadmesh, MyBrush)
AddVertex surf, -1, 1, 0, 0, 0
AddVertex surf, 1, 1, 0, 1, 0
AddVertex surf, 1, -1, 0, 1, 1
AddVertex surf, -1, -1, 0, 0, 1

AddTriangle surf, 0, 1, 2
AddTriangle surf, 0, 2, 3