[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

obsolete[LuaStudio] Bitmap3

! Bitmap class methodsFor: #samples !
drawTriangles: inGfx verts: verts indices: indices tex: tex cull: cull cols: cols
	" Draw triangles "

	inGfx drawTriangles: verts indices: indices 
		uvtData: tex culling: cull colours: cols 
		blendMode: 0
	! !


! Bitmap class methodsFor: #samples !
trianglesExample
	" Triangles example "
	
	| s0 s1 s2 s3 t0 data stage doUpdate |
	stage := Display stage.
	s0 := Display sprite new.
	s1 := Display sprite new.
	s2 := Display sprite new.
	s3 := Display sprite new.
	stage addChild: s0.
	stage addChild: s1.
	stage addChild: s2.
	stage addChild: s3.
	s0 scaleX: 0.5; scaleY: 0.5.
	s1 scaleX: 0.5; scaleY: 0.5.
	s2 scaleX: 0.5; scaleY: 0.5.
	s3 scaleX: 0.5; scaleY: 0.5.
	s1 x: 550 / 2.
	s3 x: s1 x.
	s2 y: 400 / 2.
	s3 y: s2 y.
	t0 := Lib sys getTime / 1000.
	data := BitmapData 
		bytes: (Lib project getBytes: '/assets/Image.jpg')
		rawAlpha: nil.

	doUpdate := [ | sx sy theta sin cos z w0 w1 x0 y0 vertices indices tex_uvt tex_uv cols gfx |
		sx := 1 / data width.
		sy := 1 / data height.
		theta := (Lib sys getTime / 1000) - t0.
		cos := theta cos.
		sin := theta sin.
		z := sin * 100. 
		w0 := 150 / (200 + z).
		w1 := 150 / (200 - z).
		x0 := 200.
		y0 := 200.
		vertices := #().
		vertices at: 1 put: x0 + (100 * cos * w0).
		vertices at: 2 put: y0 - (100 * w0).
		vertices at: 3 put: x0 + (100 * cos * w0).
		vertices at: 4 put: y0 + (100 * w0).
		vertices at: 5 put: x0 - (100 * cos * w1).
		vertices at: 6 put: y0 + (100 * w1).
		vertices at: 7 put: x0 - (100 * cos * w1).
		vertices at: 8 put: y0 - (100 * w1).
		indices := #(0 1 2 2 3 0).
		tex_uv := #().
		tex_uv at: 1 put: 100 * sx.
		tex_uv at: 2 put: 0.
		tex_uv at: 3 put: 100 * sx.
		tex_uv at: 4 put: 200 * sy.
		tex_uv at: 5 put: 300 * sx.
		tex_uv at: 6 put: 200 * sy.
		tex_uv at: 7 put: 300 * sx.
		tex_uv at: 8 put: 0.
		tex_uvt := #().
		tex_uvt at: 1 put: 100 * sx.
		tex_uvt at: 2 put: 0.
		tex_uvt at: 3 put: w0.
		tex_uvt at: 4 put: 100 * sx.
		tex_uvt at: 5 put: 200 * sy.
		tex_uvt at: 6 put: w0.
		tex_uvt at: 7 put: 300 * sx.
		tex_uvt at: 8 put: 200 * sy.
		tex_uvt at: 9 put: w1.
		tex_uvt at: 10 put: 300 * sx.
		tex_uvt at: 11 put: 0.
		tex_uvt at: 12 put: w1.

		cols := #( 16rFFFF0000 16rFF00FF00 16rFF0000FF 16rFFFFFFFF ).

		gfx := s0 graphics.
		gfx clear.
		gfx beginBitmapFill: data matrix: nil repeat: true smooth: false.
		gfx lineStyle: 4 color: 16r0000FF alpha: 1 
			pixelHinting: false scaleMode: nil 
			caps: nil joints: nil miterLimit: 3.
		gfx drawTriangles: vertices indices: indices  
			uvtData: tex_uvt culling: nil colours: nil
			blendMode: 0.

		gfx := s1 graphics.
		gfx clear.
		gfx beginBitmapFill: data matrix: nil repeat: true smooth: false.
		gfx lineStyle: 4 color: 15r0000FF alpha: 1 
			pixelHinting: false scaleMode: nil 
			caps: nil joints: nil miterLimit: 3.
		gfx drawTriangles: vertices indices: indices  
			uvtData: tex_uv culling: nil colours: nil
			blendMode: 0.

		gfx := s2 graphics.
		gfx clear.
		gfx beginBitmapFill: data matrix: nil repeat: true smooth: false.
		gfx lineStyle: 4 color: 16r808080 alpha: 1 
			pixelHinting: false scaleMode: nil 
			caps: nil joints: nil miterLimit: 3.
		gfx drawTriangles: vertices indices: indices  
			uvtData: tex_uv culling: nil colours: nil
			blendMode: 0.

		gfx := s3 graphics.
		gfx clear.
		gfx beginBitmapFill: data matrix: nil repeat: true smooth: false.
		gfx lineStyle: 4 color: 16r808080 alpha: 1 
			pixelHinting: false scaleMode: nil 
			caps: nil joints: nil miterLimit: 3.
		gfx drawTriangles: vertices indices: indices  
			uvtData: tex_uvt culling: nil colours: nil
			blendMode: 0.
	].

	stage
		addEventListener: Event enterFrame
		with: [:e | doUpdate value ] ! !


Bitmap trianglesExample