Flip Sprite Old school ;o)

Share your advanced PureBasic knowledge/code with the community.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Flip Sprite Old school ;o)

Post by dobro »

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:
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: Select all

;***********************************************
;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   
Last edited by dobro on Mon Oct 14, 2019 10:48 am, edited 5 times in total.
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: Flip Sprite Old school ;o)

Post by C87 »

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
If it's falling over......just remember the computer is never wrong!
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Flip Sprite Old school ;o)

Post by mk-soft »

This must be due to your browser settings and google settings (If you have a Google Account)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Flip Sprite Old school ;o)

Post by BarryG »

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.
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: Flip Sprite Old school ;o)

Post by C87 »

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 :?
If it's falling over......just remember the computer is never wrong!
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Flip Sprite Old school ;o)

Post by BarryG »

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.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Flip Sprite Old school ;o)

Post by mk-soft »

@dobro

not running with OpenGL :(
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Flip Sprite Old school ;o)

Post by Marc56us »

@C87
Maybe you inadvertently accepted a google toolbar?
(check with a tool like CCleaner Tools > Navigator Plug-in)
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Flip Sprite Old school ;o)

Post by dobro »

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
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Flip Sprite Old school ;o)

Post by dobro »

Thanks to C87 for polluting my topic ....
the moderators are on vacation ?
Last edited by dobro on Mon Oct 14, 2019 10:51 am, edited 1 time in total.
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Flip Sprite Old school ;o)

Post by #NULL »

ClearScreen() fixes the smearing with OpenGL. And you should process all events per main loop iteration. No problem here with multiple InitSprite() BTW.

Code: Select all

Repeat
      Repeat
        Event = WaitWindowEvent(2)
        
        Select Event
          Case #PB_Event_CloseWindow
            quit = #True
        EndSelect
      Until Not Event()
    
      ClearScreen(0)
      
      [...]
         
Until quit
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Flip Sprite Old school ;o) [Bug After Pb 5.11 !! ]

Post by dobro »

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......
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Flip Sprite Old school ;o) [Bug After Pb 5.11 !! ]

Post by DK_PETER »

@Dobro

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

Code: Select all

;***********************************************
;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   
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Flip Sprite Old school ;o)

Post by dobro »

Ok Thanks :)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply