I want to render only the parts where it is inside the cube to something similar that is shown in 2 figure
my current Code to render a sphere is here
def Sphere(ball):
glPushMatrix()
sphere = gluNewQuadric()
glTranslatef(ball.pos.x,ball.pos.y,ball.pos.z) #Move to the place
glColor3fv((1,0,0)) #Put color
gluSphere(sphere, ball.radius, 16, 8) #Draw sphere
glPopMatrix()