Abstract paintings

Advanced game related topics
User avatar
SPH
Enthusiast
Enthusiast
Posts: 571
Joined: Tue Jan 04, 2011 6:21 pm

Abstract paintings

Post by SPH »

Abstract paintings

F1 = Default
F2 = Mirror 1
F3 = Double mirror

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Abstract paintings OpenGL   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; PB6.0 - SPH(2023) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;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

Last edited by SPH on Wed Nov 15, 2023 9:52 am, edited 1 time in total.

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
idle
Always Here
Always Here
Posts: 5896
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Abstract paintings

Post by idle »

nice
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: Abstract paintings

Post by pf shadoko »

very nice
but there's a flip buffer problem
User avatar
SPH
Enthusiast
Enthusiast
Posts: 571
Joined: Tue Jan 04, 2011 6:21 pm

Re: Abstract paintings

Post by SPH »

pf shadoko wrote: Tue Nov 14, 2023 2:25 pm very nice
but there's a flip buffer problem
What is exactly the problem ?
Here, all is ok :cry:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Abstract paintings

Post by AZJIO »

What surprised me is that every time I start the loops are always different in shape and color
User avatar
SPH
Enthusiast
Enthusiast
Posts: 571
Joined: Tue Jan 04, 2011 6:21 pm

Re: Abstract paintings

Post by SPH »

AZJIO wrote: Tue Nov 14, 2023 6:37 pm What surprised me is that every time I start the loops are always different in shape and color
Yes, because it use "random" a lot :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Abstract paintings

Post by AZJIO »

SPH wrote: Tue Nov 14, 2023 8:21 pm Yes, because it use "random" a lot :idea:
This is to be expected.
You just didn’t leave a description of what to expect, and in such a situation, not everyone wants to waste time, given the appearance of 20 topics per day, and chooses if they liked the name of the topic.
maurice100
New User
New User
Posts: 1
Joined: Tue Mar 05, 2024 6:53 am

Re: Abstract paintings

Post by maurice100 »

Beautiful
To run on Mac OS Arm I disabled ShowCursor(0) :lol:
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: Abstract paintings

Post by threedslider »

Nice abstract ! :)

Thanks for sharing.
rootuid
User
User
Posts: 48
Joined: Sat Nov 23, 2013 11:46 am

Re: Abstract paintings

Post by rootuid »

Very nice, reminds me of a windows screensaver.

Why does ShowCursor_(0) not work on Mac?
User avatar
SPH
Enthusiast
Enthusiast
Posts: 571
Joined: Tue Jan 04, 2011 6:21 pm

Re: Abstract paintings

Post by SPH »

rootuid wrote: Fri Jul 12, 2024 10:31 am Very nice, reminds me of a windows screensaver.

Why does ShowCursor_(0) not work on Mac?
because it's an API instruction :wink:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Post Reply