
Voici un créateur de tableaux abstraits
F1 = tracé simple
F2 = tracé miroir horizontale
F3 = tracé miroir H&V
Code : Tout sélectionner
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code de démonstration OpenGL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; PB6.0 - SPH(2022) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;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, "SPH_Tableaux_OpenGL",#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
AddKeyboardShortcut(0, #PB_Shortcut_F1, 1) ; quitter
AddKeyboardShortcut(0, #PB_Shortcut_F2, 2) ; quitter
AddKeyboardShortcut(0, #PB_Shortcut_F3, 3) ; quitter
glOrtho_(0,ddw,ddh,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(0)
;*********************************************************************************************************************************
; mirror=0
;;;;;;;;;;;
timer=ElapsedMilliseconds()-1000000
cls=-1
ShowCursor_(0)
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;### D E B U T ###;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#################;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Repeat
If ElapsedMilliseconds()-timer>25000
cls+1
cls%2
If cls=0
glClearColor_(0,0,0,0)
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
glClearColor_(0,0,0,0)
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
EndIf
; mirror=0;Random(2)
;Beep_(1500,100)
f1.f=0.4
f2.f=0.31
f3.f=0.4
f4.f=0.3
ff1.f=Random(2500)/100000+0.01
ff2.f=Random(2500)/100000+0.01
ff3.f=Random(2500)/100000+0.01
ff4.f=Random(2500)/100000+0.01
xyf1.f=Random(255)/255
xyf2.f=Random(255)/255
xyf3.f=Random(255)/255
xyf4.f=5/255
ddwx2=Random(800)-400
ddhx2=Random(800)-400
ddwy2=Random(800)-400
ddhy2=Random(800)-400
diam1=Random(1000)+50
diam2=Random(1000)+50
diam3=Random(1000)+50
diam4=Random(1000)+50
timer=ElapsedMilliseconds()
EndIf
;*****
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 1
mirror=0
Case 2
mirror=1
Case 3
mirror=2
Case 666
;timer=ElapsedMilliseconds()-timer
End
EndSelect
EndSelect
Until Event = 0
;##############################################
;##############################################
xy=20
Dim x(xy)
Dim y(xy)
For i=1 To xy/2
x(i*2-1)=ddw/2+ddwx2+Cos(f1)*diam1;(ddw/3);500
y(i*2-1)=ddh/2+ddhx2+Sin(f1)*diam2;(ddh/2);400
x(i*2)=ddw/2+ddwy2+Cos(f3)*diam3;(ddw/2);900
y(i*2)=ddh/2+ddhy2+Sin(f3)*diam4;(ddh/1);600
f1+ff1.f
; f2+ff2
f3+ff3.f
; f4+ff4
Next
For zz=1 To 2
For i=1 To xy/2
glBegin_(#GL_LINES);
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glColor4f_(xyf1,xyf2,xyf3,xyf4)
glVertex2f_(x(i*2-1),y(i*2-1));
glVertex2f_(x(i*2),y(i*2));
glEnd_() ;
;;;;;;;;;;;;;;;
If mirror=1
glBegin_(#GL_LINES);
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glColor4f_(xyf2,xyf3,xyf1,xyf4)
glVertex2f_(ddw-x(i*2-1),y(i*2-1));
glVertex2f_(ddw-x(i*2),y(i*2));
glEnd_()
EndIf
;
;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;
If mirror=2
glBegin_(#GL_LINES);
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glColor4f_(xyf3,xyf1,xyf2,xyf4)
glVertex2f_(x(i*2-1),ddh-y(i*2-1));
glVertex2f_(x(i*2),ddh-y(i*2));
glEnd_() ;
;;;;;;;;;;;;;;;
glBegin_(#GL_LINES);
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glColor4f_(xyf2,xyf1,xyf3,xyf4)
glVertex2f_(ddw-x(i*2-1),ddh-y(i*2-1));
glVertex2f_(ddw-x(i*2),ddh-y(i*2));
glEnd_()
EndIf
;
Next i
;;;;;;;;;;;;;;;
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
Next zz
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