Apparently, and curiously, there's no polygon command on PureBasic.
I just want to draw filled 2d polygons (convex quadrilateral, or 2 triangles).
Does anybody have a fast procedure ? To be fast, it certainly have to be coded in ASM, but I dont't know it.
thks.
			
			
									
									
						filled polygons
well......
I have made a little filled triangle routine.
It's an adaptation for Purebasic of this => http://www.mat.uni.torun.pl/~wrona/3d_t ... llers.html
I need To code a fastest routine in ASM, to replace LineXY().
A better method would be to use direct3d polygons, with hardware acceleration, but I don't know how to do this... Do you think it's possible ?
			
			
									
									
						I have made a little filled triangle routine.
It's an adaptation for Purebasic of this => http://www.mat.uni.torun.pl/~wrona/3d_t ... llers.html
Code: Select all
Procedure flat_triangle(x1,y1,x2,y2,x3,y3,colour)
;sort vertices,to obtain y1<y2<y3 (to improve :))
If y2>y3 : y0=y3 : y3=y2 : y2=y0 : x0=x3 : x3=x2 : x2=x0 : EndIf
If y1>y2 : y0=y2 : y2=y1 : y1=y0 : x0=x2 : x2=x1 : x1=x0 : EndIf  
If y1>y3 : y0=y3 : y3=y1 : y1=y0 : x0=x3 : x3=x1 : x1=x0 : EndIf
If y2>y3 : y0=y3 : y3=y2 : y2=y0 : x0=x3 : x3=x2:  x2=x0 : EndIf
dx1.f=(x2-x1)/(y2-y1)
dx2.f=(x3-x1)/(y3-y1)
dx3.f=(x3-x2)/(y3-y2)
Sx.f=x1 : Ex.f=x1 : Y=y1
If(dx1>dx2)
  Repeat
    Y+1
    Sx+dx2
    Ex+dx1
    LineXY(Sx,Y,Ex,Y,colour)
  Until Y>=y2
  Ex=x2 :  Ey=y2
  Repeat
    Y+1 : Sx+dx2 : Ex+dx3
    LineXY(Sx,Y,Ex,Y,colour)
  Until Y>=y3
Else
  Repeat
    Y+1 : Sx+dx1 : Ex+dx2
    LineXY(Sx,Y,Ex,Y,colour)
  Until Y>=y2
  Sx=x2 : Sy=y2
  Repeat
    Y+1 : Sx+dx3 : Ex+dx2
    LineXY(Sx,Y,Ex,Y,colour)
  Until Y>=y3
EndIf
EndProcedure
A better method would be to use direct3d polygons, with hardware acceleration, but I don't know how to do this... Do you think it's possible ?
it does.For hdc you have to use the Screenoutput() Function.coma wrote:does this method works on a graphical screen open with OpenScreen() ??? .
well thats your point of view.I have seen a lot of Polygon-examples under vb that are realy fast.coma wrote: And I don't think polygon() api is very optimised.
SPAMINATOR NR.1
						i tried and it works well. I think polyline() is fast enough for common use... but i encountered a problem in this code : how can i change the color of polylines ? I tried FrontColor() just before PolyLine_() but it doesn't work !
			
			
									
									Code: Select all
Structure POINTTRIANGLE 
  pointA.POINT 
  pointB.POINT 
  pointC.POINT 
  pointD.POINT 
EndStructure 
Procedure TriangleFlat( x1, y1, x2, y2, x3, y3, color ) 
  triangle.POINTTRIANGLE 
  triangle\pointA\x = x1 
  triangle\pointA\y = y1 
  triangle\pointB\x = x2 
  triangle\pointB\y = y2 
  triangle\pointC\x = x3 
  triangle\pointC\y = y3 
  triangle\pointD\x = x1 
  triangle\pointD\y = y1 
  
  Polyline_( GetDC_( WindowID() ), @triangle, 4 ) 
  FillArea( triangle\pointA\x, triangle\pointA\y+2, 0, color ) 
EndProcedure 
If OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"") 
  StartDrawing( WindowOutput() ) 
    TriangleFlat( 100,10, 10,180, 180,180, $FFFFFF ) 
  StopDrawing() 
  
  While WaitWindowEvent() <> #WM_CLOSE : Wend 
  
EndIfNo programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
						There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
When I try to draw a triangle on ScreenOutput(), to make animations, I have a flickering problem.
			
			
									
									
						Code: Select all
Structure POINTTRIANGLE 
  pointA.POINT 
  pointB.POINT 
  pointC.POINT 
EndStructure 
Procedure TriangleFlat( x1, y1, x2, y2, x3, y3, color ) 
  triangle.POINTTRIANGLE 
  triangle\pointA\x = x1 
  triangle\pointA\y = y1 
  triangle\pointB\x = x2 
  triangle\pointB\y = y2 
  triangle\pointC\x = x3 
  triangle\pointC\y = y3 
  Polygon_(GetDC_( WindowID() ), @triangle, 3)
EndProcedure 
InitSprite() 
InitKeyboard() 
OpenWindow(0,0,0,400,200,#PB_Window_ScreenCentered | #PB_Window_SystemMenu,"test") 
OpenWindowedScreen(WindowID(), 0, 0, 400, 200,0,0,0)
Repeat
  ClearScreen(100,80,120)
  StartDrawing(ScreenOutput()) 
    Box (x,10,50,50,$ffffff)
    triangleFlat(x+100,10, x,180, x+180,180, 0) 
  StopDrawing() 
  x=x+1 : If x>300 : x=0 : EndIf
  FlipBuffers() 
ExamineKeyboard() 
Until KeyboardPushed(#PB_Key_Escape) 
  
End



