Vertex color

Blitz3D Forums/Blitz3D Programming/Vertex color

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here is what i'm trying to do :

- Load a mesh( with coloured Vertices ) and position a single surface to each vertex of the mesh --> this works
- applying the vertex color from the mesh to the single surfaces--->???

(this is just a modification of Rob's single surface stuff:)
http://www.blitzbasic.com/Community/posts.php?topic=32064


Global fpsindex#,fpstime#,fpsfold_millisecs#,fpsfps#,time,xyzturn

Type layer
	Field mesh
	Field count
	Field spritebank ; pointer to a type just for holding a list of sprites
End Type

Type sprite
	Field x#,y#,z#
	Field r,g,b
	Field s#,a#
	Field verti[3]
	Field surf
End Type

;--------------------------------------------------------------------------------------------
Graphics3D 640,480,32,2
SetBuffer BackBuffer()
Global camera=CreateCamera()
CameraRange camera,1,9000

CameraClsColor camera,141,195,245
light=CreateLight(1)
PositionEntity light,1000,1000,-1000
;--------------------------------------------------------------------------------------------
fire=LoadTexture ("fire1.png",2+48)

test=CreateLayer()
EntityTexture test,fire


Mymesh=LoadMesh("cloud1.b3d")



;EntityAlpha Mymesh,0.5
EntityFX Mymesh,2
HideEntity Mymesh

For scount=1 To CountSurfaces(Mymesh)
		surface = GetSurface(Mymesh,scount)
		numverts=CountVertices(surface)-1
		For i=0 To numverts
;Coordinates of the vertices					
			xv#=VertexX(surface,i)
			yv#=VertexY(surface,i)
			zv#=VertexZ(surface,i)
;VertexColor
			vcr=VertexRed#(surface,i)
    		vcg=VertexGreen#(surface,i)
    		vcb=VertexBlue#(surface,i)

			
			
			
			
	temp = AddSprite(test)
	
	PositionSprite temp,xv#,yv#,zv#,vcr,vcg,vcb



Next
Next
;--------------------------------------------------------------------------------------------
HidePointer

While Not KeyHit(1)
	MoveEntity camera,0,0,MouseZSpeed()*10
	mxspd#=MouseXSpeed()*.2
	myspd#=MouseYSpeed()*.2
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	TurnEntity camera,myspd,-mxspd,0
	

	
	
UpdateSprites()
	
	UpdateWorld
	RenderWorld
	Text 0,0,fps()
	Flip 0
Wend
End

;--------------------------------------------------------------------------------------------

Function UpdateSprites()
	For s.sprite=Each sprite
		TFormPoint s\x,s\y,s\z,0,camera
		If TFormedZ#()>0
			TFormVector -s\s,-s\s,0,camera,0 
			VertexCoords s\surf,s\verti[0],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()
			TFormVector s\s,-s\s,0,camera,0 
			VertexCoords s\surf,s\verti[1],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()
			TFormVector -s\s,s\s,0,camera,0 
			VertexCoords s\surf,s\verti[2],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()
			TFormVector s\s,s\s,0,camera,0 
			VertexCoords s\surf,s\verti[3],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()
		EndIf
	Next
End Function

;--------------------------------------------------------------------------------------------
Function CreateLayer()
	l.layer=New layer	
	l\mesh=CreateMesh() : surf=CreateSurface(l\mesh)
	l\spritebank=CreateBank()
	NameEntity l\mesh,Handle(l)
	EntityColor l\mesh,255,255,255
	EntityFX l\mesh,2
	EntityBlend l\mesh,3
	Return l\mesh
End Function
;--------------------------------------------------------------------------------------------
Function AddSprite(mesh)
	l.layer=Object.layer(EntityName(mesh))
	surf=GetSurface(l\mesh,1)
	l\count=l\count+1
	ResizeBank l\spritebank,l\count*4
	
	;create a new sprite
	s.sprite=New sprite
	s\verti[0]=AddVertex(surf,0,0,0,0,1) ;topleft
	s\verti[1]=AddVertex(surf,0,0,0,1,1) ;topright
	s\verti[2]=AddVertex(surf,0,0,0,0,0) ;bottomleft
	s\verti[3]=AddVertex(surf,0,0,0,1,0) ;bottomright
	AddTriangle(surf,s\verti[1],s\verti[2],s\verti[3])
	AddTriangle(surf,s\verti[2],s\verti[1],s\verti[0])
	s\s=1 : s\a=1
	s\r=255 : s\g=255 : s\b=255
	s\x=0 : s\y=0 : s\z=0
	s\surf=surf
	;put the new sprite into the bank
	PokeInt l\spritebank,(l\count*4)-4,Handle(s)
	Return Handle(s)
End Function
;--------------------------------------------------------------------------------------------
Function PositionSprite(sprite,x#,y#,z#,vcr,vcg,vcb)

	s.sprite = Object.sprite( sprite )
	s\x=x
	s\y=y
	s\z=z
	s\r=vcr
	s\g=vcg
	s\b=vcb



End Function
;--------------------------------------------------------------------------------------------



;--------------------------------------------------------------------------------------------
Function fps()
	fpsindex=fpsindex+1
	fpstime=fpstime+MilliSecs()-fpsfold_millisecs
	If fpstime=>1000
		fpsfps=fpsindex
		fpstime=0
		fpsindex=0
	EndIf
	fpsfold_millisecs=MilliSecs()
	Return fpsfps
End Function




Media(15 Kb):
http://www.boteco.de/bolo/upload1/Cloud1.zip

Use Vertexcolor surf,vert,red,green,blue.

Bear in mind though that entityblend 3 is enabled for that surface. Depends what effect you are after I suppose.

Thanks !