Desktop's capture

Just starting out? Need help? Post your questions and find answers here.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Desktop's capture

Post by SPH »

Hi,

how to capture and save the windows desktop? (i mean the desktop cleared of any open windows)

Thx :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 205
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: Desktop's capture

Post by moulder61 »

Hi SPH,

I just wrote a logout program that captures my Linux desktop as a screenshot then blurs it in the background behind the logout dialog. It's in the link in my signature if you want to see how I did it? It's called DXM-Logout. See pic below.
I couldn't find any way of doing it using PB, so unless there is some way of capturing it in memory, I used RunProgram() to call a script that runs scrot(or imagemagick) to do the job.
I guess something similar would work on Windows?

Moulder.

Image
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Desktop's capture

Post by idle »

it's not straight forward anymore do you want the icons or just the background?

This will get the wallpaper but not the icons

Code: Select all

EnableExplicit 

Import "user32.lib" 
  PrintWindow(hWnd, hdc, flags.l)
EndImport   

Global width,height,wallpaper   

Procedure GetWallpaper(mon=0) 
  Protected himage,hdc,hwnd
  ExamineDesktops()
  width = DesktopWidth(mon) 
  height = DesktopHeight(mon) 
  hImage = CreateImage(-1,Width,Height) 
  hDC  = StartDrawing(ImageOutput(himage)) 
  printwindow(FindWindowEx_(0, 0, @"Progman", 0) ,hdc,0) 
  StopDrawing() 
  ProcedureReturn hImage 
EndProcedure

wallpaper = GetWallpaper(0)

OpenWindow(0,0,0,width,height,"desktop") 
ImageGadget(1,0,0,width,height,ImageID(wallpaper)) 

Repeat 
  
Until WaitWindowEvent() = #PB_Event_CloseWindow   
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Re: Desktop's capture

Post by SPH »

Excellentissimo !

Thx :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Desktop's capture

Post by idle »

SPH wrote: Sun Oct 13, 2024 7:50 am Excellentissimo !

Thx :idea:
Great I was worried you might want the icons too and I don't know how to get at them anymore. 😅
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Re: Desktop's capture

Post by SPH »

idle wrote: Sun Oct 13, 2024 8:00 am
SPH wrote: Sun Oct 13, 2024 7:50 am Excellentissimo !

Thx :idea:
Thanks for your code.

But I have a problem to integrate it into my code. How to transform the part of my code so that it receives the image of your code?

PS: my code and your code one after the other.

Thanks
Great I was worried you might want the icons too and I don't know how to get at them anymore. 😅
Thanks for your code.

But I have a problem to integrate it into my code. How to transform the part of my code so that it receives the image of your code?

PS: my code and your code one after the other.

Thanks

Code: Select all

;;;; your code

Import "user32.lib" 
  PrintWindow(hWnd, hdc, flags.l)
EndImport   

Global width,height,wallpaper   

Procedure GetWallpaper(mon=0) 
  Protected himage,hdc,hwnd
  ExamineDesktops()
  width = DesktopWidth(mon) 
  height = DesktopHeight(mon) 
  hImage = CreateImage(-1,Width,Height) 
  hDC  = StartDrawing(ImageOutput(himage)) 
  printwindow(FindWindowEx_(0, 0, @"Progman", 0) ,hdc,0) 
  StopDrawing() 
  ProcedureReturn hImage 
EndProcedure

wallpaper = GetWallpaper(0)

;OpenWindow(0,0,0,width,height,"desktop") 
ImageGadget(1,0,0,width,height,ImageID(wallpaper)) 





;;;; my code
image$="f:/southpark_presentateur.bmp"      ;- put a picture in desktop resolution (if you can, else not =) )
Image1 = LoadImage(#PB_Any,image$)
Texture1 = SetupGLTexture(Image1)


!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Desktop's capture

Post by idle »

it would be

Code: Select all

wallpaper = GetWallpaper(0)
Texture1 = SetupGLTexture(wallpaper)
If that doesn't work try to change the image depth to 24

Code: Select all

Procedure GetWallpaper(mon=0) 
  Protected himage,hdc,hwnd
  ExamineDesktops()
  width = DesktopWidth(mon) 
  height = DesktopHeight(mon) 
  hImage = CreateImage(-1,Width,Height,24) 
  hDC  = StartDrawing(ImageOutput(himage)) 
  printwindow(FindWindowEx_(0, 0, @"Progman", 0) ,hdc,0) 
  StopDrawing() 
  ProcedureReturn hImage 
EndProcedure

User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Re: Desktop's capture

Post by SPH »

I can't do it... :?

I want to replace the "loadimage" with loading the desktop image (line 258 to 260)

in this code :

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code : Lightning camera   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; PB6.11 - SPH(2024) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Global chemin$,sph_cmb,attente,attente_ok,mix,miy,ddw,ddh
Global numero,timer,echelle_xf.f,echelle_yf.f,Resx,Resy,categorie$
Global ultimated_NANO_ALPHA.q,cat$,Dim speedx.w(1,1),Dim speedy.w(1,1)
Global axe1f.f,axe2f.f,axe3f.f,axe4f.f
;-GLOBALS
Global.i Image1, Image2
Global.i Texture1, Texture2
Global menu,ref_ici
;-DEFINES
Define.i Event
Define.i WindowFlags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget


;EnableExplicit

;-CONSTANTS
Enumeration
  #MainWindow
  #OpenGLGadget
EndEnumeration

;These two GL constants are used for texture creation. Don't change their values.
#GL_BGR = $80E0
#GL_BGRA = $80E1

ExamineDesktops()
ddw=DesktopWidth(0)
ddh=DesktopHeight(0)
mix=ddw/2
miy=ddh/2

;********************* DPI *********************
echelle_xf.f=(1920/ddw)*DesktopResolutionX()
echelle_yf.f=(1080/ddh)*DesktopResolutionY()
;**********************************************

;-STRUCTURES
Structure Integer2
  X.i
  Y.i
EndStructure
Global.Integer2 WindowDim
WindowDim\X = ddw
WindowDim\Y = ddh


;-DEFINES
Define.i Event
Define.i WindowFlags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget


;-DECLARES
Declare Render()
Declare Render2DQuad(OGLTexture.i, StartX.d, StartY.d, Width.i, Height.i, Z.d)
Declare SetupOpenGL()
Declare SetupGLTexture(ImageHandle.i)


;-MAIN WINDOW
win=OpenWindow(#MainWindow, 0, 0,ddw,ddh, "Lecteur_polygons",#PB_Window_Maximize|#PB_Window_BorderLess)
If win=0
  ;   Beep_(500,250) : Delay(150) : Beep_(500,250)
  MessageRequester("Erreur","OpenWindow() impossible")
  End
EndIf

screenGL=OpenGLGadget(#OpenGLGadget,0,0,ddw,ddh)
If screenGL=0
  ;   Beep_(500,250) : Delay(150) : Beep_(500,250)
  MessageRequester("Erreur","OpenGLGadget() impossible")
  End
EndIf


SetupOpenGL()

AddKeyboardShortcut(0,  #PB_Shortcut_Escape, 666) ; quitter

glOrtho_(0,ddw,ddh,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(0)

;*********************************************************************************************************************************

;;;;;;;;;;;
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)


Procedure Render()
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glClearColor_(0,0,0,1)
  glEnable_(#GL_TEXTURE_2D)
  Render2DQuad(Texture1, 0, 0, ImageWidth(Image1), ImageHeight(Image1), -2)
  glDisable_(#GL_TEXTURE_2D)
EndProcedure

Procedure Render2DQuad(OGLTexture.i, StartX.d, StartY.d, Width.i, Height.i, Z.d)
  glBindTexture_(#GL_TEXTURE_2D, OGLTexture)
  glBegin_(#GL_QUADS)
  glColor4f_   (1,1,1,1)
  glNormal3f_  (0,0,1.0)
  glTexCoord2f_(1.0,1.0)
  glVertex3f_  (StartX+Width,StartY,Z)
  glTexCoord2f_(0.0,1.0)
  glVertex3f_  (StartX,StartY,Z)
  glTexCoord2f_(0.0,0.0)
  glVertex3f_  (StartX,StartY+Height,Z)
  glTexCoord2f_(1.0,0.0)
  glVertex3f_  (StartX+Width,StartY+Height,Z)
  glEnd_()
  
EndProcedure

Procedure SetupOpenGL()
  
  glMatrixMode_(#GL_PROJECTION)
  
  glOrtho_(0.0, WindowDim\X, WindowDim\Y, 0.0, -1000.0, 1000.0)
  
  glMatrixMode_(#GL_MODELVIEW)
  
  ; glEnable_(#GL_DEPTH_TEST)
  
  glEnable_(#GL_BLEND)
  glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
  
EndProcedure

Procedure affiche_poly(attente,pol,xxx,yyy,angle.f,dkx,dky,zoom.f,alpha.f)
  sph_cmb=speedy(pol,0)
  sph_la=0
  Repeat
    glBegin_(#GL_POLYGON)
    glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
    glColor4f_(speedx(pol,sph_la+1)/255,speedy(pol,sph_la+1)/255,speedx(pol,sph_la+2)/255,(speedy(pol,sph_la+2)/255)*alpha)
    ;;;;;;
    For i=3 To sph_cmb-1
      sph_xxx.f=(speedx(pol,sph_la+i)/echelle_xf)-xxx
      sph_yyy.f=(speedy(pol,sph_la+i)/echelle_yf)-yyy
      sq.f=Sqr(sph_xxx*sph_xxx+sph_yyy*sph_yyy)
      ff.f = ATan2(sph_xxx,sph_yyy)+angle ; par Nemerod (sans lui, je n'y serai pas arrivé)
      centre_x=xxx+Cos(ff)*sq*zoom
      centre_y=yyy+Sin(ff)*sq*zoom
      glVertex2f_(centre_x+dkx,centre_y+dky);
    Next
    ;;;;;;;
    glEnd_()                      ; 
    sph_cmb=speedy(pol,sph_la+i)
    sph_la+i
  Until speedy(pol,sph_la)=0
  
  If attente<>0 And ElapsedMilliseconds()-timer>=attente
    timer=ElapsedMilliseconds()
    numero+1
  EndIf
  
  ;;;;;;;;;;;;;;;
EndProcedure

Procedure SetupGLTexture(ImageHandle.i)
  
  Define.i ImageW, ImageH, ImageD
  Define.i MemoryAddress
  Define.i TextureHandle
  
  If IsImage(ImageHandle) = 0
    ProcedureReturn #False
  EndIf
  
  ImageD = ImageDepth(ImageHandle, #PB_Image_InternalDepth)
  
  StartDrawing(ImageOutput(ImageHandle))
  MemoryAddress = DrawingBuffer()
  StopDrawing()
  
  If MemoryAddress = 0
    ProcedureReturn #False
  EndIf
  
  glGenTextures_(1, @TextureHandle)
  glBindTexture_(#GL_TEXTURE_2D, TextureHandle)
  
  ImageW = ImageWidth(ImageHandle)
  ImageH = ImageHeight(ImageHandle)
  
  If ImageD = 32
    glTexImage2D_(#GL_TEXTURE_2D, 0, 4, ImageW, ImageH, 0, #GL_BGRA, #GL_UNSIGNED_BYTE, MemoryAddress)
  Else
    glTexImage2D_(#GL_TEXTURE_2D, 0, 3, ImageW, ImageH, 0, #GL_BGR, #GL_UNSIGNED_BYTE, MemoryAddress)
  EndIf
  
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
  ;   glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
  
  ProcedureReturn TextureHandle
  
EndProcedure

Procedure gestion()
  Repeat
    Event = WindowEvent()
    
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Resx = GetGadgetAttribute(1, #PB_OpenGL_MouseX)
            Resy = GetGadgetAttribute(1, #PB_OpenGL_MouseY)
            ;;;;;;;         
            Select EventType()
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;             
            EndSelect
        EndSelect
      Case #PB_Event_Menu
        Select EventMenu()
          Case 666
            ;timer=ElapsedMilliseconds()-timer
            ;ShowCursor_(1)
            End
        EndSelect
    EndSelect
    
  Until Event = 0
EndProcedure


;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
glClearColor_(0,0,0, 1.0)

max=21
poly_cmb=0
pol=0
Dim speedx(poly_cmb,max)
Dim speedy(poly_cmb,max)

For i=1 To max
  Read.w speedx(pol,i-1)
  Read.w speedy(pol,i-1)
Next

;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;  I want to replace the "loadimage" with loading the desktop image  **********************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************

image$="f:/southpark_presentateur.bmp"
Image1 = LoadImage(#PB_Any,image$)
Texture1 = SetupGLTexture(Image1)

;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************

;;;;;;;;;;;;;;;;;;;;;;;

combien=6

Dim zoo1(combien)
Dim zoo2(combien)
For i=0 To combien
  zoo1(i)=Random(200)+55
  zoo2(i)=Random(200)+55
Next

Dim zoom.f(combien)
Dim zoom2.f(combien)
For i=0 To combien
  zoom(i)=Random(100)/100
  zoom2(i)=Random(100)/100
Next

Dim dist.f(combien)
For i=0 To combien
  dist(i)=0.2+Random(400)/100
Next

centrex=(540/echelle_xf)
centrey=(540/echelle_yf)

ddwf.f=5.4+ddw/1920
ddhf.f=5.4+ddh/1080


Repeat
  
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  gestion()
  
  Render()
  glReadPixels_(Resx, ddh-1-Resy, 1 , 1, #GL_RGBA, #GL_UNSIGNED_BYTE, @pixels )
  ;##############################################
  ;affiche_poly(attente | n° de polygone | axe de rotation X | axe de rotation Y | angle de rotation(.f) | decallage X | decallage Y | Zoom(.f) | alpha.f)
  ;mix=milieu de l'ecran (en X)
  ;miy=milieu de l'ecran (en Y)
  ;##############################################
  
  For nb=0 To combien 
    For i=0 To 20
      affiche_poly(0,0,0,0,0,mix-centrex*zoom(nb)+i*ddwf-mix*dist(nb)+Resx*dist(nb),miy-centrey*zoom(nb)+i*ddhf-miy*dist(nb)+Resy*dist(nb),zoom(nb)-i/100,1/zoo1(nb))
      affiche_poly(0,0,0,0,0,mix-centrex*zoom2(nb)+i*ddwf+mix*dist(nb)-Resx*dist(nb),miy-centrey*zoom2(nb)+i*ddhf+miy*dist(nb)-Resy*dist(nb),zoom2(nb)-i/100,1/zoo2(nb))
    Next
  Next
  
  SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
  
ForEver

End

DataSection
  sph_data:
  Data.w 1,21,255,255,255,255,1014,802,1025,775,1025,304,1012,270,990,243,566,4,540,1,511,4,80
  Data.w 255,65,272,59,295,59,781,64,804,81,819,518,1077,543,1079,567,1077,993,829
  Data.w 0,0
EndDataSection

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Desktop's capture

Post by idle »

it worked for me with

Code: Select all

Image1 = GetWallpaper(0)
Texture1 = SetupGLTexture(Image1)

full code

Code: Select all

;;;; your code

Import "user32.lib" 
  PrintWindow(hWnd, hdc, flags.l)
EndImport   

Global width,height,wallpaper   

Procedure GetWallpaper(mon=0) 
  Protected himage,hdc,hwnd
  ExamineDesktops()
  width = DesktopWidth(mon) 
  height = DesktopHeight(mon) 
  hImage = CreateImage(-1,Width,Height,24) 
  hDC  = StartDrawing(ImageOutput(himage)) 
  printwindow(FindWindowEx_(0, 0, @"Progman", 0) ,hdc,0) 
  StopDrawing() 
  ProcedureReturn hImage 
EndProcedure

wallpaper = GetWallpaper(0)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code : Lightning camera   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; PB6.11 - SPH(2024) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Global chemin$,sph_cmb,attente,attente_ok,mix,miy,ddw,ddh
Global numero,timer,echelle_xf.f,echelle_yf.f,Resx,Resy,categorie$
Global ultimated_NANO_ALPHA.q,cat$,Dim speedx.w(1,1),Dim speedy.w(1,1)
Global axe1f.f,axe2f.f,axe3f.f,axe4f.f
;-GLOBALS
Global.i Image1, Image2
Global.i Texture1, Texture2
Global menu,ref_ici
;-DEFINES
Define.i Event
Define.i WindowFlags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget


;EnableExplicit

;-CONSTANTS
Enumeration
  #MainWindow
  #OpenGLGadget
EndEnumeration

;These two GL constants are used for texture creation. Don't change their values.
#GL_BGR = $80E0
#GL_BGRA = $80E1

ExamineDesktops()
ddw=DesktopWidth(0)
ddh=DesktopHeight(0)
mix=ddw/2
miy=ddh/2

;********************* DPI *********************
echelle_xf.f=(1920/ddw)*DesktopResolutionX()
echelle_yf.f=(1080/ddh)*DesktopResolutionY()
;**********************************************

;-STRUCTURES
Structure Integer2
  X.i
  Y.i
EndStructure
Global.Integer2 WindowDim
WindowDim\X = ddw
WindowDim\Y = ddh


;-DEFINES
Define.i Event
Define.i WindowFlags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget


;-DECLARES
Declare Render()
Declare Render2DQuad(OGLTexture.i, StartX.d, StartY.d, Width.i, Height.i, Z.d)
Declare SetupOpenGL()
Declare SetupGLTexture(ImageHandle.i)


;-MAIN WINDOW
win=OpenWindow(#MainWindow, 0, 0,ddw,ddh, "Lecteur_polygons",#PB_Window_Maximize|#PB_Window_BorderLess)
If win=0
  ;   Beep_(500,250) : Delay(150) : Beep_(500,250)
  MessageRequester("Erreur","OpenWindow() impossible")
  End
EndIf

screenGL=OpenGLGadget(#OpenGLGadget,0,0,ddw,ddh)
If screenGL=0
  ;   Beep_(500,250) : Delay(150) : Beep_(500,250)
  MessageRequester("Erreur","OpenGLGadget() impossible")
  End
EndIf


SetupOpenGL()

AddKeyboardShortcut(0,  #PB_Shortcut_Escape, 666) ; quitter

glOrtho_(0,ddw,ddh,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(0)

;*********************************************************************************************************************************

;;;;;;;;;;;
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)


Procedure Render()
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glClearColor_(0,0,0,1)
  glEnable_(#GL_TEXTURE_2D)
  Render2DQuad(Texture1, 0, 0, ImageWidth(Image1), ImageHeight(Image1), -2)
  glDisable_(#GL_TEXTURE_2D)
EndProcedure

Procedure Render2DQuad(OGLTexture.i, StartX.d, StartY.d, Width.i, Height.i, Z.d)
  glBindTexture_(#GL_TEXTURE_2D, OGLTexture)
  glBegin_(#GL_QUADS)
  glColor4f_   (1,1,1,1)
  glNormal3f_  (0,0,1.0)
  glTexCoord2f_(1.0,1.0)
  glVertex3f_  (StartX+Width,StartY,Z)
  glTexCoord2f_(0.0,1.0)
  glVertex3f_  (StartX,StartY,Z)
  glTexCoord2f_(0.0,0.0)
  glVertex3f_  (StartX,StartY+Height,Z)
  glTexCoord2f_(1.0,0.0)
  glVertex3f_  (StartX+Width,StartY+Height,Z)
  glEnd_()
  
EndProcedure

Procedure SetupOpenGL()
  
  glMatrixMode_(#GL_PROJECTION)
  
  glOrtho_(0.0, WindowDim\X, WindowDim\Y, 0.0, -1000.0, 1000.0)
  
  glMatrixMode_(#GL_MODELVIEW)
  
  ; glEnable_(#GL_DEPTH_TEST)
  
  glEnable_(#GL_BLEND)
  glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
  
EndProcedure

Procedure affiche_poly(attente,pol,xxx,yyy,angle.f,dkx,dky,zoom.f,alpha.f)
  sph_cmb=speedy(pol,0)
  sph_la=0
  Repeat
    glBegin_(#GL_POLYGON)
    glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
    glColor4f_(speedx(pol,sph_la+1)/255,speedy(pol,sph_la+1)/255,speedx(pol,sph_la+2)/255,(speedy(pol,sph_la+2)/255)*alpha)
    ;;;;;;
    For i=3 To sph_cmb-1
      sph_xxx.f=(speedx(pol,sph_la+i)/echelle_xf)-xxx
      sph_yyy.f=(speedy(pol,sph_la+i)/echelle_yf)-yyy
      sq.f=Sqr(sph_xxx*sph_xxx+sph_yyy*sph_yyy)
      ff.f = ATan2(sph_xxx,sph_yyy)+angle ; par Nemerod (sans lui, je n'y serai pas arrivé)
      centre_x=xxx+Cos(ff)*sq*zoom
      centre_y=yyy+Sin(ff)*sq*zoom
      glVertex2f_(centre_x+dkx,centre_y+dky);
    Next
    ;;;;;;;
    glEnd_()                      ; 
    sph_cmb=speedy(pol,sph_la+i)
    sph_la+i
  Until speedy(pol,sph_la)=0
  
  If attente<>0 And ElapsedMilliseconds()-timer>=attente
    timer=ElapsedMilliseconds()
    numero+1
  EndIf
  
  ;;;;;;;;;;;;;;;
EndProcedure

Procedure SetupGLTexture(ImageHandle.i)
  
  Define.i ImageW, ImageH, ImageD
  Define.i MemoryAddress
  Define.i TextureHandle
  
  If IsImage(ImageHandle) = 0
    ProcedureReturn #False
  EndIf
  
  ImageD = ImageDepth(ImageHandle, #PB_Image_InternalDepth)
  
  StartDrawing(ImageOutput(ImageHandle))
  MemoryAddress = DrawingBuffer()
  StopDrawing()
  
  If MemoryAddress = 0
    ProcedureReturn #False
  EndIf
  
  glGenTextures_(1, @TextureHandle)
  glBindTexture_(#GL_TEXTURE_2D, TextureHandle)
  
  ImageW = ImageWidth(ImageHandle)
  ImageH = ImageHeight(ImageHandle)
  
  If ImageD = 32
    glTexImage2D_(#GL_TEXTURE_2D, 0, 4, ImageW, ImageH, 0, #GL_BGRA, #GL_UNSIGNED_BYTE, MemoryAddress)
  Else
    glTexImage2D_(#GL_TEXTURE_2D, 0, 3, ImageW, ImageH, 0, #GL_BGR, #GL_UNSIGNED_BYTE, MemoryAddress)
  EndIf
  
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
  ;   glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
  
  ProcedureReturn TextureHandle
  
EndProcedure

Procedure gestion()
  Repeat
    Event = WindowEvent()
    
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Resx = GetGadgetAttribute(1, #PB_OpenGL_MouseX)
            Resy = GetGadgetAttribute(1, #PB_OpenGL_MouseY)
            ;;;;;;;         
            Select EventType()
                ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;             
            EndSelect
        EndSelect
      Case #PB_Event_Menu
        Select EventMenu()
          Case 666
            ;timer=ElapsedMilliseconds()-timer
            ;ShowCursor_(1)
            End
        EndSelect
    EndSelect
    
  Until Event = 0
EndProcedure


;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
glClearColor_(0,0,0, 1.0)

max=21
poly_cmb=0
pol=0
Dim speedx(poly_cmb,max)
Dim speedy(poly_cmb,max)

For i=1 To max
  Read.w speedx(pol,i-1)
  Read.w speedy(pol,i-1)
Next

;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;  I want to replace the "loadimage" with loading the desktop image  **********************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************

image$="f:/southpark_presentateur.bmp"
Image1 = GetWallpaper(0)
Texture1 = SetupGLTexture(Image1)

;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################**********************************************

;;;;;;;;;;;;;;;;;;;;;;;

combien=6

Dim zoo1(combien)
Dim zoo2(combien)
For i=0 To combien
  zoo1(i)=Random(200)+55
  zoo2(i)=Random(200)+55
Next

Dim zoom.f(combien)
Dim zoom2.f(combien)
For i=0 To combien
  zoom(i)=Random(100)/100
  zoom2(i)=Random(100)/100
Next

Dim dist.f(combien)
For i=0 To combien
  dist(i)=0.2+Random(400)/100
Next

centrex=(540/echelle_xf)
centrey=(540/echelle_yf)

ddwf.f=5.4+ddw/1920
ddhf.f=5.4+ddh/1080


Repeat
  
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  gestion()
  
  Render()
  glReadPixels_(Resx, ddh-1-Resy, 1 , 1, #GL_RGBA, #GL_UNSIGNED_BYTE, @pixels )
  ;##############################################
  ;affiche_poly(attente | n° de polygone | axe de rotation X | axe de rotation Y | angle de rotation(.f) | decallage X | decallage Y | Zoom(.f) | alpha.f)
  ;mix=milieu de l'ecran (en X)
  ;miy=milieu de l'ecran (en Y)
  ;##############################################
  
  For nb=0 To combien 
    For i=0 To 20
      affiche_poly(0,0,0,0,0,mix-centrex*zoom(nb)+i*ddwf-mix*dist(nb)+Resx*dist(nb),miy-centrey*zoom(nb)+i*ddhf-miy*dist(nb)+Resy*dist(nb),zoom(nb)-i/100,1/zoo1(nb))
      affiche_poly(0,0,0,0,0,mix-centrex*zoom2(nb)+i*ddwf+mix*dist(nb)-Resx*dist(nb),miy-centrey*zoom2(nb)+i*ddhf+miy*dist(nb)-Resy*dist(nb),zoom2(nb)-i/100,1/zoo2(nb))
    Next
  Next
  
  SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
  
ForEver

End

DataSection
  sph_data:
  Data.w 1,21,255,255,255,255,1014,802,1025,775,1025,304,1012,270,990,243,566,4,540,1,511,4,80
  Data.w 255,65,272,59,295,59,781,64,804,81,819,518,1077,543,1079,567,1077,993,829
  Data.w 0,0
EndDataSection
User avatar
SPH
Enthusiast
Enthusiast
Posts: 593
Joined: Tue Jan 04, 2011 6:21 pm

Re: Desktop's capture

Post by SPH »

Hooooo, thank you very much. That's nice !! :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Post Reply