Black lines when drawing tiled images.

BlitzMax Forums/BlitzMax Programming/Black lines when drawing tiled images.

nawi(Posted 2009) [#1]
I have a function to draw a laser, it works okay when zoomed in, but when you zoom out these black lines are shown. If you look close you can also see the black lines in the zoomed in pic.



The method is quite simply. I just draw a part of the laser several times.
	Method DrawLaser(X1:Float,Y1:Float,X2:Float,Y2:Float)
		Local Dis:Float = Distance(X1,Y1,X2,Y2)
		Local Steps:Int = Dis/Float(ImageWidth(LaserMiddle)*Player.Zoom)
		Local LastStep:Float = -(Steps*Float(ImageWidth(LaserMiddle))*Player.Zoom-Dis)/Float(ImageWidth(LaserMiddle))*Player.Zoom
		Local Angle:Float = ATan2(Y2-Y1,X2-X1)
		Local OldRot:Float = GetRotation()
		SetRotation(Angle)
		SetScale(Player.Zoom,Player.Zoom)
		Local DX:Float,DY:Float
		For Local t:Int = 1 To Steps
			DX:Float = Float(X1)+Player.Zoom*ImageWidth(LaserMiddle)*Cos(Angle)*Float(t-1)
			DY:Float = Float(Y1)+Player.Zoom*ImageWidth(LaserMiddle)*Sin(Angle)*Float(t-1)
			DrawImage LaserMiddle,DX,DY
		Next
		SetScale(1.0,1.0)
		SetRotation(OldRot)
	End Method



Jesse(Posted 2009) [#2]
I usually get that when I overlap or have one pixel spacing in between. I don't know if using double for a more acurate result will help with the scale factor but it might be wordth to try it out. note that I have not used the scale factor to draw angled tile images. For things like that I sometimes use the "DrawImageRect" which I am shure is a lot faster.


nawi(Posted 2009) [#3]
Converting to double didn't fix it ;/


Ked(Posted 2009) [#4]
Wouldn't it just be easier to scale the laser image instead of tiling it?


Jesse(Posted 2009) [#5]
I did A laser type a while ago but I never added scale. I updated it right now with scale and it works fine. try it with your image and see if it works.
Strict

Graphics 640,480,32
SetBlend alphablend

Local lazer:Tlazer= New Tlazer
Global scale:Float = 1
SetColor 255,155,0
Repeat

	Cls	
	If KeyDown(key_space) Tlazer.Create(50,50,45,4.0)
	lazer.update()
	lazer.draw()
	Flip()
	
Until KeyDown(key_escape)

Type Tlazer

	Field x:Float
	Field y:Float
	Field dx:Float
	Field dy:Float
	Field rot:Float
	Field r:Float
	Field speed:Float
	Field warmup:Int
	Field fire:Int
	Field link:TLink

	Global list:TList = New TList
	Global dist:Float
	Global count:Int
	Global beam:TImage
	
	Function Create(x:Float, y:Float, angle:Float, speed:Float)

		If beam = Null
			beam =  LoadImage("gfx\laser_middle.png",MIPMAPPEDIMAGE|FILTEREDIMAGE)
			If beam = Null Print "bad laser.img" ;End
			MidHandleImage beam
			count = 0
		EndIf
		If dist >= beam.width	Or count = 0
			Local l:tlazer = New Tlazer
			dist = dist Mod beam.width 
			l.dx = Cos(angle)
			l.dy = Sin(angle)
			l.x = x+l.dx*dist*scale
			l.y = y+l.dy*dist*scale
			l.rot = angle
			l.speed = speed
			l.count :+ 1
			l.link = list.addlast(l)

		EndIf
	End Function
	
	method update()
		If count = 0 Return
		dist :+ Tlazer(list.last()).speed
		For Local l:Tlazer = EachIn list
			l.x :+ l.dx * l.speed*scale
			l.y :+ l.dy * l.speed*scale
			If l.x > -30
				If l.y < 510
					If l.x < 500
						If l.y > -30
							Continue
						EndIf
					EndIf
				EndIf
			EndIf
			l.link.remove()
			l.count :- 1
		Next	
	End method
	
	method draw()

		SetRotation 0
		SetScale 1,1
		DrawText count,10,10
		SetScale scale , scale
		For Local l:Tlazer = EachIn list
			SetRotation l.rot
			DrawImage beam,l.x,l.y
		Next
		
	End method
	
End Type



I did notice that when I removed the scale of the create function I got the same thing you got.


Jesse(Posted 2009) [#6]
@Ked
I think the problem is that when colliding it becomes really slow which makes tiling it a lot more efficient.


Ked(Posted 2009) [#7]
I think the problem is that when colliding it becomes really slow which makes tiling it a lot more efficient.

I had a feeling there was a downside to it. :) Well, that's all I got.


TaskMaster(Posted 2009) [#8]
I think that line will go away if you draw your laser tiles at exact pixel coordinates (integer).


xlsior(Posted 2009) [#9]
Is the image an even or odd number of pixels?

I've run into this when I had an odd-sized image (which I had done intentioanlly, for the convenience of being able to rotate them around a central pixel and still have everything fit together) properly)

Switching to an even number made the lines go away for me.


nawi(Posted 2009) [#10]
It's even sized (30x30).


dan_upright(Posted 2009) [#11]
It's even sized (30x30)
have you tried a power of 2?


Jesse(Posted 2009) [#12]
I tryed your code and I don't get the black lines. although I had to adopt it to make it work:
superstrict
Global laserMiddle:TImage = LoadImage("gfx\lazer3b.png",MIPMAPPEDIMAGE|FILTEREDIMAGE)
If laserMiddle = Null Print "bad lazer3 img"

Global zoom:Float = .2

Type Tlaser	
	
	
	Method DrawLaser(X1:Float,Y1:Float,X2:Float,Y2:Float)
		Local Dis:Float = Sqr((X2-X1)^2+(Y2-Y1)^2)
		Local Steps:Int = Dis/Float(ImageWidth(LaserMiddle)*Zoom)
		Local LastStep:Float = -(Steps*Float(ImageWidth(LaserMiddle))-Dis)/Float(ImageWidth(LaserMiddle))*zoom
		Local Angle:Float = ATan2(Y2-Y1,X2-X1)
		Local OldRot:Float = GetRotation()
		SetRotation(Angle)
		SetScale(Zoom,Zoom)
		Local DX:Float,DY:Float
		For Local t:Int = 1 To Steps
			DX:Float = Float(X1)+Zoom*ImageWidth(LaserMiddle)*Cos(Angle)*Float(t-1)
			DY:Float = Float(Y1)+Zoom*ImageWidth(LaserMiddle)*Sin(Angle)*Float(t-1)
			DrawImage LaserMiddle,DX,DY
		Next
		SetScale(1.0,1.0)
		SetRotation(OldRot)
	End Method
	
End Type
Graphics 640,480,32
SetBlend alphablend
SetColor 200,0,0
Local lazer:tlaser = New Tlaser

lazer.drawlaser(100 , 100 , 300,600)
Flip()
WaitKey()

I am using this image:

can you post the image? It might be the problem.


nawi(Posted 2009) [#13]

EDIT: I get the black lines with your code too (using my image and also with your image).
Perhaps this is a blitzmax bug then?


plash(Posted 2009) [#14]
Perhaps this is a blitzmax bug then?
Or just a driver/video card bug/inconsistency?


Jesse(Posted 2009) [#15]
it might be a driver problem or graphics settings issue. I had some problems with my graphics card before to where it wouldn't draw alpha images properly until I messed with the driver settings.


nawi(Posted 2009) [#16]
I'm using Nvidia 180.51, but you're right, it might be a driver problem if other people are not seein those lines.


Arowx(Posted 2009) [#17]
Have you tried changing the image size to 32x32?

I think textures should be square and a binary size e.g. 32,64,128,...?


nawi(Posted 2009) [#18]
Merx, thank you very much, changing it to 32x32 fixes the issue.