PureBasic Forum
http://forums.purebasic.com/english/

Flip Sprite Old school ;o)
http://forums.purebasic.com/english/viewtopic.php?f=12&t=73791
Page 1 of 1

Author:  dobro [ Sat Oct 12, 2019 11:09 pm ]
Post subject:  Flip Sprite Old school ;o)

no assembler
no complicated stuff about directX

an old-fashioned code like we do more of it
very simple

probably cross-platform
goodbye transformSprite :lol: :lol: :lol:

Quote:
since the following versions of Purebasic 5.11
this code Bug , if using a subsystem
or DirectX11
or OpenGL

it depends on the users.....

̷w̷h̷i̷l̷e̷ ̷i̷n̷ ̷P̷B̷ ̷5̷.̷1̷1̷ ̷i̷t̷ ̷w̷o̷r̷k̷s̷

rectification
even in version 5.11 it doesn't work with DirectX11





Code:
;***********************************************
;Titre  :*test_transforme_sprite perso
;Auteur  : Dobro
;Date  :12/10/2019
;Heure  :23:50:05
;Version Purebasic :  PureBasic 5.70 LTS (Windows - x86)
;Version de l'editeur :EPB PHOENIX V2.68
; Libairies necessaire : Aucune
;***********************************************


InitSprite()

Enumeration
      #win
      #sprite1
      #sprite2
EndEnumeration

; ********* My Super Procedures LOL  ****************
Declare Scan_Sprite(Num_sprite)
Declare Flip_H_Sprite(Num_sprite)
Declare Flip_V_Sprite(Num_sprite)
Declare Flip_VH_Sprite(Num_sprite)
; ****************************************************



ExamineDesktops()
EcranX=DesktopWidth(0)/2
EcranY=DesktopHeight(0)/2
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
      MessageRequester("Erreur", "Impossible d'initialiser l'écran.")
      End
EndIf

OpenWindow(#win,1,1,Ecranx,Ecrany,"yoo Flip", #PB_Window_SystemMenu )
OpenWindowedScreen(WindowID(#win),1,1,EcranX,Ecrany,1,0,0)


; *************** pour l'exemple on creer un sprite fait de 2 box de 2 couleurs differentes ******************
;Sprite 1
CreateSprite(#sprite1,100,100)
StartDrawing(SpriteOutput(#Sprite1))
      Box(1,1,64,64,RGB(255,255,0))
      Box(32,32,64,64,RGB(0,255,150))
StopDrawing()
;*******************************************************************************************************

Scan_Sprite(#sprite1)  ;  la premiere des procedures, permet de mettre le sprite en Tableau .... pis c'est les tableaux qu'on va manipuler pour fliper notre sprite
CopySprite(#sprite1,#sprite2)  ; garde une trace du sprite originale dans #sprite2

; boucle principale
Repeat
      Repeat
        Event = WindowEvent()
       
        Select Event
          Case #PB_Event_CloseWindow
            End
        EndSelect
      Until Event = 0
   
      ClearScreen(0)
     
     
      ExamineKeyboard()
     
      DisplayTransparentSprite(#sprite2, 10,100)  ; le sprite des origines sans modification
           
      Flip_H_Sprite(#sprite1)  ; on fait un FLip Horizontale
      DisplayTransparentSprite(#sprite1, 10,250)       ; on affiche fierement le resultat
           
      Flip_V_Sprite(#sprite1)  ; on fait un Flip Vertical
      DisplayTransparentSprite(#sprite1, 10,400)      ; on affiche fierement le resulat
     
      Flip_VH_Sprite(#sprite1)  ; la on est fou , on fait carrement un flip Vertical ET horizontal roulement de tambour ....brbrbrbrbrbrbr  tiiiich  !
      DisplayTransparentSprite(#sprite1, 500,100)      ; on affiche le sprite qui ne c'est pas gamélé
     
      ; ici on va afficher le text pour les neuneu qu'aurai pas compris ..... ;o)
      StartDrawing(ScreenOutput())
            DrawText(100,150,"<--- Sprite1  original normal ")
            DrawText(100,300,"<--- Sprite2  flipé horizontalement ")
            DrawText(100,400,"<--- Sprite2  flipé verticalement ")
            DrawText(550,100,"<--- Sprite2  flipé verticalement et horizontalement ")
      StopDrawing()
     
      ;Affichage à l'écran  concretement
      FlipBuffers()
         
ForEver







;- **** Zone Procedure ************

Procedure Scan_Sprite(Num_sprite)
      ;By Dobro
      Protected w
      Protected h
      w=SpriteWidth(Num_sprite)
      h=SpriteHeight(Num_sprite)
      Global Dim tab_spr(w,h)
      StartDrawing(SpriteOutput(Num_sprite))
            For y=0 To h-1
                  For x=0 To w-1
                        tab_spr(x,y)=Point(x,y)   
                  Next x
            Next y
      StopDrawing()
EndProcedure




Procedure Flip_H_Sprite(Num_sprite)
      ;By Dobro
      w=SpriteWidth(Num_sprite)
      h=SpriteHeight(Num_sprite)
      StartDrawing(SpriteOutput(Num_sprite))
            For y=0 To h-1
                  For x= 0 To w-1
                        Plot(x,y,tab_spr(x,h-y))
                  Next x
            Next y     
      StopDrawing()
EndProcedure   


Procedure Flip_V_Sprite(Num_sprite)
      ;By Dobro
      w=SpriteWidth(Num_sprite)
      h=SpriteHeight(Num_sprite)
      StartDrawing(SpriteOutput(Num_sprite))
            For y=0 To h-1
                  For x=0 To w-1     
                        Plot(x,y,tab_spr(w-x,y))
                  Next x
            Next y     
      StopDrawing()
EndProcedure   


Procedure Flip_VH_Sprite(Num_sprite)
      ;By Dobro
      w=SpriteWidth(Num_sprite)
      h=SpriteHeight(Num_sprite)
      StartDrawing(SpriteOutput(Num_sprite))
            For y=0 To h-1
                  For x=0 To w-1     
                        Plot(x,y,tab_spr(w-x,h-y))
                  Next x
            Next y     
      StopDrawing()
EndProcedure   

Author:  C87 [ Sun Oct 13, 2019 9:39 am ]
Post subject:  Re: Flip Sprite Old school ;o)

This post resulted in something that is of great concern to me. When I opened the post, Google immediately offered the option of using Google Translate. Which means that in the fraction of a second it took to open, in the background Google had ascertained that all of the text in the post was not English! Is there any part of the internet that Google is not monitoring? If it can access any posted item in a relatively small and esoteric forum so easily, how much else is it scanning and downloading from every single internet user? :evil:

Have to say, pretty far from happy about this intrusion. :x :x

Author:  mk-soft [ Sun Oct 13, 2019 10:15 am ]
Post subject:  Re: Flip Sprite Old school ;o)

This must be due to your browser settings and google settings (If you have a Google Account)

Author:  BarryG [ Sun Oct 13, 2019 10:20 am ]
Post subject:  Re: Flip Sprite Old school ;o)

mk-soft wrote:
This must be due to your browser settings and google settings (If you have a Google Account)

Yep. I also have a logged-in Google account, but no offer of translation happens for me. Using Firefox. I know Chrome offers real-time translations, so I bet C876 is using Chrome (made by Google) for his browser.

Author:  C87 [ Sun Oct 13, 2019 11:46 am ]
Post subject:  Re: Flip Sprite Old school ;o)

Nope.....not using Chrome, never have. Don't have a Google Account. Actually use BRAVE on a Private Window for PureB. The only browsers I use are Brave, Epic & Firefox. Searching only use DuckDuckGo. Mind you don't Google own Firefox?
Could you have inadvertently clicked don't want to see the offer of Google Translate again? The fact is the unwanted offer came up :?

Author:  BarryG [ Sun Oct 13, 2019 12:50 pm ]
Post subject:  Re: Flip Sprite Old school ;o)

C87 wrote:
don't Google own Firefox?

No, Google own Chrome. Firefox is owned by Mozilla.

C87 wrote:
Could you have inadvertently clicked don't want to see the offer of Google Translate again?

Again no, because Firefox doesn't offer translation natively (https://support.mozilla.org/en-US/kb/ho ... re-firefox). You'd need to install a translation extension.

Author:  mk-soft [ Sun Oct 13, 2019 1:36 pm ]
Post subject:  Re: Flip Sprite Old school ;o)

@dobro

not running with OpenGL :(

Author:  Marc56us [ Sun Oct 13, 2019 1:46 pm ]
Post subject:  Re: Flip Sprite Old school ;o)

@C87
Maybe you inadvertently accepted a google toolbar?
(check with a tool like CCleaner Tools > Navigator Plug-in)

Author:  dobro [ Sun Oct 13, 2019 11:05 pm ]
Post subject:  Re: Flip Sprite Old school ;o)

mk-soft wrote:
@dobro

not running with OpenGL :(


works with Sous system openGL at home :)
I just added "ClearScreen($0)" after the Flipbuffer()


there is nothing particular in the code, just redraw a sprite using a array.

maybe not put a subsystem ?
at home it's when I use directX11 that it doesn't display anything

you have to ask Fred why
the use of a subsystem can prevent
the display of a simple sprite!
personally, I don't know

Author:  dobro [ Mon Oct 14, 2019 8:35 am ]
Post subject:  Re: Flip Sprite Old school ;o)

Thanks to C87 for polluting my topic ....
the moderators are on vacation ?

Author:  #NULL [ Mon Oct 14, 2019 8:56 am ]
Post subject:  Re: Flip Sprite Old school ;o)

ClearScreen() fixes the smearing with OpenGL. And you should process all events per main loop iteration. No problem here with multiple InitSprite() BTW.
Code:
Repeat
      Repeat
        Event = WaitWindowEvent(2)
       
        Select Event
          Case #PB_Event_CloseWindow
            quit = #True
        EndSelect
      Until Not Event()
   
      ClearScreen(0)
     
      [...]
         
Until quit

Author:  dobro [ Mon Oct 14, 2019 9:01 am ]
Post subject:  Re: Flip Sprite Old school ;o) [Bug After Pb 5.11 !! ]

yes I know that ClearScreen() corrects the effect of blurrs
in OpenGL

dobro wrote:
works with Sous system openGL at home :)
I just added "ClearScreen($0)" after the Flipbuffer()


in PB 5.70
but the problem is that with the DirectX11 subsystem
in my house no sprites are displayed!!!



mk-soft has a problem with openGL!
I'm with DirectX11

ps: my system is in DirectX12 look here :
http://michel.dobro.free.fr/forum_gamopat/bug.gif


at the same time, I assume that if we don't specify anything, it must take the DirectX system present on the computer..... (at home DX12)
Just a guess, huh...

and when I put nothing, all works... so......

Author:  DK_PETER [ Thu Oct 24, 2019 12:30 am ]
Post subject:  Re: Flip Sprite Old school ;o) [Bug After Pb 5.11 !! ]

@Dobro

There's no bug.
Ive changed your code a bit. It should work with DirectX11 and OpenGL now.

Code:
;***********************************************
;Titre  :*test_transforme_sprite perso
;Auteur  : Dobro
;Date  :12/10/2019
;Heure  :23:50:05
;Version Purebasic :  PureBasic 5.70 LTS (Windows - x86)
;Version de l'editeur :EPB PHOENIX V2.68
; Libairies necessaire : Aucune
;***********************************************


InitSprite()

Enumeration
  #win
  #sprite1
  #sprite2
EndEnumeration

; ********* My Super Procedures LOL  ****************
Declare Scan_Sprite(Num_sprite)
Declare Flip_H_Sprite(Num_sprite)
Declare Flip_V_Sprite(Num_sprite)
Declare Flip_VH_Sprite(Num_sprite)
; ****************************************************

Global Quit = #False

ExamineDesktops()
EcranX=DesktopWidth(0)/2
EcranY=DesktopHeight(0)/2
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Erreur", "Impossible d'initialiser l'écran.")
  End
EndIf

OpenWindow(#win,1,1,Ecranx,Ecrany,"yoo Flip", #PB_Window_SystemMenu )
OpenWindowedScreen(WindowID(#win),1,1,EcranX,Ecrany,1,0,0)


; *************** pour l'exemple on creer un sprite fait de 2 box de 2 couleurs differentes ******************
;Sprite 1
CreateSprite(#sprite1,100, 100, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(#Sprite1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(1,1,64,64,RGBA(255,255,0, 255))
Box(32,32,64,64,RGBA(0,255,150, 255))
StopDrawing()
;*******************************************************************************************************

Scan_Sprite(#sprite1)  ;  la premiere des procedures, permet de mettre le sprite en Tableau .... pis c'est les tableaux qu'on va manipuler pour fliper notre sprite
CopySprite(#sprite1,#sprite2)  ; garde une trace du sprite originale dans #sprite2

; boucle principale
Repeat
  ClearScreen(0)
  Repeat
    Event = WindowEvent()
    If Event = #PB_Event_CloseWindow : Quit = #True : EndIf
  Until Event = 0 
 
  ExamineKeyboard()
 
  DisplayTransparentSprite(#sprite2, 10,100, 255)  ; le sprite des origines sans modification
 
  Flip_H_Sprite(#sprite1)  ; on fait un FLip Horizontale
  DisplayTransparentSprite(#sprite1, 10,250, 255)       ; on affiche fierement le resultat
 
  Flip_V_Sprite(#sprite1)  ; on fait un Flip Vertical
  DisplayTransparentSprite(#sprite1, 10,400, 255)      ; on affiche fierement le resulat
 
  Flip_VH_Sprite(#sprite1)  ; la on est fou , on fait carrement un flip Vertical ET horizontal roulement de tambour ....brbrbrbrbrbrbr  tiiiich  !
  DisplayTransparentSprite(#sprite1, 500,100, 255)      ; on affiche le sprite qui ne c'est pas gamélé
 
  ; ici on va afficher le text pour les neuneu qu'aurai pas compris ..... ;o)
  StartDrawing(ScreenOutput())
  DrawText(100,150,"<--- Sprite1  original normal ")
  DrawText(100,300,"<--- Sprite2  flipé horizontalement ")
  DrawText(100,400,"<--- Sprite2  flipé verticalement ")
  DrawText(550,100,"<--- Sprite2  flipé verticalement et horizontalement ")
  StopDrawing()
 
  ;Affichage à l'écran  concretement
  FlipBuffers()
 
Until Quit = #True

;- **** Zone Procedure ************

Procedure Scan_Sprite(Num_sprite)
  ;By Dobro
  Protected w
  Protected h
  Protected Color
  w=SpriteWidth(Num_sprite)
  h=SpriteHeight(Num_sprite)
  Global Dim tab_spr(w,h)
  StartDrawing(SpriteOutput(Num_sprite))
  DrawingMode(#PB_2DDrawing_AllChannels)
  For y=0 To h-1
    For x=0 To w-1
      Color = Point(x,y)
      tab_spr(x,y)= RGBA(Red(color), Green(color), Blue(color), 255)
    Next x
  Next y
  StopDrawing()
EndProcedure

Procedure Flip_H_Sprite(Num_sprite)
  ;By Dobro
  w=SpriteWidth(Num_sprite)
  h=SpriteHeight(Num_sprite)
  StartDrawing(SpriteOutput(Num_sprite))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  For y=0 To h-1
    For x= 0 To w-1
      Plot(x,y,tab_spr(x,h-y))
    Next x
  Next y     
  StopDrawing()
EndProcedure   


Procedure Flip_V_Sprite(Num_sprite)
  ;By Dobro
  w=SpriteWidth(Num_sprite)
  h=SpriteHeight(Num_sprite)
  StartDrawing(SpriteOutput(Num_sprite))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  For y=0 To h-1
    For x=0 To w-1     
      Plot(x,y,tab_spr(w-x,y))
    Next x
  Next y     
  StopDrawing()
EndProcedure   


Procedure Flip_VH_Sprite(Num_sprite)
  ;By Dobro
  w=SpriteWidth(Num_sprite)
  h=SpriteHeight(Num_sprite)
  StartDrawing(SpriteOutput(Num_sprite))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  For y=0 To h-1
    For x=0 To w-1     
      Plot(x,y,tab_spr(w-x,h-y))
    Next x
  Next y     
  StopDrawing()
EndProcedure   

Author:  dobro [ Thu Nov 14, 2019 3:49 pm ]
Post subject:  Re: Flip Sprite Old school ;o)

Ok Thanks :)

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/