Voir là également
http://nehe.developpez.com/tutoriel/01-introduction/
OpenGL - Tutoriaux - 22 leçons !
Une gestion plus efficace du clavier. Il suffit simplement de remplacer le tableau Global Keys.b(256) par une variable structurée Global Keyboard.Keyboard
Et de remplacer la section suivante dans la Procédure WinProc()
par celle-ci
Ensuite dans la boucle de gestion de choisir l'action approprié pour ce que l'on veut faire. Exemple lancer un action lorsque l'on appui ou lorsque l'on relâche un bouton.
J'ai fait aucun test poussé mais je pense qu'il est plus prudent de faire comme suit :
A+
Guimauve
Code : Tout sélectionner
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; CODE GÉNÉRÉ AUTOMATIQUEMENT, NE PAS MODIFIER À
; MOINS D'AVOIR UNE RAISON TRÈS TRÈS VALABLE !!!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Code généré par : Dev-Type
; Nom du projet : NeHe - OpenGL tutorial
; Fichier : OpenGL - KeyBoard.pb
; Version : 1.0.1
; Programmation : OK
; Programmé par : Guimauve
; Date : 25-09-2007
; Mise à jour : 28-09-2007
; Codé pour PureBasic V4.10
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<
Structure KeyBoard
ButtonDown.b[257]
ButtonUp.b[257]
EndStructure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les Macros d'accès <<<<<
Macro KeyBoardButtonDown(KeyBoardA, Index)
KeyBoardA\ButtonDown[Index]
EndMacro
Macro KeyBoardButtonUp(KeyBoardA, Index)
KeyBoardA\ButtonUp[Index]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<
Macro SetKeyBoardButtonDown(KeyBoardA, Index, P_ButtonDown)
KeyBoardA\ButtonDown[Index] = P_ButtonDown
EndMacro
Macro SetKeyBoardButtonUp(KeyBoardA, Index, P_ButtonUp)
KeyBoardA\ButtonUp[Index] = P_ButtonUp
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<
Macro GetKeyBoardButtonDown(KeyBoardA, Index)
KeyBoardA\ButtonDown[Index]
EndMacro
Macro GetKeyBoardButtonUp(KeyBoardA, Index)
KeyBoardA\ButtonUp[Index]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset complet <<<<<
Macro ResetKeyBoard(KeyBoardA)
For Index = 0 To 256
SetKeyBoardButtonDown(KeyBoardA, Index, 0)
SetKeyBoardButtonUp(KeyBoardA, Index, 0)
Next
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code généré en : 00.015 secondes <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Code : Tout sélectionner
Case #WM_KEYDOWN ;Is A Key Being Held Down?
keys(wParam)=#True ;If So, Mark It As TRUE
ProcedureReturn 0 ;Jump Back
Case #WM_KEYUP ;Has A Key Been Released?
keys(wParam)=#False ;If So, Mark It As FALSE
ProcedureReturn 0 ;Jump Back
Code : Tout sélectionner
Case #WM_KEYDOWN
SetKeyBoardButtonDown(KeyBoard, wParam, #True)
SetKeyBoardButtonUp(KeyBoard, wParam, #False)
ProcedureReturn 0
Case #WM_KEYUP
SetKeyBoardButtonDown(KeyBoard, wParam, #False)
SetKeyBoardButtonUp(KeyBoard, wParam, #True)
ProcedureReturn 0
J'ai fait aucun test poussé mais je pense qu'il est plus prudent de faire comme suit :
Code : Tout sélectionner
If GetKeyBoardButtonUp(KeyBoard, #VK_ESCAPE)
SetKeyBoardButtonUp(KeyBoard, #VK_ESCAPE, #False)
Exit = #True
EndIf
Guimauve