Texturing a Mesh? How?

Blitz3D Forums/Blitz3D Programming/Texturing a Mesh? How?

Slider(Posted 2003) [#1]
Why doesn't the following code texture a mesh?

  side = CreateMesh() 					

  sideTexture = LoadTexture("c:\blitz\bright.bmp")
  sideBrush = CreateBrush()                            
  BrushTexture(sideBrush, sideTexture)
    	
  sideSurface = CreateSurface(side, sideBrush)
  
  AddVertex sideSurface,-1,-1,-1             
  AddVertex sideSurface, 1,-1,-1 
  AddVertex sideSurface, 1,-1, 1 
  AddVertex sideSurface,-1,-1, 1

  AddTriangle sideSurface,0,1,2             
  AddTriangle sideSurface,0,2,3

  ; Paint the mesh with the textured brush?
  PaintMesh(side, sideBrush)



Slider(Posted 2003) [#2]
I forgot to add that "c:\blitz\bright.bmp" is a copy of the grass.bmp texture that comes with blitz.

Also the mesh appears, but is a single solid greeny colour. Looks as though the first texture pixel is being used to fill the whole mesh.


Ross C(Posted 2003) [#3]
Try messing about with the entityfx command. Can't remember which flag it is tho. Think it might be the vertex colouring flag you need to use :)


Ross C(Posted 2003) [#4]
Hey, sorry. I see you aren't setting the UV co-ords when your adding a vertex. This must be done so the texture is layed out properly.

v0=AddVertex sideSurface,-1,-1,-1,0,1           
v1=AddVertex sideSurface, 1,-1,-1,1,1 
v2=AddVertex sideSurface, 1,-1, 1,1,0 
v3=AddVertex sideSurface,-1,-1, 1,0,0

  AddTriangle sideSurface,v0,v1,v2             
  AddTriangle sideSurface,v0,v2,v3


try that :)


Slider(Posted 2003) [#5]
Still no joy!


Ross C(Posted 2003) [#6]
Don't use the brush command. Try simply loading in the texture then applying it to the mesh

EntityTexture side,sideTexture


Take out all references to the brush, and use vertex colouring. Also, mind and stick in the addvertex commands i put above.


Slider(Posted 2003) [#7]
So we now have...

  side = CreateMesh() 					

  sideTexture = LoadTexture("c:\blitz\bright.bmp")
    	
  sideSurface = CreateSurface(side)
  
  v0=AddVertex sideSurface,-1,-1,-1,0,1           
  v1=AddVertex sideSurface, 1,-1,-1,1,1 
  v2=AddVertex sideSurface, 1,-1, 1,1,0 
  v3=AddVertex sideSurface,-1,-1, 1,0,0

  AddTriangle sideSurface,v0,v1,v2             
  AddTriangle sideSurface,v0,v2,v3

  EntityTexture(side, sideTexture)


Unfortunately it still doesn't work!!! Arhhh! Surely this should be easy...


Ross C(Posted 2003) [#8]
No brackets on EntityTexture.


Ross C(Posted 2003) [#9]
side = CreateMesh() 					

  sideTexture = LoadTexture("c:\blitz\bright.bmp")
    	
  sideSurface = CreateSurface(side)
  
  v0=AddVertex sideSurface,-1,-1,0,0,1           
  v1=AddVertex sideSurface, 1,-1,0,1,1 
  v2=AddVertex sideSurface,-1, 1,0,1,0 
  v3=AddVertex sideSurface, 1, 1,0,0,0

  AddTriangle sideSurface,v0,v1,v2             
  AddTriangle sideSurface,v0,v2,v3

  EntityTexture side, sideTexture 


Try that?


Slider(Posted 2003) [#10]
No difference! I'm fairly sure the brackets are optional on all commands.


Ross C(Posted 2003) [#11]
I'm at college right now so i can't test it. I'll see if i can find some mesh stuff on this site.


Ross C(Posted 2003) [#12]
side = CreateMesh() 					

  sideTexture = LoadTexture("c:\blitz\bright.bmp",1)
    	
  sideSurface = CreateSurface(side)
  
  EntityFx side,4

  v0=AddVertex sideSurface,-1,-1,0,0,0           
  v1=AddVertex sideSurface, 1,-1,0,1,0 
  v2=AddVertex sideSurface,-1, 1,0,0,1 
  v3=AddVertex sideSurface, 1, 1,0,1,1

  AddTriangle sideSurface,v0,v1,v2             
  AddTriangle sideSurface,v0,v2,v3

  EntityTexture side, sideTexture


Does that work? What do you get? A green color?


Slider(Posted 2003) [#13]
It doing what it always did: displaying a flat shaded green square. I'm guessing the green colour is coming from the texture (as no other colour is defined), so something must be wrong the the texture u/v. Maybe I'm not supplying them?!?


Ross C(Posted 2003) [#14]
That's what the to end values are on the end of add vertex. Did you try fiddling with the various options of the EntityFx flag?

Also you could try

UpdateNormals side


After you create the triangle.


Slider(Posted 2003) [#15]
Still no luck! Help!!! =-)


Ross C(Posted 2003) [#16]
Yeah come-on ppl, someone else step in here. I can't actually test anything! :D


Slider(Posted 2003) [#17]
If I texture a cube created with the CreateCube() command it works, so there must be something that isn't setup correctly in my hand made mesh. I'm new to this so it might be something very obvious!


Slider(Posted 2003) [#18]
I've got it!

This code was missing:
  VertexTexCoords sideSurface, 0, 0, 1
  VertexTexCoords sideSurface, 1, 1, 1
  VertexTexCoords sideSurface, 2, 1, 0
  VertexTexCoords sideSurface, 3, 0, 0



Ross C(Posted 2003) [#19]
That's strange :S The addvertex command, lets you assign the texture co-ords. Oh well, glad you got it working :)


Slider(Posted 2003) [#20]
Doh! I missed those extra parameters Ross. Thanks for the help.


Ross C(Posted 2003) [#21]
np!