hi!
i made a triangle fill routine here. i've seen so many fill routines which were so fast... why is mine so slow? is there any visible mistake?
i mean - i've seen this sample below running on 100 fps, and now it's only 20 fps. where is the giant speed leak?
i know, everything i'm programing is slow :(...
thank you for any help!
texture:
i made a triangle fill routine here. i've seen so many fill routines which were so fast... why is mine so slow? is there any visible mistake?
i mean - i've seen this sample below running on 100 fps, and now it's only 20 fps. where is the giant speed leak?
i know, everything i'm programing is slow :(...
thank you for any help!
texture:

Graphics 1024, 768, 32, 2 SetBuffer BackBuffer() ;Texture Dim Tex(15, 15) img = LoadImage("Texture.png") LockBuffer ImageBuffer(img) For x = 0 To 15 For y = 0 To 15 Tex(x, y) = ReadPixelFast(x, y, ImageBuffer(img)) Next Next UnlockBuffer ImageBuffer(img) FreeImage img While Not KeyHit(1) mx = MouseX() my = MouseY() Cls LockBuffer() FillTri(50, 50, 0, 0, 970, 100, 16, 0, mx, my, 16, 16);, 0, 0, 16, 0, 16, 16) FillTri(50, 50, 0, 0, 100, 600, 0, 16, mx, my, 16, 16);, 0, 0, 0, 16, 16, 16) UnlockBuffer() Text 10, 10, "FPS: " + GetFPS() Flip 0 Wend End Global FPS, FPS_temp, FPS_time Function GetFPS() ctime = MilliSecs() FPS_temp = FPS_temp + 1 If ctime - FPS_time > 500 Then FPS = FPS_temp * 2 FPS_temp = 0 FPS_time = ctime EndIf Return FPS End Function ;--- Function FillTri(p1x, p1y, p1u, p1v, p2x, p2y, p2u, p2v, p3x, p3y, p3u, p3v) If p1y > p2y Then ptx = p1x pty = p1y ptu = p1u ptv = p1v p1x = p2x p1y = p2y p1u = p2u p1v = p2v p2x = ptx p2y = pty p2u = ptu p2v = ptv EndIf If p2y > p3y Then ptx = p2x pty = p2y ptu = p2u ptv = p2v p2x = p3x p2y = p3y p2u = p3u p2v = p3v p3x = ptx p3y = pty p3u = ptu p3v = ptv If p1y > p2y Then ptx = p1x pty = p1y ptu = p1u ptv = p1v p1x = p2x p1y = p2y p1u = p2u p1v = p2v p2x = ptx p2y = pty p2u = ptu p2v = ptv EndIf EndIf If p1y <> p2y Then For y = p1y To p2y x1 = vgliIntp(y, p1y, p3y, p1x, p3x) u1# = vgliIntp(y, p1y, p3y, p1u, p3u) v1# = vgliIntp(y, p1y, p3y, p1v, p3v) x2 = vgliIntp(y, p1y, p2y, p1x, p2x) u2# = vgliIntp(y, p1y, p2y, p1u, p2u) v2# = vgliIntp(y, p1y, p2y, p1v, p2v) FillTriLine(x1, u1#, v1#, x2, u2#, v2#, y) Next EndIf If p2y <> p3y Then For y = p2y To p3y x1 = vgliIntp(y, p1y, p3y, p1x, p3x) u1# = vgliIntp(y, p1y, p3y, p1u, p3u) v1# = vgliIntp(y, p1y, p3y, p1v, p3v) x2 = vgliIntp(y, p2y, p3y, p2x, p3x) u2# = vgliIntp(y, p2y, p3y, p2u, p3u) v2# = vgliIntp(y, p2y, p3y, p2v, p3v) FillTriLine(x1, u1#, v1#, x2, u2#, v2#, y) Next EndIf End Function Function FillTriLine(p1x, p1u#, p1v#, p2x, p2u#, p2v#, y) If p1x = p2x Then Return If p1x > p2x Then tx = p1x tu# = p1u# tv# = p1v# p1x = p2x p1u# = p2u# p1v# = p2v# p2x = tx p2u# = tu# p2v# = tv# EndIf For x = p1x To p2x u = vgliIntp(x, p1x, p2x, p1u#, p2u#) v = vgliIntp(x, p1x, p2x, p1v#, p2v#) WritePixelFast x, y, Tex(u, v) Next End Function Function vgliIntp#(value#, vMin#, vMax#, retMin#, retMax#) Return retMin# + (value# - vMin#) * (retMax# - retMin#) / (vMax# - vMin#) End Function