For future reference I've achieved what I needed by using user-defined clip planes
ofApp.h
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
ofSpherePrimitive sphere, sphere1;
ofLight light;
double eqn0[4] = {0., -0.1, 0.1, 5.};
double eqn1[4] = {0., 0.1, -0.1, 5.};
double eqn2[4] = {0.1, -0.1, 0.1, 5.};
double eqn3[4] = {-0.1, 0.1, -0.1, 5.};
float rot;
};
ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
sphere.set(200,20);
sphere1.set(150,20);
ofBackground(0, 0, 0);
ofEnableDepthTest();
light.setPosition(500, 100, 100);
light.enable();
}
//--------------------------------------------------------------
void ofApp::update(){
//updating the plane equations for fun
eqn0[0] = sin(ofGetElapsedTimef());
eqn1[0] = -1*sin(ofGetElapsedTimef());
eqn2[1] = cos(ofGetElapsedTimef());
eqn3[1] = -1*cos(ofGetElapsedTimef());
//for some reason the clip plane equations need to be set every frame
//seetting them in setup() alone does not work; even when not updating them.
glClipPlane(GL_CLIP_PLANE0, eqn0);
glClipPlane(GL_CLIP_PLANE1, eqn1);
glClipPlane(GL_CLIP_PLANE2, eqn2);
glClipPlane(GL_CLIP_PLANE3, eqn3);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofColor(255);
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofPushView();
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
sphere.draw();
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
ofPopView();
ofPushView();
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
sphere1.draw();
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
ofPopView();
}