texture not visible

Blitz3D Forums/Blitz3D Programming/texture not visible

Fedor(Posted 2004) [#1]
I have created a quad that I want to texture with some image I have. But somehow it stays invisible or (depending on the image I use) gives me a strange color (might very well be one color used in the image.
So somehow I think I haven't quite layed out my texture properly. Could anyone of you tell me what I am doing wrong here?

Graphics3D 800,600

SetBuffer BackBuffer()

camera=CreateCamera()
CameraViewport camera,0,0,800,600

;setup lighting
Light=CreateLight(1)
RotateEntity Light,45,20,0
PositionEntity Light,640,300,640
LightColor Light,160,160,100

cube=CreateCube()
PositionEntity cube,1,1,6
tex0=LoadTexture("tree.bmp",1)
entitytexture cube,tex0


sprite=CreateMySprite()
PositionEntity sprite,0,0,5


While Not KeyHit(1)

pointentity sprite,camera
TurnEntity cube ,0.1,0.2,-0.3
UpdateWorld
RenderWorld

Text 340,500,"Texturing Demo"

Flip

Wend
End



Function CreateMySprite()

tx=Loadtexture("wall.bmp",1)

mesh=CreateMesh()
surf=CreateSurface( mesh)

AddVertex surf,-1,1,0
AddVertex surf,1,1,0
AddVertex surf,1,-1,0
AddVertex surf,-1,-1,0

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

scaletexture tx,2,2
entitytexture mesh,tx

UpdateNormals mesh
Return mesh
End Function

By the way, the cube does get textured well...


N(Posted 2004) [#2]
Looks like you're missing UV coordinates.

Change
AddVertex surf,-1,1,0
AddVertex surf,1,1,0
AddVertex surf,1,-1,0
AddVertex surf,-1,-1,0


to

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



Fedor(Posted 2004) [#3]
ok,
that worked!

silly me.
Thanks!