Texte sur du openGL

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

Re: Texte sur du openGL

Message par kernadec »

bjr SPH
Comme il me semble que mon code précédent ne fonctionne pas sur toutes les machines :?:

Donc voilà, j'ai revu ma copie pour afficher les textes sur l' OpenGLGadget
en adaptant les procédures d' "appelPI" dans mon précédent code
ce code tourne bien chez moi, mais comme mes ordis ne font pas référence, donc, bonne chance chez vous :mrgreen:
j' espère que ce code fonctionnera sur beaucoup de configurations Windows :D
Cordialement

ps: j'ajoute ce lien : https://cpp.hotexamples.com/fr/ car sur celui-ci
en utilisant la recherche pour OpengGL
ce qui est intéressant, c'est que les codes C++ sont proche de la syntaxe PB pour l' OpenGLGadget()
donc facile a transposer :D

Code : Tout sélectionner


EnableExplicit

Enumeration
  #Windows
  #Openglgadget
EndEnumeration

#fond = 0                                                        ; couleur de fond de la fenetre
#ligne = 20                                                      ; Taille format saut de ligne avec Drawtext
#DecaleText_X = 300                                              ; valeur de la position X du texte sur OpengelGadget
#DecaleText_Y = 28                                               ; valeur de la position Y du texte sur OpengelGadget
#DecaleTitre_X = 400                                             ; valeur de la position X du Titre sur la Fenetre 0
#DecaleTitre_Y = 12                                              ; valeur de la position Y du texte sur la Fenetre 0

Global Event.i, EventMenu.i, Rouge.i, Vert.i, Bleu.i, Alpha.i, i.i, menux.s, n.i, quit.i, KeyPause.i, KeySortie.i, fond.i

Global Dim keys.b(256)                                           ; Array Used For The Keyboard Routine
Global base.l                                                    ; Base Display List For The Font Set
Global Dim paragraph$(30)                                        ; Array menu

;{;-- ; Déclaration des Procédures
;--  Déclaration des procédures 
Declare Pause_Key(KeyPause.i)
Declare Standby_to_See()
;};--


ExamineDesktops()                                                ; taille ecran
OpenWindow(#Windows, 0, 0, DesktopWidth(0),DesktopHeight(0), "",  #PB_Window_Maximize|#PB_Window_BorderLess)
SetWindowColor(#Windows, #Black)
OpenGLGadget(#Openglgadget, 0, 0,  DesktopWidth(0),DesktopHeight(0), #PB_OpenGL_Keyboard)
; OpenGLGadget(#Openglgadget, 0, 28,  DesktopWidth(0),DesktopHeight(0)-28, #PB_OpenGL_Keyboard)  ; Option de decalage Y de 28 pixels pour la fenetre OpenGL utilisé avec procédure Titre()

#ANTIALIASED_QUALITY=4                                           ; for CreateFont_()



AddKeyboardShortcut(#Windows, #PB_Shortcut_Escape, 27)  ;  27 = Valeur Touche Escape
AddKeyboardShortcut(#Windows, #PB_Shortcut_Space, 32)   ;  32 = Valeur Touche Espace
AddKeyboardShortcut(#Windows, #PB_Shortcut_W, 119)      ; 119 = Valeur Touche w

Restore Menu_Polygone_fr:
While menux <> "-8888"                                           ; Chargement datas liste des commandes menu polygones
  n = n + 1
  Read.s menux : paragraph$(n) = menux
  If  paragraph$(n) = "-8888"
    paragraph$(n) = ""
  EndIf
Wend

Procedure BuildFont(nomfont.s,height.l,bold.l,italic.b,symbol.l) ; Build Our Bitmap Font   
                                                                 ; Procédure appelPI forum english
  Protected hDC                                                  ; BuildFont("Courier New",24,1,0,0) ;Build The Font
  Protected font.l                                               ; Windows Font ID
  Protected oldfont.l                                            ; Used For Good House Keeping
  
  If bold : bold=#FW_BOLD : Else : bold=#FW_NORMAL : EndIf       ; font weight
  If symbol : symbol=#SYMBOL_CHARSET : Else : symbol=#ANSI_CHARSET : EndIf ;character set
  
  base = glGenLists_(96)                                         ; Storage For 96 Characters
  
  font = CreateFont_(-height,0,0,0,bold,italic,#False,#False,symbol,#OUT_TT_PRECIS,#CLIP_DEFAULT_PRECIS,#ANTIALIASED_QUALITY,#FF_DONTCARE | #DEFAULT_PITCH,nomfont)
  
  hDC = GetDC_(WindowID(#Windows))
  oldfont=SelectObject_(hDC, font)                               ; Selects The Font We Want
  wglUseFontBitmaps_(hDC, 32, 96, base)                          ; Builds 96 Characters Starting At Character 32
  SelectObject_(hDC, oldfont)                                    ; reselect the old font again
  DeleteObject_(font)                                            ; Delete The Font
  
EndProcedure

Procedure KillFont()                                             ; Delete The Font List
                                                                 ; Procéduere appelPI forum english
  glDeleteLists_(base,96)                                        ; Delete All 96 Characters
  
EndProcedure

Procedure glPrint(text.s)                                        ; Custom GL "Print" Routine
                                                                 ; Procéduere appelPI forum english
  If text=""                                                     ; If There's No Text
    ProcedureReturn #False                                       ; Do Nothing
  EndIf
  
  glPushAttrib_(#GL_LIST_BIT)                                    ; Pushes The Display List Bits
  glListBase_(base-32)                                           ; Sets The Base Character to 32
  glCallLists_(Len(text),#GL_UNSIGNED_BYTE,text)                 ; Draws The Display List Text
  glPopAttrib_()                                                 ; Pops The Display List Bits
  
EndProcedure

Procedure Opengl_texte_tableau(mode_affichage.l)
  
  If mode_affichage = 0                                          ; mose affichage = 0 = OpenGL /  1 = Windows
    
    glTranslatef_(0, 0, - 0.5)
    glColor4f_(1, 1, 1, 1)
    
    For i= 1 To 21
      glRasterPos2f_(0.75 , 1.46 - (0.05 * i))
      glColor4f_(1, 1, 1, 1)
      glPrint(paragraph$(i) + Space(42))                          ; Ajouter autant d'espace que de caracteres     Print GL Text To The Screen
    Next i
    
    SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)    ; pour affichage du menu sous OpenGL
    Delay(25)
    
  Else
    
    StartDrawing(WindowOutput(#Windows))
    ; Box(WindowWidth(0) - #DecaleText_X, WindowX(0) +  #DecaleText_Y-1, 265, #ligne * 21 ,  RGBA(0,0,0,1))   ; effface menu texte ebarre espace test : #red
    For i = 0 To 20
      DrawText(WindowWidth(#Windows) - #DecaleText_X, WindowX(#Windows) +  #DecaleText_Y - #ligne + #ligne * i  ,paragraph$(i) , #White , RGBA(0,0,0,1))
    Next i
    StopDrawing()
    
  EndIf
  
EndProcedure


Procedure opengltext()
  
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  
  glOrtho_(-2,2,-2,2,-2,2)                                       ; position du texte
  gluPerspective_(75.0, 1, 0.1, 100.0)                           ; essential to see the text
  glMatrixMode_(#GL_MODELVIEW)                                   ;
                                                                 ;----------------------------------------------
  glLoadIdentity_()
  
  glTranslatef_(0, 0, - 0.5)
  
  glColor4f_(0, 1, 0, 1)
  
  glRasterPos2f_(0.20, 0.73)                                                                 ; position x,y ecran
  glPrint("RGBA(" + Rouge + ", " + Vert+ ", " + Bleu + ", " + Alpha + ")" +  Space(20))      ; Ajouter autant d'espace que de caracteres     Print GL Text To The Screen
  
  glRasterPos2f_(0.35, 0.73)                                                                 ; position x,y ecran
  glPrint("Menu Aide : OpenGL = Espace / Windows = W : oui/non" + Space(50))                 ; Ajouter autant d'espace que de caracteres     Print GL Text To The Screen
  
  glPopMatrix_()
  Delay(10)
  
EndProcedure

;########################################################################


BuildFont("Courier New",16,1,0,0)                               ; Vers Procedure Build The Font                 écriture en mode opengl

SetActiveGadget(#OpenGLGadget)                                  ; focus OpenglGadget
quit = 0

Repeat
  
  event = WindowEvent()
  
  opengltext()                                                   ; affichage bande titre mode texte sous OpenGL                                                         
  
  SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)                                                                                     ; Flip de mise à jour qui redessine l'écran de l' OpenGLGadget
  
  opengltext()  
  Standby_to_See()
  
  
Until quit 
KillFont()

End

Procedure Pause_Key(KeyPause.i)
  Protected Event, eventmenu
  
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Menu
        EventMenu = EventMenu()
        Select EventMenu 
          Case 27                               ; Touche Escape
            End
          Case 32                               ; Touche Espace  
            KeySortie = 32                      ; stock valeur touche pour comparaison à venir                                             
            If KeyPause = KeySortie             ; Test OK si c' est la meme Touche
              Quit = #True
            EndIf
            KeySortie = 0
          Case 119                               ; Touche w 
            KeySortie = 119                      ; stock valeur touche pour comparaison à venir        
            If KeyPause = KeySortie              ; Test OK si c' est la meme Touche
              Quit = #True
            EndIf
            KeySortie = 0
        EndSelect
    EndSelect
    
  Until Quit Or Event = #PB_Event_CloseWindow
  Quit = #False
  KeySortie = 0
  
EndProcedure

Procedure Standby_to_See()
  Protected Event, eventmenu
  Quit = #False   
  
  Repeat
    Event = WaitWindowEvent()
    Select  Event
      Case #PB_Event_Menu
        EventMenu = EventMenu()
        Select EventMenu     
          Case 27                              ; Touche Escape
            End
          Case 32                              ; Touche Espace
            Opengl_texte_tableau(0)
            KeyPause = 32                       ; stock valeur touche pour comparaison à venir
            Pause_Key(KeyPause)      
            Quit = #True
            KeyPause = 0
          Case 119                             ; Touche w
            Opengl_texte_tableau(1)
            KeyPause = 119                      ; stock valeur touche pour comparaison à venir
            Pause_Key(KeyPause)
            Quit = #True
            KeyPause = 0
            SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)     ; Flip de mise à jour qui redessine l'écran de l' OpenGLGadget
           ;Delay(2)   
        EndSelect
    EndSelect
    
  Until Quit Or Event = #PB_Event_CloseWindow
  Quit = #False
  KeyPause = 0
  
EndProcedure


DataSection
  Menu_Polygone_fr:
  Data.s "' 1 >< 2 ' = Rouge   + 0.01 /  Rouge  - 0.01"     
  Data.s  "' 3 >< 4 ' = Vert    + 0.01 /  Vert   - 0.01"
  Data.s "' 5 >< 6 ' = Bleu    + 0.01 /  Bleu   - 0.01"
  Data.s  "' + >< - ' =  Alpha  + 0.01 /  Alpha  - 0.01"
  Data.s "' 7 ' = Rouge 0.5  "                             
  Data.s "' 8 ' = Vert    0.5  "                           
  Data.s "' 9 ' = Bleu   0.5  "                           
  Data.s "' * ><  /  ' =  Alpha  /  NO Alpha"             
  Data.s "' p ' = Piquer Couleur sur image de Fond"       
  Data.s "' h ' = Active/Desactive dernier 'Triangle'"   
  Data.s "' m ' = Model ON/OFF"                         
  Data.s "' k ' = Kill le dernier Polygone"               
  Data.s "' i ' = Afficher l'image de fond"               
  Data.s "' c ' = Continuer sur un Model"                 
  Data.s "' z ' = Zoom ON/OFF"                           
  Data.s "' a ' = Tout mettre en Alpha ON/OFF"           
  Data.s "' F1 ' = Couleur précédente en memoire"       
  Data.s "' F2 ' = Couleur suivante en memoire"           
  Data.s "' F3 ' = Model précédent"                       
  Data.s "' F4 ' = Model suivant"                         
  Data.s "' F5 ' = Sauve les polygones" 
  Data.s "-8888"
EndDataSection
Dernière modification par kernadec le lun. 14/déc./2020 23:11, modifié 7 fois.
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Re: Texte sur du openGL

Message par SPH »

Bon, je ne vois que :

Code : Tout sélectionner

glRasterPos2f_(0.35, 0.73)
  glPrint("RGBA(" + Rouge + ", " + Vert+ ", " + Bleu + ", " + Alpha + ")" +  Space(20))      ; Ajout autant d'espace que de caractere     Print GL Text To The Screen
 
  glRasterPos2f_(0.53, 0.73)
  glPrint("Aide touche Espace oui/non" + Space(28))                                          ; Ajout autant d'espace que de caractere     Print GL Text To The Screen
Mais c'est une bonne chose car apparement, cette phrase s'affiche bien. On peux la mettre n'importe où :

Code : Tout sélectionner

  glOrtho_(-2,10,-2,10,-2,10)             ; position du texte
Je vais donc bricoler avec ca...

(pour ce bug, peut etre faut il voir avec Fred !)

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

Re: Texte sur du openGL

Message par kernadec »

Ah aaaggrr :idea: code précédent mis à jour

avec ce code dans la procédure OpenglText()
active la procédure commentée ; Opengl_texte_tableau()
et tu auras la liste direct dans OpenGLGadget
tu devrais pouvoir gérer le oui:non avec un "select" "case" sans problème :mrgreen:

je ne sais pas si c'est un bug :?:
cordialement
Avatar de l’utilisateur
Zorro
Messages : 2186
Inscription : mar. 31/mai/2016 9:06

Re: Texte sur du openGL

Message par Zorro »

avec ton dernier code , a present je vois la ligne :

Image

mais les touches R, ctrl+R ou bien Espace , ne font rien !

(I7 ,GTX1060 , 32go Ram )
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Re: Texte sur du openGL

Message par SPH »

kernadec a écrit :Ah aaaggrr :idea: code précédent mis à jour

avec ce code dans la procédure OpenglText()
active la procédure commentée ; Opengl_texte_tableau()
Dernier code avec Opengl_texte_tableau() decommenté : ca marche enfin (mais peut etre pas chez zorro. Attendons son retour pour en conclure à un bug) :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

Re: Texte sur du openGL

Message par kernadec »

Bjr Zorro
Eh ben j avoue que je comprend pas ce qui se passe
Car quand on regarde la doc d OpenGLGadget c est
ce qui est preconise avec eventtype()
Sinon ya un truc que j ai oublie :?: :mrgreen:

Cordialement
Avatar de l’utilisateur
falsam
Messages : 7317
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Texte sur du openGL

Message par falsam »

Une autre méthode serait de traiter le texte dans une image puis d'afficher cette image avec OpenGL.

glDrawtext(x.f, y.f, Text.s, Font, Color = $FFEEF5FF)

Les paramètres sont évidents je pense.

Attention à la couleur qui doit être au format RGBA.

Le code est largement documenté. J'affiche un polygone pour faire plaisir à SPH puis un texte et un compteur incrémentiel qui sert à rien.

Code : Tout sélectionner

EnableExplicit

Global Scene, ww = 800, wh = 600

Global Font0, Font1

; Plan de l'application
Declare Start()
Declare Render()
Declare Exit()

Start()

; Texte affiché sur une image RGBA
Procedure glDrawtext(x.f, y.f, Text.s, Font, Color = $FFEEF5FF)
  Protected Tmp = CreateImage(#PB_Any, 1, 1, 32, #PB_Image_Transparent) 
  Protected iw, ih        ; Largeur auteur de l'image
  Protected DrawingBuffer ; Pointeur de données de l'image
  
  Protected TextureID = 0 ; Il restera unique
  
  ; Préparation de l'image format RGBA au dimension du texte
  ; Déterminer les dimensions du texte à afficher (iw & ih)
  StartDrawing(ImageOutput(tmp))
  DrawingFont(FontID(Font))
  iw = TextWidth(Text)
  ih = TextHeight(Text)  
  StopDrawing()
  
  ; On connait maintenant les dimensions du texte (iw & ih)
  ; Création de l'image 
  ResizeImage(tmp, iw, ih)
  
  StartDrawing(ImageOutput(tmp))
  DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
  DrawingFont(FontID(Font)) 
  DrawText(0, 0, Text, Color, RGBA(0, 0, 0, 0))
  DrawingBuffer = DrawingBuffer() ;Récupération adresse mémoire de l'image
  StopDrawing()
  
  ; Préparation de la texture OpenGL
  glEnable_(#GL_TEXTURE_2D)
  
  ; Selection de la texture
  glBindTexture_(#GL_TEXTURE_2D, TextureID)
  
  ; Méthode de placage 
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
  glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
  
  ; Création de la texture
  glTexImage2D_(#GL_TEXTURE_2D, 0, 4, iw, ih, 0, #GL_BGRA_EXT, #GL_UNSIGNED_BYTE, DrawingBuffer)
  
  ; La texture est prete. On a plus besoin de l'image
  FreeImage(tmp)
  
  ; Modelisation texture  
  glMatrixMode_(#GL_TEXTURE)
  glLoadIdentity_()
  glPushMatrix_()
  
  ; Le coin 0,0 étnt en bas à droite de l'image, Flip vertical de la texture
  glScalef_(1, -1, 0)       
  
  ; Modelisation de la texture   
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
  glPushMatrix_()
  
  ; Reset couleur
  glColor4f_(255, 255, 255, 255)
  
  ; Dessin 
  glBegin_(#GL_QUADS)
  
  ; Coin haut gauche 
  glTexCoord2f_(0, 0) : glVertex2i_(x, y)
  
  ; Coin haut droit
  glTexCoord2f_(1, 0) : glVertex2i_(x + iw, y)
  
  ; Coin bas droit
  glTexCoord2f_(1, 1) : glVertex2i_(x + iw, y + ih)
  
  ; Coin bas gauche 
  glTexCoord2f_(0, 1) : glVertex2i_(x, y + ih) 
  
  glEnd_()  
  
  glPopMatrix_()
  
  glDisable_(#GL_TEXTURE_2D)
EndProcedure

;-
Procedure Start() 
  ; Chargement des fonts d'affichage du texte 
  Font0 = LoadFont(#PB_Any, "Arial", 25)
  Font1 = LoadFont(#PB_Any, "Arial", 15)
  
  OpenWindow(#PB_Any, 0, 0, ww, wh, "OpenGL : Création d'une scene", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  
  ; Fenetre openGl
  Scene = OpenGLGadget(#PB_Any, 0, 0, ww, wh, #PB_OpenGL_Keyboard)
  
  ; Activation textures et transparence
  glEnable_(#GL_BLEND)
  glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
  
  ; Couleur d'arrière plan
  ; Chaque composant RGBA est divisé par 255
  glClearColor_(0.5, 0.5, 0.5, 1.0) 
  
  ; Sélectionner la pile des matrices de projection 
  glMatrixMode_(#GL_PROJECTION)
  
  ; Ré-initialise la matrice de projection 
  ; et assure ainsi qu’une seule projection soit effectuée.
  glLoadIdentity_()
  
  ; glOrtho_(gauche, droit, bas, haut, proche, loin);
  glOrtho_(0, ww, wh, 0, -1, 1)
  glDisable_(#GL_DEPTH_TEST)
  
  glMatrixMode_(#GL_MODELVIEW);
  glLoadIdentity_()
  
  ; Déclencheur  
  BindEvent(#PB_Event_CloseWindow, @Exit())
  
  ; Boucle de rendu visuel
  Render()
EndProcedure

; Visualisation du résultat
Procedure Render()  
  Static N
  
  Repeat
    
    ; Efface le frame buffer et le Z-buffer
    glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
    
    ; Un peu de polygone pour SPH ;)
    glColor4f_(1, 0, 0, 1)
    glBegin_(#GL_POLYGON)
    glVertex2f_(300, 10)
    glVertex2f_(500, 10)
    glVertex2f_(400, 200)
    glEnd_()   
    
    ; Affichage d'un titre
    glDrawtext(10, 10, "Texte sur un OpenGLGadget", Font0, RGBA(255, 255, 255, 255))
    
    ; Dessin d'un compteur
    glDrawtext(10, 100, "Compteur", Font1, RGBA(255, 255, 255, 255))
    glDrawtext(130, 100, Str(N), Font1, RGBA(227, 139, 226, 255))
    
    ; Compteur + 1
    N + 1
    
    ; FlipBuffers
    SetGadgetAttribute(Scene, #PB_OpenGL_FlipBuffers, #True)
    
  Until WindowEvent() = #PB_Event_CloseWindow
EndProcedure

Procedure Exit()  
  End
EndProcedure
:arrow: La technique étant basé sur une texture unique, il ne sera pas possible d'effectuer une rotation de texte.

:idea: Une astuce. Pour une utilisation 2D La fonction gluOrtho2D_() est suffisante
Remplacer

Code : Tout sélectionner

glOrtho_(0, ww, wh, 0, -1, 1)
par

Code : Tout sélectionner

gluOrtho2D_(0, ww, wh, 0)
Source https://www.khronos.org/registry/OpenGL ... rtho2D.xml
Configuration : Windows 11 Famille 64-bit - PB 6.20 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4937
Inscription : mer. 09/nov./2005 9:53

Re: Texte sur du openGL

Message par SPH »

La, ca maaaaarche :idea:

Merci a vous 2 pour vous êtes pris la tête sur ce code :wink:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.12LTS- 64 bits
Avatar de l’utilisateur
Zorro
Messages : 2186
Inscription : mar. 31/mai/2016 9:06

Re: Texte sur du openGL

Message par Zorro »

je confirme, le code de Falsam fonctionne chez moi ..
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

Re: Texte sur du openGL

Message par kernadec »

bjr à tous
Mises à jours de mon dernier code.
Ajout d un choix pour le mode d affichage du menu : espace = OpenGL et W = Windows
un aussi stockage données data pour avoir des sections Data menus multi-langages.

c'est juste pour le fun. :wink:

@Zorro sur toutes mes machines avec mon code, la touche contrôle R fonctionne, la touche r aussi.
c'est un vrai mystère peut être que Fred jettera un coup œil à mon code
avec un peu de chance, il est peut être hors sujet :mrgreen: :mrgreen:

@falsam code intéressant, merci pour le partage
Fonctionne bien sur mes ordis récents, (enfin qui ont moins de dix ans) :D

Mais sur mon vieux Dell latitude D520 XP32 1024, 768 hors d'age qui est "Net Non Grata".
ce code à les zones textes qui apparaissent en rectangle blanc qui cache le texte
idem pour le compteur en violet lui aussi disparait sous son rectangle blanc.

Il faut dire aussi que plus personne n'utilise XP à part les vieux de mon age
habité au vieux engins. :mrgreen:

Ps: si j'ai encore mon vieux Dell c'est parce qu'il ne sors pas de chez moi
et je ne rabat jamais l'écran de ce fait la connectique n'a pas subit
l' usure due au rabat d'écran au cours du temps :wink:

cordialement
Avatar de l’utilisateur
Zorro
Messages : 2186
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
Avatar de l’utilisateur
kernadec
Messages : 1606
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