■ DrawMoon(x.f, y.f, Width.f, Height.f, Fullness.f = 1, Color.i = $FFFFFFFF, Angle.f = 0)
x, y Position de la lune
Width, Height. Largeur et hauteur de la lune.
Fullness : Rondeur de la lune.
Par défaut 1 la lune est pleine
-0.99 Le croissant de lune est très fin.
-0.95 Le croissant de lune est un peu moins fin
etc ...
Color : Couleur à utiliser au format RGBA
Par défaut la couleur utilisé est blanche.
Angle : Rotation de la lune.
■ Code exemple.
Code : Tout sélectionner
EnableExplicit
Global Scene, ww = 800, wh = 600
; Summary
Declare Start()
Declare Render()
Declare DrawMoon(x.f, y.f, Width.f, Height.f, Fullness.f = 1, Color.i = $FFFFFFFF, Angle.f = 0)
Declare Exit()
Start()
Procedure Start()
OpenWindow(#PB_Any, 0, 0, ww, wh, "OpenGL : Draw Moon", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
; OpenGL drawing context
Scene = OpenGLGadget(#PB_Any, 0, 0, ww, wh, #PB_OpenGL_NoDepthBuffer)
; Properties of the camera
glMatrixMode_(#GL_PROJECTION)
glOrtho_(0, ww, wh, 0, -1, 1)
; Background color
; Each RGBA component is divided by 255
glClearColor_(0, 0, 112/255, 1.0)
; Opacity
glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
; Events
BindEvent(#PB_Event_CloseWindow, @Exit())
; Render Loop
Render()
EndProcedure
; Render
Procedure Render()
Repeat
WindowEvent()
; ClearScreen
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
; Draw moon
DrawMoon(600, 150, 100, 100, -0.90, RGBA(255, 255, 212, 255))
; FlipBuffers
SetGadgetAttribute(Scene, #PB_OpenGL_FlipBuffers, #True)
ForEver
EndProcedure
; Draw Moon
Procedure DrawMoon(x.f, y.f, Width.f, Height.f, Fullness.f = 1, Color.i = $FFFFFFFF, Angle.f = 0)
Protected Finesse.f = 0.1
Protected n.f = Finesse
Protected SinAngle.f
Protected CosAngle.f
Protected x0.f
Protected y0.f
glMatrixMode_(#GL_MODELVIEW)
glPushMatrix_();
; Location
glTranslatef_(x, y, 0)
; Rotate
glRotatef_(Angle, 0, 0, 1)
; Draw Moon
glBegin_(#GL_QUAD_STRIP)
glColor4f_(Red(Color)/255, Green(Color)/255, Blue(Color)/255, Alpha(Color)/255)
While n < #PI
SinAngle.f = Sin(n)
CosAngle.f = Cos(n)
x0 = (Width * SinAngle)
y0 = (Height * CosAngle)
glVertex2f_(x0, y0);
glVertex2f_(-Fullness * x0, y0)
n + Finesse
Wend
glEnd_()
glPopMatrix_()
EndProcedure
Procedure Exit()
End
EndProcedure