Why the polygons of line 150 and 157 do not respect the alpha that I want to apply to them?
thx
Code: Select all
;EnableExplicit
UsePNGImageDecoder()
UseJPEGImageDecoder()
;-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
;-STRUCTURES
Structure Integer2
X.i
Y.i
EndStructure
Global.Integer2 WindowDim
WindowDim\X = 1920
WindowDim\Y = 1080
;-GLOBALS
Global.i Image1, Image2
Global.i Texture1, Texture2
;-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,1920,1080, "Polygons_Maker",#PB_Window_Maximize|#PB_Window_BorderLess)
If win=0
Beep_(500,250) : Delay(150) : Beep_(500,250)
Debug ("OpenWindow() impossible")
End
EndIf
screenGL=OpenGLGadget(#OpenGLGadget,0,0,1920,1080)
If screenGL=0
Beep_(500,250) : Delay(150) : Beep_(500,250)
Debug ("OpenGLGadget() impossible")
End
EndIf
SetupOpenGL()
;Load images.
im$=OpenFileRequester("Choisis une image","","",0)
Image1 = LoadImage(#PB_Any,im$)
Texture1 = SetupGLTexture(Image1)
;*********************************************************************************************************************************
;*********************************************************************************************************************************
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 666)
AddKeyboardShortcut(0, #PB_Shortcut_H, 8) ; hide/show
hide=0
alpha.f=0.5
rouge.f=0.5
vert.f=0.5
bleu.f=0.5
no_alpha=0
Dim poly_x(1000)
Dim poly_y(1000)
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;*********************************************************************************************************************************
;-MAIN REPEAT
Repeat ;- ..... Repeat
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()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_LeftClick
Beep_(1500,55) ;Debug "Clic avec le bouton gauche de la souris"
poly_x(0)+1
poly_x(poly_x(0))=Resx
poly_y(poly_x(0))=Resy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_RightDoubleClick
If poly_x(0)>0
Beep_(500,400) ;: Debug "Double-clic avec le bouton droit de la souris"
Dim poly_x(1000)
Dim poly_y(1000)
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_RightClick
If poly_x(0)>0
Beep_(500,55) ;Debug "Clic avec le bouton droit de la souris"
poly_x(0)-1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case #PB_EventType_MiddleButtonDown
If poly_x(0)>2
Beep_(3000,55) : Delay(150) : Beep_(3000,55) ;Debug "Clic avec le bouton centre de la souris"
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndSelect
EndSelect
Case #PB_Event_Menu
Select EventMenu()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Case 666
End
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EndSelect
EndSelect
Render()
glBegin_(#GL_POLYGON)
glColor4f_(1,1,1,1)
glVertex2f_(22,11)
glVertex2f_(500,66)
glVertex2f_(33,755)
glEnd_()
glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA,#GL_ONE_MINUS_SRC_ALPHA)
glBegin_(#GL_POLYGON)
glColor4f_(0,1,1,0.5)
;glColor4f_(1,1,1,1)
glVertex2f_(400,600)
glVertex2f_(200,600)
glVertex2f_(300,100)
glEnd_()
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
If poly_x(0)>1; And 0=1
glBegin_(#GL_POLYGON)
If no_alpha=1
glColor4f_(rouge,vert,bleu,1)
Else
glColor4f_(rouge,vert,bleu,alpha)
EndIf
For i=1 To poly_x(0)
glVertex2f_(poly_x(i),poly_y(i))
Next
If hide=0
glVertex2f_(Resx,Resy) ;: Debug Resx : Debug Resy : Debug "----------"
EndIf
glEnd_()
EndIf
; SetGadgetAttribute(1,#PB_OpenGL_FlipBuffers,#True)
SetGadgetAttribute(#OpenGLGadget, #PB_OpenGL_FlipBuffers, #True)
ForEver
; EndIf
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
Procedure SetupGLTexture(ImageHandle.i)
Define.i ImageW, ImageH, ImageD
Define.i MemoryAddress
Define.i TextureHandle
If IsImage(ImageHandle) = 0
ProcedureReturn #False
EndIf
ImageD = ImageDepth(ImageHandle, #PB_Image_InternalDepth)
StartDrawing(ImageOutput(ImageHandle))
MemoryAddress = DrawingBuffer()
StopDrawing()
If MemoryAddress = 0
ProcedureReturn #False
EndIf
glGenTextures_(1, @TextureHandle)
glBindTexture_(#GL_TEXTURE_2D, TextureHandle)
ImageW = ImageWidth(ImageHandle)
ImageH = ImageHeight(ImageHandle)
If ImageD = 32
glTexImage2D_(#GL_TEXTURE_2D, 0, 4, ImageW, ImageH, 0, #GL_BGRA, #GL_UNSIGNED_BYTE, MemoryAddress)
Else
glTexImage2D_(#GL_TEXTURE_2D, 0, 3, ImageW, ImageH, 0, #GL_BGR, #GL_UNSIGNED_BYTE, MemoryAddress)
EndIf
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
ProcedureReturn TextureHandle
EndProcedure