Un exemple de création d'une surface carré 2D
Code : Tout sélectionner
;Summary
Declare Start()
Declare DrawPlane(Gadget)
Declare Resize()
Declare Exit()
Start()
Procedure Start()
OpenWindow(0, 0, 0, 800, 600, "Create Plane", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
OpenGLGadget(0, 10, 10, 700, 500)
DrawPlane(0)
;Triggers
BindEvent(#PB_Event_SizeWindow, @Resize())
BindEvent(#PB_Event_CloseWindow, @Exit())
Repeat : WaitWindowEvent() : ForEver
EndProcedure
Procedure DrawPlane(Gadget)
SetGadgetAttribute(Gadget, #PB_OpenGL_SetContext, #True)
; Set the current color
;glColor3f_(1.0, 1.0, 0.0)
;or rgb color
glColor3ub_(255, 0, 0)
; Delimit the vertices that define a primitive
glBegin_(#GL_POLYGON)
glVertex2f_(-0.5, -0.5)
glVertex2f_(-0.5, 0.5)
glVertex2f_(0.5, 0.5)
glVertex2f_(0.5, -0.5)
glEnd_()
; force execution of GL commands
glFlush_()
SetGadgetAttribute(Gadget, #PB_OpenGL_FlipBuffers, #True)
EndProcedure
Procedure Resize()
ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0) - 100, WindowHeight(0) - 100)
DrawPlane(0)
EndProcedure
Procedure Exit()
End
EndProcedure
Avantage : Contrairement à Ogre3D, on peut redimensionner le gadget openGl. Ici je ne respecte pas les proportions.
