Page 6 sur 6

Publié : ven. 07/mars/2008 14:15
par Backup
.......................

Publié : ven. 07/mars/2008 14:22
par Backup
......................

Publié : sam. 08/mars/2008 1:14
par SPH
@cpt bator (page 6) :

Ton code comporte la traditionnelle erreur de décallage graphique dont on a à plusieurs reprises parlé ici :
http://www.purebasic.fr/french/viewtopic.php?t=7542 et autre part, je ne sais plus ou...

Chez moi, ce code dessine des traits hachurés rouge vert et bleu. Ces hachures semblent dessiner 5 ou 6 triangles...
Cpl.Bator a écrit :

Code : Tout sélectionner

Macro BGR(Blue,Green,Red)
  RGB(Blue,Green,Red)
EndMacro

Procedure OpenScreen2DFX(SizeX.l,SizeY.l)
  Global *SCREEN.l          = AllocateMemory((SizeX*SizeY)*4)
  Global *Blur_byte.b       = AllocateMemory(SizeX*SizeY)
  Global ScreenX.l          = SizeX
  Global ScreenY.l          = SizeY
  Global TransparentColor.l = 0
  Global DB.l,DBP.l,PF.l
   
  If *SCREEN=0 Or *Blur_byte=0
    MessageRequester("erreur","pas assez de mémoire vive, "+Str( ((SizeX*SizeY)*4)+(SizeX*SizeY) )+" bytes" )
  EndIf
  
  If InitSprite()=0 Or InitKeyboard()=0 Or InitMouse()=0 Or OpenScreen(SizeX,SizeY,32,"")=0
     MessageRequester("erreur","pb directx")
  EndIf
  

  
  StartDrawing(ScreenOutput())
  DB  = DrawingBuffer()
  DBP = DrawingBufferPixelFormat()
 
  Select DBP
    Case #PB_PixelFormat_8Bits         : PF=1 
    Case #PB_PixelFormat_15Bits        : PF=2 
    Case #PB_PixelFormat_16Bits        : PF=2 
    Case #PB_PixelFormat_24Bits_RGB    : PF=3 
    Case #PB_PixelFormat_24Bits_BGR    : PF=3 
    Case #PB_PixelFormat_32Bits_RGB    : PF=4 
    Case #PB_PixelFormat_32Bits_BGR    : PF=4 
  EndSelect 
  StopDrawing()
EndProcedure


Procedure FlipBuffers2DFX()
  Protected Color.l
  
  StartDrawing(ScreenOutput())
  DB = DrawingBuffer()
  
  
  For Y = 0 To ScreenY-1
    For x = 0 To ScreenX-1
      Color = PeekL(*SCREEN+ (x*PF) + ScreenX * (Y*PF))
      PokeL(DB + (x*PF) + ScreenX * (Y*PF),Color)
     
      If Color<>TransparentColor 
        PokeB(*Blur_byte+x+ScreenX*Y,1)
      EndIf 
      If Color=TransparentColor 
         PokeB(*Blur_byte+x+ScreenX*Y,0)
      EndIf 
      
      
      
    Next
  Next
  
  StopDrawing()
  
  FlipBuffers()
  
EndProcedure


Procedure BlurPixel(x.l,Y.l,offset.l=1)
  Protected _11.l,_12.l,_13.l,_14.l,_15.l,_16.l,_17.l,_18.l
  Protected _21.l,_22.l,_23.l,_24.l,_25.l,_26.l,_27.l,_28.l
  Protected Myn.f,r.l,v.l,b.l
  
  
  If x>0 And Y>0 And  x<ScreenX-1  And Y<ScreenY-1
    
    _11 = PeekL(*SCREEN+ ((x-1)*PF) + ScreenX * ((Y-1)*PF))
    r+Red(_11) : v+Green(_11) : b+Blue(_11)
    
    _12 = PeekL(*SCREEN+ ((x)*PF)   + ScreenX * ((Y-1)*PF))
    r+Red(_12) : v+Green(_12) : b+Blue(_12)
    
    _13 = PeekL(*SCREEN+ ((x+1)*PF) + ScreenX * ((Y-1)*PF))
    r+Red(_13) : v+Green(_13) : b+Blue(_13)
    
    _14 = PeekL(*SCREEN+ ((x+1)*PF) + ScreenX * ((Y)*PF))
    r+Red(_14) : v+Green(_14) : b+Blue(_14)
    
    _15 = PeekL(*SCREEN+ ((x+1)*PF) + ScreenX * ((Y+1)*PF))
    r+Red(_15) : v+Green(_15) : b+Blue(_15)
    
    _16 = PeekL(*SCREEN+ ((x)*PF)   + ScreenX * ((Y+1)*PF))
    r+Red(_16) : v+Green(_16) : b+Blue(_16)
    
    _17 = PeekL(*SCREEN+ ((x-1)*PF) + ScreenX * ((Y+1)*PF))
    r+Red(_17) : v+Green(_17) : b+Blue(_17)
    
    _18 = PeekL(*SCREEN+ ((x-1)*PF) + ScreenX * ((Y)*PF))
    r+Red(_18) : v+Green(_18) : b+Blue(_18)
    
    
    r/8 : v/8 : b/8
    r-offset
    v-offset
    b-offset
    
    If r<10 : r=TransparentColor : PokeL(*Blur_byte+x+ScreenX*Y,0) : EndIf
    If v<10 : v=TransparentColor : PokeL(*Blur_byte+x+ScreenX*Y,0) : EndIf
    If b<10 : b=TransparentColor : PokeL(*Blur_byte+x+ScreenX*Y,0): EndIf
    
    If Y>2
      Myn = BGR(r,v,b): PokeL(*SCREEN+ (x*PF) + ScreenX * ((Y-2)*PF),Myn)
    EndIf 

    
    
    PokeB(*Blur_byte+x+ScreenX*(Y),1)
    ;PokeB(*Blur_byte+(x-1)+ScreenX*(Y-1),1)
    PokeB(*Blur_byte+(x)+ScreenX*(Y-1),1)
    ;PokeB(*Blur_byte+(x+1)+ScreenX*(Y-1),1)
    PokeB(*Blur_byte+(x+1)+ScreenX*(Y),1)
    ;PokeB(*Blur_byte+(x+1)+ScreenX*(Y+1),1)
    PokeB(*Blur_byte+(x)+ScreenX*(Y+1),1)
    ;PokeB(*Blur_byte+(x-1)+ScreenX*(Y+1),1)
    PokeB(*Blur_byte+(x-1)+ScreenX*(Y),1)

    
  EndIf   

EndProcedure


Procedure FastPixel(x.l,Y.l,Color.l)
  If x=>0 And x<ScreenX-1 And Y=>0 And Y<ScreenY-1
    PokeL(*SCREEN+ (x*PF) + ScreenX * (Y*PF),Color)
    PokeB(*Blur_byte+x+ScreenX*Y,1)
  EndIf
EndProcedure

Procedure ClearScreen2DFX(Color.l)
  
  For Y = 0 To ScreenY-1
    For x = 0 To ScreenX-1
      
      If PeekL(*SCREEN+ ((x)*4) + ScreenX * ((Y)*4)) = TransparentColor
        PokeL( *SCREEN+ ((x)*4) + ScreenX * ((Y)*4),0)
        PokeB(*Blur_byte+x+ScreenX*Y,0)
      EndIf
       
    Next
  Next 
  
  
EndProcedure

Procedure lineXY2DFX(x1.f,y1.f,x2.f,y2.f,Couleur.l)
  Shared dx.f,dy.f,xincr.l,yincr.l,x.l,Y.l,erreur.f
  
  If x1<>0 And y1<>0 And x2<>0 And y2<>0
    
   
    dx = Abs(x2-x1)
    dy = Abs(y2-y1)
    
    If x1<x2
      xincr = 1
    Else
      xincr = -1
    EndIf
    
    If y1<y2
      yincr = 1
    Else
      yincr = -1
    EndIf
    
    
    ;/* Trace de ligne */
    
    x = x1
    Y = y1
    
    If dx>dy
      
      erreur = dx/2  ; /* c'est plus esthetique comme ca */
      For i= 0 To dx
        
        x = x+xincr;
        erreur = erreur+dy
        If erreur > dx
          
          erreur = erreur - dx
          Y = Y+yincr
        EndIf
        If x>0 And x<ScreenX-1 And Y>0 And Y<ScreenY-1
          PokeB(*Blur_byte+x+ScreenX*Y,1)
          PokeL(*SCREEN+ (x*PF) + ScreenX * (Y*PF),Couleur)
        EndIf
      Next i
      
    Else
      erreur = dy/2;     /* c'est plus esthetique comme ca */
      For i=0 To dy
        Y = Y + yincr
        erreur = erreur + dx
        If erreur>dy
          erreur = erreur - dy
          x = x + xincr
        EndIf
        If x>0 And x<ScreenX-1 And Y>0 And Y<ScreenY-1
          PokeB(*Blur_byte+x+ScreenX*Y,1)
          PokeL(*SCREEN+ (x*PF) + ScreenX * (Y*PF),Couleur)
        EndIf
      Next i
    EndIf
  EndIf   
EndProcedure


Procedure Circle2DFX(x.f,Y.f,Radius.l,Couleur.l)
  
  For i = 0 To 360
    
    Tx.l = x+Radius*Cos(i*#PI/180)
    Ty.l = Y+Radius*Sin(i*#PI/180)
     
    If Tx>0 And Tx<ScreenX-1 And Ty>0 And Ty<ScreenY-1
    PokeL(*SCREEN+ (Tx*PF) + ScreenX * (Ty*PF),Couleur)
  EndIf 
  Next
  
  
EndProcedure



OpenScreen2DFX(640,480)


Repeat
  ExamineKeyboard() : ExamineMouse()
  ClearScreen2DFX(BGR(0,0,0))

 

  
  a.f+1
  b.f+1
  
  P1x = 200 + 80 * Cos(a*#PI/180)
  P1y = 200 + 80 * Sin(a*#PI/180)
  
  P2x = 320 + 120 * Cos(-b*#PI/180)
  P2y = 240 + 80 * Sin(-b*#PI/180)
   
  P3x = 320 + 80 * Cos(b*#PI/180)
  P3y = 320 + 80 * Sin(b*#PI/180)
     
  
  
  ; For i = 1 To 10
    ; Circle2DFX(MouseX(),MouseY(),i,BGR(255-(i*25),255-(i*25),255))
  ; Next
  ; 
  
  
  For i = -2 To 2
  lineXY2DFX(P1x+i,P1y+i,P2x+i,P2y+i,BGR(Random(255),0,0))
  lineXY2DFX(P2x+i,P2y+i,P3x+i,P3y+i,BGR(0,Random(255),0))
  lineXY2DFX(P3x+i,P3y+i,P1x+i,P1y+i,BGR(0,0,128+Random(128)))
Next                              
  
 

  
  If DelayToBlur.l <ElapsedMilliseconds()
  DelayToBlur = ElapsedMilliseconds()+75
  For Y = 0 To ScreenY-1
    For x = 0 To ScreenX-1
      If PeekB(*Blur_byte+x+ScreenX*Y)<>0
        BlurPixel(x,Y,Random(10))
      EndIf
    Next 
  Next 
  EndIf 
  
  
  FlipBuffers2DFX()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()

Publié : sam. 08/mars/2008 12:21
par Backup
.............................

Publié : sam. 08/mars/2008 13:14
par Ar-S
Cet effet de motion blur sur un drawtext qui bouge serait superbe