1

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()

Current

Required

1 Answers1

2

You can define clip panes with glClipPlane. e.g.:

glEnable(GL_CLIP_PLANE0)
glClipPlane(GL_CLIP_PLANE0, [1, 0, 0, distance])

glEnable(GL_CLIP_PLANE1)
glClipPlane(GL_CLIP_PLANE1, [0, 1, 0, distance])

# [...]

See also OpenGL overlapping ugly rendering

Rabbid76
  • 202,892
  • 27
  • 131
  • 174