Bon, j'ai bien regardé vos exemples. Je les comprends facilement et je sais les faire.
Mais ce que je redoutais est arrivé...
Voici une scène en polygones et un carré rouge sensé traverser l'écran. Seulement, le carré ne se déplace que quand il y a un évènement à traiter... (bougez la souris par exemple)
Le carré est à la ligne 161 à 173.
Code : Tout sélectionner
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SPH(2021) ;; Polygons_Run_4 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;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
carre_x=0
carre_y=ddh-150
;********************* DPI *********************
dpix.f=DesktopResolutionX()
dpiy.f=DesktopResolutionY()
xf.f=(1920/ddw)*dpix
yf.f=(1080/ddh)*dpiy
;**********************************************
;-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, "Polygons_Run",#PB_Window_Maximize|#PB_Window_BorderLess)
If win=0
Beep_(500,250) : Delay(150) : Beep_(500,250)
MessageRequester("Erreur","OpenWindow() impossible")
End
EndIf
screenGL=OpenGLGadget(#OpenGLGadget,0,0,ddw,ddh)
If screenGL=0
Beep_(500,250) : Delay(150) : Beep_(500,250)
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)
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
long=346
Dim poly_mx2(long)
Dim poly_my2(long)
For i=1 To long
Read.w poly_mx2(i-1)
Read.w poly_my2(i-1)
Next
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
timer=ElapsedMilliseconds()
;-MAIN REPEAT
Repeat ;- ..... Repeat
; glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
;##############################################
;##############################################
;##############################################
Event = WaitWindowEvent()
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
End
EndSelect
EndSelect
;##############################################
;##############################################
;############La bete noire en polygones :################
nb2=0
ii=0
While poly_my2(nb2)>0
ii=poly_my2(nb2)
alpha2.f=poly_mx2(nb2+4)/32767
glBegin_(#GL_POLYGON)
If alpha2=1
glBlendFunc_(#GL_SRC_ALPHA,0)
glColor4f_(poly_mx2(nb2+1)/32767,poly_mx2(nb2+2)/32767,poly_mx2(nb2+3)/32767,1)
Else
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glColor4f_(poly_mx2(nb2+1)/32767,poly_mx2(nb2+2)/32767,poly_mx2(nb2+3)/32767,alpha2)
EndIf
For i=1 To poly_my2(nb2)-5
glVertex2f_(poly_mx2(nb2+4+i)/xf.f,poly_my2(nb2+4+i)/yf.f)
Next
glEnd_()
nb2+ii
Wend
;##############################################
;##############################################
;-########Un simple carré qui essaye d'avancer :#############
alpha2.f=poly_mx2(nb2+4)/32767
glBegin_(#GL_POLYGON)
glBlendFunc_(#GL_SRC_ALPHA,0)
glColor4f_(1,0,0,1)
glVertex2f_(carre_x,carre_y)
glVertex2f_(carre_x+20,carre_y)
glVertex2f_(carre_x+20,carre_y+20)
glVertex2f_(carre_x,carre_y+20)
glEnd_()
;========================================================
carre_x+2
;=======================================================
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
ForEver
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*************************************************************** ******************************************************************
;*********************************************************************************************************************************
;************************************************************************* *******************************************************
;*********************************************************************************************************************************
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
DataSection
Data.w 24, 9, 5397, 0, 7453, 0, 11950, 0, 32767, 0, 0, 0, 0, 1079, 1919, 1079, 1919, 0, 0, 17, 4754, 0, 5140, 0, 7838, 0, 32767, 0, 253, 1079, 0, 1079, 0, 968, 66, 962, 210, 886, 211, 846, 244, 820, 263, 821, 272, 887, 332, 969, 1525, 965, 1919, 1079, 0, 13, 4754, 0, 5140, 0, 7838, 0, 32767, 0, 1810, 1079
Data.w 1919, 1079, 1918, 819, 1825, 816, 1779, 832, 1721, 899, 1528, 948, 1507, 971, 0, 10, 4626, 0, 4883, 0, 7581, 0, 32767, 0, 0, 111, 0, 0, 239, 0, 132, 46, 77, 113, 0, 9, 4626, 0, 4883, 0, 7581, 0, 32767, 0, 1919, 0, 1868, 0, 1910, 589, 1919, 591, 0, 18, 4883, 0, 6810, 0, 11179, 0, 32767, 0, 1909, 587
Data.w 1867, 0, 1626, 0, 1648, 294, 1673, 435, 1694, 549, 1687, 599, 1576, 814, 1527, 950, 1715, 898, 1779, 833, 1832, 813, 1918, 813, 0, 15, 4883, 0, 6810, 0, 11179, 0, 32767, 0, 1519, 964, 1581, 814, 1461, 846, 1312, 850, 1245, 823, 1185, 856, 710, 880, 721, 899, 482, 900, 330, 966, 0, 20, 4883, 0, 6810, 0
Data.w 11179, 0, 32767, 0, 370, 932, 494, 916, 482, 895, 426, 843, 395, 837, 379, 647, 350, 651, 342, 825, 299, 814, 262, 820, 273, 880, 333, 967, 514, 965, 530, 955, 500, 901, 0, 19, 4883, 0, 6810, 0, 11179, 0, 32767, 0, 0, 742, 0, 965, 66, 966, 210, 886, 210, 845, 242, 819, 266, 821, 300, 817, 162, 595, 156, 542
Data.w 232, 4, 133, 47, 73, 112, 0, 109, 0, 23, 8224, 0, 14135, 0, 30711, 0, 32767, 0, 377, 0, 249, 271, 234, 332, 261, 496, 285, 551, 363, 646, 380, 645, 382, 671, 419, 710, 622, 844, 663, 842, 1148, 811, 1502, 768, 1620, 546, 1613, 479, 1619, 315, 1607, 266, 1455, 0, 0, 22, 0, 0, 17733, 0, 32767, 0, 32767, 0
Data.w 387, 0, 310, 203, 293, 330, 298, 388, 334, 509, 380, 547, 416, 710, 646, 708, 757, 765, 1151, 756, 1413, 564, 1515, 512, 1512, 496, 1516, 366, 1402, 208, 1350, 1, 1327, 0, 0, 21, 0, 0, 0, 0, 0, 0, 32767, 0, 421, 495, 389, 515, 378, 551, 407, 616, 417, 713, 585, 1079, 738, 1079, 682, 975, 643, 703, 599, 611
Data.w 631, 588, 1302, 232, 1226, 161, 1171, 41, 1039, 12, 831, 11, 0, 29, 0, 0, 0, 0, 0, 0, 32767, 0, 629, 588, 423, 491, 439, 411, 505, 354, 554, 231, 651, 160, 721, 38, 830, 13, 1302, 233, 1360, 343, 1425, 403, 1452, 479, 1485, 494, 1496, 533, 1253, 591, 1152, 749, 1123, 888, 1123, 945, 934, 884, 913, 957
Data.w 925, 989, 926, 1012, 934, 1079, 819, 1079, 0, 10, 0, 0, 0, 0, 0, 0, 32767, 0, 833, 1079, 719, 1079, 683, 976, 726, 952, 751, 877, 0, 18, 0, 0, 0, 0, 0, 0, 32767, 0, 1182, 993, 1174, 962, 934, 881, 951, 946, 931, 965, 933, 1011, 911, 1016, 911, 1079, 1919, 1079, 1409, 1011, 1405, 1001, 1367, 975, 1218, 976
Data.w 0, 12, 0, 0, 0, 0, 0, 0, 32767, 0, 1408, 1010, 1919, 1007, 1919, 1079, 1394, 1079, 0, 1079, 0, 1012, 449, 1011, 0, 8, 0, 0, 0, 0, 0, 0, 32767, 0, 446, 1010, 546, 944, 583, 1051, 0, 13, 0, 0, 0, 0, 0, 0, 32767, 0, 1278, 623, 1228, 770, 1219, 982, 1370, 980, 1441, 770, 1459, 620, 1497, 533, 1241, 570
Data.w 0, 9, 22102, 0, 17476, 0, 14392, 0, 32767, 0, 901, 704, 913, 705, 911, 664, 906, 664, 0, 9, 22102, 0, 17476, 0, 14392, 0, 32767, 0, 937, 578, 943, 515, 958, 516, 944, 578, 0, 9, 22102, 0, 17476, 0, 14392, 0, 32767, 0, 821, 511, 832, 557, 839, 556, 837, 512, 0, 9, 14135, 0, 3212, 0, 0, 0, 32767, 0, 789, 436
Data.w 795, 452, 813, 454, 806, 438, 0, 9, 14135, 0, 3212, 0, 0, 0, 32767, 0, 967, 426, 961, 443, 979, 442, 985, 425, 0, 9, 22102, 0, 17476, 0, 14392, 0, 32767, 0, 835, 646, 827, 694, 837, 693, 839, 649, 0, 0
Data.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
EndDataSection