Move depth squared in OpenGL

Share your advanced PureBasic knowledge/code with the community.
threedslider
Enthusiast
Enthusiast
Posts: 397
Joined: Sat Feb 12, 2022 7:15 pm

Move depth squared in OpenGL

Post by threedslider »

Hello

Nice to play (very small) and to move for squared by mouse :)

Code: Select all

;;;
;;;  Created by threedslider -- 02/07/2024
;;;

move.f = 0

ox.f = 0
oy.f = 0

Procedure squared(x,y,w,h)   
    
    glBegin_(#GL_LINES)
    glColor3f_(1.0, 0.3, 1.0)
    glVertex3f_( x-w, y+h, 0.0) 
    glVertex3f_( x+w, y+h, 0.0) 
    glVertex3f_( x+w, y+h, 0.0) 
    glVertex3f_( x+w, y-h, 0.0) 
    glVertex3f_( x+w, y-h, 0.0) 
    glVertex3f_( x-w, y-h, 0.0) 
    glVertex3f_( x-w, y-h, 0.0) 
    glVertex3f_( x-w, y+h, 0.0) 
    glEnd_()
   
EndProcedure
  
Procedure depth_squared(x,y,w,h,iter)
  
  Shared ox
  Shared oy

  

  
  xpos.f = 0
  ypos.f = 0
  
  xpos = xpos + ox / 130.0 
  ypos = ypos - oy / 100.0 
  
  squared(x,y,w,h)
  
  If iter = 0
    iter = 1
  Else
    depth_squared(x+1+xpos-4,y+1+ypos+2,w-3,h-3,iter-1)
  EndIf
  
EndProcedure

  

InitSprite()
InitKeyboard()
InitMouse()


OpenWindow(0, 0, 0, 800, 600, "OpenGL : Move for depth squared", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)


glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_() 
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glMatrixMode_(#GL_MODELVIEW)
glTranslatef_(0, 0, -50)
glShadeModel_(#GL_SMOOTH)
glEnable_(#GL_LIGHT0)
glEnable_(#GL_LIGHTING)
glEnable_(#GL_COLOR_MATERIAL)
glEnable_(#GL_DEPTH_TEST)
glEnable_(#GL_CULL_FACE)   
glViewport_(0, 0, 800, 600)

x.i = 0

Repeat
glClearColor_(0.1, 0.1, 0.1, 0) ; background color
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  Repeat
    event = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        quit = 1
     EndSelect
   Until event = 0
   
   ExamineMouse()
   ox = MouseX()
   oy = MouseY()   
    
   depth_squared(0,0,25,19,6)
       
   FlipBuffers()
 
   ExamineKeyboard()
 
Until KeyboardPushed(#PB_Key_Escape) Or quit = 1
Happy coding !