Ca alors, SPH qui poste un code !! Ca faisait longtemps...
Bon, je voudrais savoir une chose : quand on dessine (par exemple un triangle) sur un écran et qu'on swap l'écran, ce 2eme écran n'a pas ce triangle. Il faut le redessiner une fois.
Comment faire que le dessin s'applique sur les 2 écrans qui se swap ?
Code : Tout sélectionner
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code de démonstration OpenGL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; PB6.0 - SPH(2023) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;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
If ExamineDesktops()
ddw=DesktopWidth(0)
ddh=DesktopHeight(0)
Else
ddw=1024
ddh=768
EndIf
;-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, "Titre",#PB_Window_Maximize|#PB_Window_BorderLess)
If win=0
MessageRequester("Erreur","OpenWindow() impossible")
End
EndIf
screenGL=OpenGLGadget(#OpenGLGadget,0,0,ddw,ddh)
If screenGL=0
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)
;*********************************************************************************************************************************
;;;;;;;;;;;
timer=ElapsedMilliseconds()
glClearColor_(0,0,0, 1.0)
; ShowCursor_(0)
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;### D E B U T ###;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Repeat
;glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
;*****
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
End
EndSelect
EndSelect
Until Event = 0
;##############################################
;##############################################
;##############################################
;##############################################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; Traçage de vos polygones ;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
For i=1 To 1
glBegin_(#GL_POLYGON);
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glColor4f_(Random(255)/255,Random(255)/255,Random(255)/255,Random(255)/255)
For u=1 To 5
glVertex2f_(Random(ddw),Random(ddh));
Next u
glEnd_() ;
Next i
;;;;;;;;;;;;;;;
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
Delay(100)
ForEver
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