Skip to content

Instantly share code, notes, and snippets.

@heisters
Created November 16, 2011 22:41
Show Gist options
  • Save heisters/1371724 to your computer and use it in GitHub Desktop.
Save heisters/1371724 to your computer and use it in GitHub Desktop.
reproduce gluPerspective in openFrameworks w/ ofxFenster and glFrustum
// useful as a basis for rendering parts of the image across multiple monitors
// see also http://www.opengl.org/wiki/GluPerspective_code
// and https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/gl/ofGLRenderer.cpp#L315
void testApp::draw(){
ofxFenster * win = ofxFensterManager::get()->getActiveWindow();
ofPoint size = win->getWindowSize();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float halfFovTan = tanf(60 * PI / 360.0);
float baseDist = (size.y / 2) / halfFovTan;
float near = baseDist / 10.f;
float far = baseDist * 10.f;
float ymax = near * halfFovTan;
float xmax = (size.x / size.y) * ymax;
glFrustum(-xmax, xmax, -ymax, ymax, near, far);
glMatrixMode(GL_MODELVIEW);
// the rest of your draw here
}
@ofZach
Copy link

ofZach commented Dec 1, 2014

👏 thanks for this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment