
Je n'arrive pas a "peek" une couleur de l'image aux coordonnées de la souris.
Y aurait il une âme charitable pour m'aider ?
Merci

EDIT : c'est bon (touche "P" pour "peek") mais il faut que vous mettiez une image de fond pour peeker
Code : Tout sélectionner
;EnableExplicit
UsePNGImageDecoder()
UseJPEGImageDecoder()
;-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
If ExamineDesktops()
ddw=DesktopWidth(0)
ddh=DesktopHeight(0)
Else
ddw=1920
ddh=1080
EndIf
;-STRUCTURES
Structure Integer2
X.i
Y.i
EndStructure
Global.Integer2 WindowDim
WindowDim\X = ddw
WindowDim\Y = ddh
;-GLOBALS
Global.i Image1, Image2
Global.i Texture1, Texture2
;-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, "Polygons_Maker",#PB_Window_Maximize|#PB_Window_BorderLess)
If win=0
Beep_(500,250) : Delay(150) : Beep_(500,250)
Debug ("OpenWindow() impossible")
End
EndIf
screenGL=OpenGLGadget(#OpenGLGadget,0,0,ddw,ddh)
If screenGL=0
Beep_(500,250) : Delay(150) : Beep_(500,250)
Debug ("OpenGLGadget() impossible")
End
EndIf
; If OpenWindow(#MainWindow, 0, 0, WindowDim\X, WindowDim\Y, "Polygons_Maker",#PB_Window_Maximize|#PB_Window_BorderLess)
; If OpenGLGadget(#OpenGLGadget, 0, 0, WindowDim\X, WindowDim\Y) = 0
; End
; EndIf
;This procedure sets up the rendering system to mimic the standard Purebasic drawing system.
SetupOpenGL()
;Load images.
Image1 = LoadImage(#PB_Any,"f:\image_gl.bmp")
; Image2 = LoadImage(#PB_Any, #PB_Compiler_Home+"\Examples\3D\Data\Textures\grass1.png")
;Now we create textures which can be used for rendering with OpenGL.
Texture1 = SetupGLTexture(Image1)
; Texture2 = SetupGLTexture(Image2)
;*********************************************************************************************************************************
;*********************************************************************************************************************************
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 666)
AddKeyboardShortcut(0, #PB_Shortcut_H, 8) ; hide/show
AddKeyboardShortcut(0, #PB_Shortcut_P, 16); peek une couleur
AddKeyboardShortcut(0, #PB_Shortcut_Add, 100) ; alpha+0.01
AddKeyboardShortcut(0, #PB_Shortcut_Subtract, 101) ; alpha-0.01
AddKeyboardShortcut(0, #PB_Shortcut_Multiply, 102) ; alpha=0.5
AddKeyboardShortcut(0, #PB_Shortcut_Divide, 103) ; NO alpha
AddKeyboardShortcut(0, #PB_Shortcut_Pad1, 110) ; rouge-0.02
AddKeyboardShortcut(0, #PB_Shortcut_Pad2, 111) ; rouge+0.02
AddKeyboardShortcut(0, #PB_Shortcut_Pad4, 112) ; vert-0.02
AddKeyboardShortcut(0, #PB_Shortcut_Pad5, 113) ; vert+0.02
AddKeyboardShortcut(0, #PB_Shortcut_Pad7, 114) ; bleu-0.02
AddKeyboardShortcut(0, #PB_Shortcut_Pad8, 115) ; bleu+0.02
AddKeyboardShortcut(0, #PB_Shortcut_Pad3, 116) ; rouge=0.5
AddKeyboardShortcut(0, #PB_Shortcut_Pad6, 117) ; vert=0.5
AddKeyboardShortcut(0, #PB_Shortcut_Pad9, 118) ; bleu=0.5
hide=0
alpha.f=0.5
rouge.f=0.5
vert.f=0.5
bleu.f=0.5
no_alpha=0
nb=0
Dim poly_x(1000)
Dim poly_y(1000)
Dim poly_x2(100000)
Dim poly_y2(100000)
glOrtho_(0,ddw,ddh,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(0)
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;-MAIN REPEAT
Repeat ;- ..... Repeat
glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
Render()
glReadPixels_(Resx, ddh-1-Resy, 1 , 1, #GL_RGBA, #GL_UNSIGNED_BYTE, @pixels )
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Resx = GetGadgetAttribute(1, #PB_OpenGL_MouseX)
Resy = GetGadgetAttribute(1, #PB_OpenGL_MouseY)
;;;;;;;
Select EventType()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_LeftClick
Beep_(1500,33) ;Debug "Clic avec le bouton gauche de la souris"
poly_x(0)+1
poly_x(poly_x(0))=Resx
poly_y(poly_x(0))=Resy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_RightDoubleClick
If poly_x(0)>0
Beep_(500,400) ;: Debug "Double-clic avec le bouton droit de la souris"
Dim poly_x(1000)
Dim poly_y(1000)
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_RightClick
If poly_x(0)>0
Beep_(500,33) ;Debug "Clic avec le bouton droit de la souris"
poly_x(0)-1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_MiddleButtonDown
If poly_x(0)>2
Beep_(3000,33) : Delay(33) : Beep_(3000,33) ;Debug "Clic avec le bouton centre de la souris"
;-;;;;;;;;;;;;;;;;;;;;;;;bouton centre
poly_x2(0)+1
nb=0
While poly_y2(nb)>0
i=poly_y2(nb)
Debug "i = "+Str(nb)
nb+i
Wend
Debug "nb = "+Str(nb)
poly_y2(nb)=poly_x(0)+5
poly_x2(nb+1)=rouge*65536
poly_x2(nb+2)=vert*65536
poly_x2(nb+3)=bleu*65536
poly_x2(nb+4)=alpha*65536
For i=1 To poly_x(0)
poly_x2(nb+4+i)=poly_x(i)
poly_y2(nb+4+i)=poly_y(i)
Next
Dim poly_x(1000)
Dim poly_y(1000)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndSelect
EndSelect
Case #PB_Event_Menu
Select EventMenu()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 666
End
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 8
hide+1 : hide%2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 16
glReadPixels_(Resx, ddh-1-Resy, 1 , 1, #GL_RGBA, #GL_UNSIGNED_BYTE, @pixels )
rouge=(Red(pixels))/255
vert=(Green(pixels))/255
bleu=(Blue(pixels))/255
alpha=(Alpha(pixels))/255
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 100
alpha+0.01
If alpha>1
alpha=1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 101
alpha-0.01
If alpha<0
alpha=0
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 102
alpha=0.5
no_alpha=0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 103
no_alpha+1 : no_alpha%2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 110
rouge-0.02
If rouge<0
rouge=0
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 111
rouge+0.02
If rouge>1
rouge=1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 112
vert-0.02
If vert<0
vert=0
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 113
vert+0.02
If vert>1
vert=1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 114
bleu-0.02
If bleu<0
bleu=0
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 115
bleu+0.02
If bleu>1
bleu=1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 116
rouge=0.5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 117
vert=0.5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 118
bleu=0.5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndSelect
EndSelect
peeek-1
If peeek<0
peeek=0
EndIf
glBlendFunc_(#GL_SRC_ALPHA,0)
glBegin_(#GL_POLYGON)
glColor4f_(1,1,1,1)
glVertex2f_(22,11)
glVertex2f_(500,66)
glVertex2f_(33,755)
glEnd_()
; glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glBegin_(#GL_POLYGON)
glColor4f_(0,1,1,0.5)
;glColor4f_(1,1,1,1)
glVertex2f_(400,600)
glVertex2f_(200,600)
glVertex2f_(300,100)
glEnd_()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If poly_x(0)>1; And 0=1
glBegin_(#GL_POLYGON)
If no_alpha=1
glColor4f_(rouge,vert,bleu,1)
Else
glColor4f_(rouge,vert,bleu,alpha)
EndIf
For i=1 To poly_x(0)
glVertex2f_(poly_x(i),poly_y(i))
Next
If hide=0
glVertex2f_(Resx,Resy) ;: Debug Resx : Debug Resy : Debug "----------"
EndIf
glEnd_()
EndIf
; SetGadgetAttribute(1,#PB_OpenGL_FlipBuffers,#True)
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
ForEver
; EndIf
End
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
Procedure Render()
;Clearing buffers and resetting clear color to remove old graphics from the last frame.
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
; glClearColor_(0.2, 0.2, 0.2, 1.0)
glClearColor_(0,0,0,1)
;## DRAWING TEXTURES/IMAGES
;First enable the Texture system.
glEnable_(#GL_TEXTURE_2D)
;This procedure will create a quad and apply a texture to it.
;The Texture variable contains the texture created earlier using SetupGLTexture().
Render2DQuad(Texture1, 0, 0, ImageWidth(Image1), ImageHeight(Image1), -2)
; Render2DQuad(Texture2, 0, 0, ImageWidth(Image2), ImageHeight(Image2), -1)
;After all the textures have been displayed disable the texture system.
;Otherwise it will conflict with the non texture graphics.
glDisable_(#GL_TEXTURE_2D)
EndProcedure
Procedure Render2DQuad(OGLTexture.i, StartX.d, StartY.d, Width.i, Height.i, Z.d)
;The texture is first bound which tells OpenGL to use this texture for any future rendering.
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 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