Texte sur du openGL

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
Zorro
Messages : 2185
Inscription : mar. 31/mai/2016 9:06

Re: Texte sur du openGL

Message par Zorro »

@Kernadec , ton dernier code fonctionne un peu mieux
je peux utiliser la barre d'espace et voir le recap des touches

mais la touche R et Ctrl+R ne donne rien chez moi :)

ps: lorsque c'est possible, je conseille l'emploi de " Case ---- Select Case "
c'est bien plus clair qu'une serie de If else endif et le pire :-> ElseIf
Image
Image
Site: http://michel.dobro.free.fr/
Devise :"dis moi ce dont tu as besoin, je t'expliquerai comment t'en passer"
Avatar de l’utilisateur
kernadec
Messages : 1594
Inscription : ven. 25/avr./2008 11:14

Re: Texte sur du openGL

Message par kernadec »

bjr Zorro
Ok pour [Select], [Case], je comprend ton point de vue.
Dans le manuel pour CanvasGadget et OpenGlGadget
les exemples utilisent très souvent la commande EventType()

donc j'ai fait des recherche sur le forum anglais pour voir si il y a des exemples qui utilise OpenGLGadget avec eventype()
comme l' exemple du manuel de l ' OpenGLGadget, d'ailleurs celui-ci a déjà été revisité par applePI sur le forum English.
le lien est placé en tête du code.

comme ce code fonctionnait bien chez moi. Cela ma donné l'idée de poursuive et ajouter du texte sur la Fenêtre
OpenGLGadget via la commande drawtext() ensuite augmenté les menus flèches pour le déplacement du cube
et pour modifier quelques couleurs sur le cube utilisation des commandes [Contrôle] et [Shift] avec une lettre..
je met cet essai pour le fun :mrgreen:

En visitant le lien du code applePI celui-ci donne un lien vers un post de Danilo ou ce sujet est abordé
en scrutant les codes, je suis tombé sur celui de marc_256 qui utilise les commandes [Select], [Case].
Demain, j'essayerais dans le code menu SPH qui pose problème, en attendant j'ai modifie l'exemple OpenGLGadget
avec ce mode [Select], [Case] de marc_256 pour tester. ça marche sur mes machines :D

Cordialement

Code Mode : EvenType()

Code : Tout sélectionner

;https://www.purebasic.fr/english/viewtopic.php?f=36&t=60039
;
; OpenGL Gadget demonstration
;
; (c) Fantaisie Software
;
; Axis explainations:
;
;             +
;             y
;
;             |
;             |
;  +          |
;  x ---------\
;              \
;               \
;                \
;                  z+
;
; So a rotate on the y axis will take the y axis as center. With OpenGL, we can specify
; positive And negative value. Positive values are always in the same sens as the axis
; (like described on the schmatic, with '+' signs)
;

Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f = 1.0
Global RotateSpeedY.f
Global RotateSpeedZ.f = 1.0

Global ZoomFactor.f = 1.0 ; Distance of the camera. Negative value = zoom back
Global MoveX.f = 0        ; Distance of the camera. Negative value = Movex
Global MoveY.f = 0        ; Distance of the camera. Negative value = Movey
Global Rouge.f = 0        ;  couleur rouge
Global Vert.f = 0         ;  couleur rouge
Global Bleu.f = 1         ;  couleur rouge
Global Alpha.f = 1        ;  couleur rouge


Procedure DrawCube(Gadget)
  SetGadgetAttribute(Gadget, #PB_OpenGL_SetContext, #True)
  
  glPushMatrix_()                  ; Save the original Matrix coordinates
  glMatrixMode_(#GL_MODELVIEW)
  
  glTranslatef_(MoveX, MoveY, ZoomFactor)  ;  move it forward a bit
  
  
  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
  
  RollAxisX + RotateSpeedX
  RollAxisY + RotateSpeedY
  RollAxisZ + RotateSpeedZ
  
  ; clear framebuffer And depth-buffer
  
  glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  
  ; draw the faces of a cube
  
  ; draw colored faces
  
  glDisable_(#GL_LIGHTING)
  glBegin_  (#GL_QUADS)
  
  ; Build a face, composed of 4 vertex !
  ; glBegin() specify how the vertexes are considered. Here a group of
  ; 4 vertexes (GL_QUADS) form a rectangular surface.
  
  ; Now, the color stuff: It's r,v,b but with float values which
  ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity)
  
  glNormal3f_ (0,0,1.0)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (0.5,0.5,0.5)   
  glColor3f_  (0,1.0,1.0)         
  glVertex3f_ (-0.5,0.5,0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (-0.5,-0.5,0.5)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (0.5,-0.5,0.5)
  
  ; The other face is the same than the previous one
  ; except the colour which is nice blue To white gradiant
  
  glNormal3f_ (0,0,-1.0)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (-0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,-0.5,-0.5)
  
  glEnd_()
  
  ; draw shaded faces
  
  glEnable_(#GL_LIGHTING)
  glEnable_(#GL_LIGHT0)
  glBegin_ (#GL_QUADS)
  
  glNormal3f_ (   0, 1.0,   0)
  glVertex3f_ ( 0.5, 0.5, 0.5)
  glVertex3f_ ( 0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  
  glNormal3f_ (0,-1.0,0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (-0.5,-0.5,0.5)
  
  glNormal3f_ (1.0,0,0)
  glVertex3f_ (0.5,0.5,0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,0.5,-0.5)
  
  glNormal3f_ (-1.0,   0,   0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (-0.5,-0.5, 0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  
  glEnd_()
  
  glPopMatrix_()
  glFinish_()
  
  SetGadgetAttribute(Gadget, #PB_OpenGL_FlipBuffers, #True)
EndProcedure


Procedure SetupGL()
  
  glMatrixMode_(#GL_PROJECTION)
  gluPerspective_(30.0, 200/200, 1.0, 50)
  
  ; position viewer
  glMatrixMode_(#GL_MODELVIEW)
  
  glTranslatef_(0, 0, -5.0)
  
  glEnable_(#GL_DEPTH_TEST)   ; Enabled, it slowdown a lot the rendering. It's to be sure than the
                              ; rendered objects are inside the z-buffer.
  
  glEnable_(#GL_CULL_FACE)    ; This will enhance the rendering speed as all the back face will be
                              ; ignored. This works only with CLOSED objects like a cube... Singles
                              ; planes surfaces will be visibles only on one side.
  
  glShadeModel_(#GL_SMOOTH)
  
  glEnable_(#GL_BLEND)
  glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
  
EndProcedure

Procedure Titre()   
  StartDrawing(WindowOutput(0))
  DrawText(10, 212 , Space(50), RGB(240, 240, 240), RGB(240, 240, 240))
  DrawText(10, 212 , "Menu Couleur " + Int(Mod(Abs(Rouge.f * 255),256)) + "," + Int(Mod(Abs(Vert.f * 255),256)) + "," + Int(Mod(Abs(Bleu.f * 255),256)) + "," + Int(Mod(Abs(Alpha.f * 255),256)), RGB(40, 40, 255), RGB(240, 240, 240))
  DrawText(10, 228 , "CTRL   Clavier  = R,V,B,A, = -", #Black, RGB(240, 240, 240))
  DrawText(10, 243 , "SHIFT  Clavier  = R,V,B,A, = +", #Black, RGB(240, 240, 240))
  DrawText(10, 258 , "Couleur Clavier = R,V,B,A" , #Black, RGB(240, 240, 240))
  DrawText(10, 273 , "PageHaut / PageBas = Zoom", #Black, RGB(240, 240, 240))
  DrawText(10, 288 , "Fleche Right = X + / Left    = X - ", #Black, RGB(240, 240, 240))
  DrawText(10, 303 , "Fleche UP     = Y +/ Down = Y - ", #Black, RGB(240, 240, 240))
  StopDrawing()
EndProcedure

Procedure HandleError (Result, Text$)
  If Result = 0
    MessageRequester("Error", Text$, 0)
    End
  EndIf
EndProcedure

OpenWindow(0, 0, 0, 530, 320, "OpenGL Gadget.. PageUp/pageDown to zoom & arrow keys X/Y +/- Esc to exit", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenGLGadget(0, 10, 10, 200, 200, #PB_OpenGL_Keyboard )
SetupGL()

OpenGLGadget(1, 220, 10, 300, 300)
SetupGL()

AddWindowTimer(0, 1, 16) ; about 60 fps
SetActiveGadget(0)

Repeat
  
  Event = WaitWindowEvent()
  
  
  Select Event
    Case #PB_Event_Timer
      If EventTimer() = 1
        DrawCube(0)
        DrawCube(1)
      EndIf
  EndSelect
  
  If EventType() = #PB_EventType_KeyDown Or EventType() = #PB_EventType_KeyUp
    
    Keyf = GetGadgetAttribute(0, #PB_OpenGL_Modifiers)
    key  = GetGadgetAttribute(0, #PB_OpenGL_Key )
    
    
    If    GetGadgetAttribute (0, #PB_OpenGL_Modifiers) = #PB_OpenGL_Control : Debug "controle"
      
      If  GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_R
        Rouge = Rouge - 0.003  : If rouge < 0 : rouge = 0: EndIf : Debug "Controle R= " + Rouge                   ; controle + R = couleur Rouge moins
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_V
        Vert  = Vert  - 0.003  : If Vert  < 0 : Vert  = 0: EndIf : Debug "Controle V= " + Vert                    ; controle + V = couleur vert moins
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_B
        Bleu  = Bleu  - 0.003  : If Bleu  < 0 : Bleu  = 0: EndIf : Debug "Controle B= " + Bleu                    ; controle + B = couleur Bleu moins
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_A
        Alpha = Alpha - 0.003  : If Alpha < 0 : Alpha = 0: EndIf : Debug "Controle A= " + Alpha                   ; controle + A = couleur alpha moins
      EndIf
      
    ElseIf  GetGadgetAttribute (0, #PB_OpenGL_Modifiers) = #PB_OpenGL_Shift :  Debug "Shift"
      
      If    GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_R
        Rouge = Rouge + 0.003  : If rouge > 1 : rouge = 1 : EndIf : Debug "Shift R= " + Rouge                      ; Shift + R = couleur Rouge plus
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_V
        Vert  = Vert  + 0.003  : If Vert  > 1 : Vert  = 1 : EndIf : Debug "Shift  V= " + Vert                      ; Shift + V = couleur Vert plus
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_B
        Bleu  = Bleu  + 0.003 : If Bleu  > 1 : Bleu  = 1 : EndIf : Debug "Shift  B= " + Bleu                      ; Shift + B = couleur Bleu plus
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_A
        Alpha = Alpha + 0.003  : If Alpha > 1 : Alpha = 1 : EndIf : Debug "Shift  A= " + Alpha                     ; Shift + A = couleur Alpha plus
      EndIf  
      
    Else
      
      If    GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_R
        Rouge = 1 : Vert = 0 : Bleu = 0  : Alpha = 1 : Debug "R = " + Rouge + ", " + Vert + ", " + Bleu
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_V
        Rouge = 0 : Vert = 1 : Bleu = 0  : Alpha = 1 : Debug "V = " + Rouge + ", " + Vert + ", " + Bleu
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_B
        Rouge = 0 : Vert = 0 : Bleu = 1  : Alpha = 1 : Debug "B = " + Rouge + ", " + Vert + ", " + Bleu
      ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_A
        Alpha = 1                                    : Debug "A = " + Alpha                             
      EndIf
      
    EndIf
    
    If GetGadgetAttribute (0, #PB_OpenGL_Key) =  #PB_Shortcut_Right       ; Right arrow cube à droite
      MoveX.f + 0.02
    ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) =  #PB_Shortcut_Left    ; Left  arrow cube à gauche
      MoveX.f - 0.02
    EndIf
    If GetGadgetAttribute (0, #PB_OpenGL_Key) =   #PB_Shortcut_Up         ; UP arrow   move cube en haut
      MoveY.f + 0.02
    ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) =   #PB_Shortcut_Down   ; down arrow move cube en bas
      MoveY.f - 0.02
    EndIf
    If GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_PageUp       ; PageUP arrow Zoom vue avant
      ZoomFactor.f + 0.1
    ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_PageDown ; PageDown arrow Zoom vue arrière
      ZoomFactor.f - 0.1
    ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_Escape   ;  Esc key to exit
      quit = 1
    EndIf                   
  EndIf
  
  Titre()
  Delay(2)
Until key = #PB_Shortcut_Escape Or Event = #PB_Event_CloseWindow Or quit = 1



Code Mode : Select, Case

Code : Tout sélectionner

;https://www.purebasic.fr/english/viewtopic.php?f=36&t=60039
;
; OpenGL Gadget demonstration
;
; (c) Fantaisie Software
;
; Axis explainations:
;
;             +
;             y
;
;             |
;             |
;  +          |
;  x ---------\
;              \
;               \
;                \
;                  z+
;
; So a rotate on the y axis will take the y axis as center. With OpenGL, we can specify
; positive And negative value. Positive values are always in the same sens as the axis
; (like described on the schmatic, with '+' signs)
;

Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f = 1.0
Global RotateSpeedY.f
Global RotateSpeedZ.f = 1.0

Global ZoomFactor.f = 1.0 ; Distance of the camera. Negative value = zoom back
Global MoveX.f = 0        ; Distance of the camera. Negative value = Movex
Global MoveY.f = 0        ; Distance of the camera. Negative value = Movey
Global Rouge.f = 0        ;  couleur rouge
Global Vert.f = 0         ;  couleur rouge
Global Bleu.f = 1         ;  couleur rouge
Global Alpha.f = 1        ;  couleur rouge


Procedure DrawCube(Gadget)
  SetGadgetAttribute(Gadget, #PB_OpenGL_SetContext, #True)
  
  glPushMatrix_()                  ; Save the original Matrix coordinates
  glMatrixMode_(#GL_MODELVIEW)
  
  glTranslatef_(MoveX, MoveY, ZoomFactor)  ;  move it forward a bit
  
  
  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
  
  RollAxisX + RotateSpeedX
  RollAxisY + RotateSpeedY
  RollAxisZ + RotateSpeedZ
  
  ; clear framebuffer And depth-buffer
  
  glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  
  ; draw the faces of a cube
  
  ; draw colored faces
  
  glDisable_(#GL_LIGHTING)
  glBegin_  (#GL_QUADS)
  
  ; Build a face, composed of 4 vertex !
  ; glBegin() specify how the vertexes are considered. Here a group of
  ; 4 vertexes (GL_QUADS) form a rectangular surface.
  
  ; Now, the color stuff: It's r,v,b but with float values which
  ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity)
  
  glNormal3f_ (0,0,1.0)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (0.5,0.5,0.5)   
  glColor3f_  (0,1.0,1.0)         
  glVertex3f_ (-0.5,0.5,0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (-0.5,-0.5,0.5)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (0.5,-0.5,0.5)
  
  ; The other face is the same than the previous one
  ; except the colour which is nice blue To white gradiant
  
  glNormal3f_ (0,0,-1.0)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glColor4f_  (rouge,vert,bleu,Alpha)
  glVertex3f_ (-0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,-0.5,-0.5)
  
  glEnd_()
  
  ; draw shaded faces
  
  glEnable_(#GL_LIGHTING)
  glEnable_(#GL_LIGHT0)
  glBegin_ (#GL_QUADS)
  
  glNormal3f_ (   0, 1.0,   0)
  glVertex3f_ ( 0.5, 0.5, 0.5)
  glVertex3f_ ( 0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  
  glNormal3f_ (0,-1.0,0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (-0.5,-0.5,0.5)
  
  glNormal3f_ (1.0,0,0)
  glVertex3f_ (0.5,0.5,0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,0.5,-0.5)
  
  glNormal3f_ (-1.0,   0,   0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (-0.5,-0.5, 0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  
  glEnd_()
  
  glPopMatrix_()
  glFinish_()
  
  SetGadgetAttribute(Gadget, #PB_OpenGL_FlipBuffers, #True)
EndProcedure


Procedure SetupGL()
  
  glMatrixMode_(#GL_PROJECTION)
  gluPerspective_(30.0, 200/200, 1.0, 50)
  
  ; position viewer
  glMatrixMode_(#GL_MODELVIEW)
  
  glTranslatef_(0, 0, -5.0)
  
  glEnable_(#GL_DEPTH_TEST)   ; Enabled, it slowdown a lot the rendering. It's to be sure than the
                              ; rendered objects are inside the z-buffer.
  
  glEnable_(#GL_CULL_FACE)    ; This will enhance the rendering speed as all the back face will be
                              ; ignored. This works only with CLOSED objects like a cube... Singles
                              ; planes surfaces will be visibles only on one side.
  
  glShadeModel_(#GL_SMOOTH)
  
  glEnable_(#GL_BLEND)
  glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
  
EndProcedure

Procedure Titre()  
  StartDrawing(WindowOutput(0))
  DrawText(10, 212 , Space(50), RGB(240, 240, 240), RGB(240, 240, 240))
  DrawText(10, 212 , "Menu Couleur " + Int(Mod(Abs(Rouge.f * 255),256)) + "," + Int(Mod(Abs(Vert.f * 255),256)) + "," + Int(Mod(Abs(Bleu.f * 255),256)) + "," + Int(Mod(Abs(Alpha.f * 255),256)), RGB(40, 40, 255), RGB(240, 240, 240))
  DrawText(10, 228 , "CTRL   Clavier  = R,V,B,A, = -", #Black, RGB(240, 240, 240))
  DrawText(10, 243 , "SHIFT  Clavier  = R,V,B,A, = +", #Black, RGB(240, 240, 240))
  DrawText(10, 258 , "Couleur Clavier = R,V,B,A" , #Black, RGB(240, 240, 240))
  DrawText(10, 273 , "PageHaut / PageBas = Zoom", #Black, RGB(240, 240, 240))
  DrawText(10, 288 , "Fleche Right = X + / Left    = X - ", #Black, RGB(240, 240, 240))
  DrawText(10, 303 , "Fleche UP     = Y +/ Down = Y - ", #Black, RGB(240, 240, 240))
  StopDrawing()
EndProcedure

Procedure HandleError (Result, Text$)
  If Result = 0
    MessageRequester("Error", Text$, 0)
    End
  EndIf
EndProcedure

OpenWindow(0, 0, 0, 530, 320, "OpenGL Gadget.. PageUp/pageDown to zoom & arrow keys X/Y +/- Esc to exit", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenGLGadget(0, 10, 10, 200, 200, #PB_OpenGL_Keyboard )
SetupGL()

OpenGLGadget(1, 220, 10, 300, 300)
SetupGL()

AddWindowTimer(0, 1, 16) ; about 60 fps
SetActiveGadget(0)

Repeat
  Event = WindowEvent()
  
  Select Event
      
    Case #PB_Event_Timer
      If EventTimer() = 1
        DrawCube(0)
        DrawCube(1)
      EndIf
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0                         ; Canvas gadget
          Select EventType()
            Case #PB_EventType_MouseEnter
              SetActiveGadget(0)
              
            Case  #PB_EventType_KeyDown
              
              If GetGadgetAttribute (0, #PB_OpenGL_Modifiers) = #PB_OpenGL_Control : Debug "controle"
                
                If  GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_R
                  Rouge = Rouge - 0.003  : If rouge < 0 : rouge = 0: EndIf : Debug "Controle R= " + Rouge                   ; controle + R = couleur Rouge moins
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_V
                  Vert  = Vert  - 0.003  : If Vert  < 0 : Vert  = 0: EndIf : Debug "Controle V= " + Vert                    ; controle + V = couleur vert moins
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_B
                  Bleu  = Bleu  - 0.003  : If Bleu  < 0 : Bleu  = 0: EndIf : Debug "Controle B= " + Bleu                    ; controle + B = couleur Bleu moins
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_A
                  Alpha = Alpha - 0.003  : If Alpha < 0 : Alpha = 0: EndIf : Debug "Controle A= " + Alpha                   ; controle + A = couleur alpha moins
                EndIf
                
              ElseIf  GetGadgetAttribute (0, #PB_OpenGL_Modifiers) = #PB_OpenGL_Shift :  Debug "Shift"
                
                If    GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_R
                  Rouge = Rouge + 0.003  : If rouge > 1 : rouge = 1 : EndIf : Debug "Shift R= " + Rouge                      ; Shift + R = couleur Rouge plus
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_V
                  Vert  = Vert  + 0.003  : If Vert  > 1 : Vert  = 1 : EndIf : Debug "Shift  V= " + Vert                      ; Shift + V = couleur Vert plus
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_B
                  Bleu  = Bleu  + 0.003 : If Bleu  > 1 : Bleu  = 1 : EndIf : Debug "Shift  B= " + Bleu                      ; Shift + B = couleur Bleu plus
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key)  = #PB_Shortcut_A
                  Alpha = Alpha + 0.003  : If Alpha > 1 : Alpha = 1 : EndIf : Debug "Shift  A= " + Alpha                     ; Shift + A = couleur Alpha plus
                EndIf  
                
              Else
                
                If    GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_R
                  Rouge = 1 : Vert = 0 : Bleu = 0  : Alpha = 1 : Debug "R = " + Rouge + ", " + Vert + ", " + Bleu
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_V
                  Rouge = 0 : Vert = 1 : Bleu = 0  : Alpha = 1 : Debug "V = " + Rouge + ", " + Vert + ", " + Bleu
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_B
                  Rouge = 0 : Vert = 0 : Bleu = 1  : Alpha = 1 : Debug "B = " + Rouge + ", " + Vert + ", " + Bleu
                ElseIf GetGadgetAttribute (0, #PB_OpenGL_Key) = #PB_Shortcut_A
                  Alpha = 1                                    : Debug "A = " + Alpha                             
                EndIf
              EndIf
              
              If GetGadgetAttribute (0,  #PB_OpenGL_Key) =  #PB_Shortcut_Right
                MoveX.f + 0.02
              ElseIf GetGadgetAttribute (0,  #PB_OpenGL_Key) =  #PB_Shortcut_Left
                MoveX.f - 0.02
              EndIf
              If GetGadgetAttribute (0,  #PB_OpenGL_Key) =   #PB_Shortcut_Up
                MoveY.f + 0.02
              ElseIf GetGadgetAttribute (0,  #PB_OpenGL_Key) =   #PB_Shortcut_Down
                MoveY.f - 0.02
              EndIf
              If GetGadgetAttribute (0,  #PB_OpenGL_Key) = #PB_Shortcut_PageUp       ; UP arrow page key
                ZoomFactor.f + 0.1
              ElseIf GetGadgetAttribute (0,  #PB_OpenGL_Key) = #PB_Shortcut_PageDown ; Down arrow page key
                ZoomFactor.f - 0.1
              ElseIf GetGadgetAttribute (0,  #PB_OpenGL_Key) = #PB_Shortcut_Escape ;  Esc key to exit
                quit = 1
              EndIf                   
          EndSelect
      EndSelect
  EndSelect
  Titre()
  Delay(2)
Until key = #PB_Shortcut_Escape Or Event = #PB_Event_CloseWindow Or quit = 1
Répondre