//---------------------------------------------------------- void ofSetupScreenPerspective(float width, float height, bool vFlip, float fov, float nearDist, float farDist) { if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); float eyeX = width / 2; float eyeY = height / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; float aspect = (float) width / height; if(nearDist == 0) nearDist = dist / 10.0f; if(farDist == 0) farDist = dist * 10.0f; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov, aspect, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { glScalef(1, -1, 1); // invert Y axis so increasing Y goes down. glTranslatef(0, -height, 0); // shift origin up to upper-left corner. ofSetCoordHandedness(OF_LEFT_HANDED); } }
//---------------------------------------------------------- void ofGLRenderer::setupScreenOrtho(float width, float height, bool vFlip, float nearDist, float farDist) { if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); ofSetCoordHandedness(OF_RIGHT_HANDED); #ifndef TARGET_OPENGLES if(vFlip) { glOrtho(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); } else glOrtho(0, width, 0, height, nearDist, farDist); #else if(vFlip) { ofMatrix4x4 ortho = ofxMatrix4x4::newOrthoMatrix(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); glMultMatrixf(ortho.getPtr()); }else{ ofMatrix4x4 ortho = ofxMatrix4x4::newOrthoMatrix(0, width, 0, height, nearDist, farDist); glMultMatrixf(ortho.getPtr()); } #endif glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
void ofCairoRenderer::setupScreenOrtho(float width, float height, bool vFlip, float nearDist, float farDist){ if(!b3D) return; if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { projection.makeOrthoMatrix(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); }else{ projection.makeOrthoMatrix(0, width, 0, height, nearDist, farDist); } modelView.makeIdentityMatrix(); };
//---------------------------------------- void ofCamera::begin(ofRectangle rect) { if(!isActive) ofPushView(); isActive = true; ofSetCoordHandedness(OF_RIGHT_HANDED); // autocalculate near/far clip planes if not set by user float nc = nearClip, fc = farClip; if(nearClip == 0 || farClip == 0) { float dist = rect.height * 0.5f / tanf(PI * fov / 360.0f); nc = (nearClip == 0) ? dist / 100.0f : nearClip; fc = (farClip == 0) ? dist * 10.0f : farClip; } glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(isOrtho) { // if(vFlip) glOrtho(0, width, height, 0, nearDist, farDist); // else #ifndef TARGET_OPENGLES glOrtho(0, rect.width, 0, rect.height, nc, fc); #endif } else { gluPerspective(fov, rect.width/rect.height, nc, fc); } glMatrixMode(GL_MODELVIEW); glLoadMatrixf(ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()).getPtr()); //ofViewport(rect.x, rect.y, rect.width, rect.height); }
void ofApp::setup() { ofBackground(0); ofSetCoordHandedness(OF_RIGHT_HANDED); // Setup post-processing chain post.init(ofGetWidth(), ofGetHeight()); post.createPass<FxaaPass>()->setEnabled(false); post.createPass<BloomPass>()->setEnabled(false); post.createPass<DofPass>()->setEnabled(false); post.createPass<KaleidoscopePass>()->setEnabled(false); post.createPass<NoiseWarpPass>()->setEnabled(false); post.createPass<PixelatePass>()->setEnabled(false); post.createPass<EdgePass>()->setEnabled(false); post.createPass<VerticalTiltShifPass>()->setEnabled(false); post.createPass<GodRaysPass>()->setEnabled(false); // Setup box positions for (unsigned i = 0; i < NUM_BOXES; ++i) { posns.push_back(ofVec3f(ofRandom(-300, 300), ofRandom(-300, 300), ofRandom(-300, 300))); cols.push_back(ofColor::fromHsb(255 * i / (float)NUM_BOXES, 255, 255, 255)); } // Setup light light.setPosition(1000, 1000, 2000); // create our own box mesh as there is a bug with // normal scaling and ofDrawBox() at the moment boxMesh = ofMesh::box(20, 20, 20); }
//---------------------------------------- void ofCamera::begin(ofRectangle viewport) { if(!isActive) ofPushView(); isActive = true; ofSetCoordHandedness(OF_RIGHT_HANDED); // autocalculate near/far clip planes if not set by user calcClipPlanes(viewport); glMatrixMode(GL_PROJECTION); ofLoadIdentityMatrix(); if(isOrtho) { // if(vFlip) glOrtho(0, width, height, 0, nearDist, farDist); // else #ifndef TARGET_OPENGLES glOrtho(0, viewport.width, 0, viewport.height, nearClip, farClip); #else ofMatrix4x4 ortho; ortho.makeOrthoMatrix(0, viewport.width, 0, viewport.height, nearClip, farClip); ofLoadMatrix( ortho ); #endif } else { ofMatrix4x4 persp; persp.makePerspectiveMatrix( fov, viewport.width/viewport.height, nearClip, farClip ); ofLoadMatrix( persp ); //gluPerspective(fov, viewport.width/viewport.height, nearClip, farClip); } glMatrixMode(GL_MODELVIEW); ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) ); ofViewport(viewport); }
//---------------------------------------------------------- void ofSetupScreenOrtho(float width, float height, bool vFlip, float nearDist, float farDist) { if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); #ifndef TARGET_OPENGLES glMatrixMode(GL_PROJECTION); glLoadIdentity(); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { glOrtho(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); } else glOrtho(0, width, 0, height, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #else //FIX: is here http://stackoverflow.com/questions/2847574/opengl-es-2-0-equivalent-of-glortho ofLog(OF_LOG_ERROR, "ofSetupScreenOrtho - you can't use glOrtho with iphone / ES at the moment"); #endif }
//---------------------------------------- void ofCamera::begin(ofRectangle viewport) { if(!isActive) ofPushView(); isActive = true; ofSetCoordHandedness(OF_RIGHT_HANDED); // autocalculate near/far clip planes if not set by user calcClipPlanes(viewport); ofSetMatrixMode(OF_MATRIX_PROJECTION); ofLoadIdentityMatrix(); ofLoadMatrix( this->getProjectionMatrix(viewport) ); ofSetMatrixMode(OF_MATRIX_MODELVIEW); ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) ); ofViewport(viewport); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetCoordHandedness(OF_RIGHT_HANDED); sphere.setRadius(100); chroma.load("shaders/chromadepth"); ofFbo::Settings fboSettings; fboSettings.width = 1280; fboSettings.height = 800; fboSettings.internalformat = GL_RGBA32F_ARB; fbo.allocate(fboSettings); fbo.begin(); ofClear(0, 0, 0, 0); fbo.end(); // Setup box positions for (unsigned i = 0; i < 150; ++i) { posns.push_back(ofVec3f(ofRandom(-300, 300), ofRandom(-300, 300), ofRandom(-300, 300))); cols.push_back(ofColor::fromHsb(255 * i / (float)100, 255, 255, 255)); } // Setup light // create our own box mesh as there is a bug with // normal scaling and ofDrawBox() at the moment vidcam.initGrabber(1280, 720); sphere.setRadius(20); sphere.mapTexCoordsFromTexture(vidcam.getTextureReference()); mesh = sphere.getMesh(); }
//---------------------------------------------------------- void ofGLRenderer::setupScreenOrtho(float width, float height, ofOrientation orientation, bool vFlip, float nearDist, float farDist) { if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { ofMatrix4x4 ortho = ofMatrix4x4::newOrthoMatrix(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); } ofMatrix4x4 ortho = ofMatrix4x4::newOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist); glMultMatrixf(ortho.getPtr()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //note - theo checked this on iPhone and Desktop for both vFlip = false and true if(ofDoesHWOrientation()){ if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } }else{ if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation(); switch(orientation) { case OF_ORIENTATION_180: glRotatef(-180, 0, 0, 1); if(vFlip){ glScalef(1, -1, 1); glTranslatef(-width, 0, 0); }else{ glTranslatef(-width, -height, 0); } break; case OF_ORIENTATION_90_RIGHT: glRotatef(-90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); }else{ glScalef(-1, -1, 1); glTranslatef(0, -height, 0); } break; case OF_ORIENTATION_90_LEFT: glRotatef(90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); glTranslatef(-width, -height, 0); }else{ glScalef(-1, -1, 1); glTranslatef(-width, 0, 0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } break; } } }
void ofCairoRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist){ if(!b3D) return; if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); ofOrientation orientation = ofGetOrientation(); float viewW = viewportRect.width; float viewH = viewportRect.height; ofSetCoordHandedness(OF_RIGHT_HANDED); if(isVFlipped()) { ofSetCoordHandedness(OF_LEFT_HANDED); } projection.makeOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist); modelView.makeIdentityMatrix(); //note - theo checked this on iPhone and Desktop for both vFlip = false and true switch(orientation) { case OF_ORIENTATION_180: modelView.glRotate(-180,0,0,1); if(isVFlipped()){ modelView.glScale(-1,-1,1); modelView.glTranslate(width,0,0); }else{ modelView.glTranslate(width,-height,0); } break; case OF_ORIENTATION_90_RIGHT: modelView.glRotate(-90,0,0,1); if(isVFlipped()){ modelView.glScale(1,1,1); }else{ modelView.glScale(1,-1,1); modelView.glTranslate(-width,-height,0); } break; case OF_ORIENTATION_90_LEFT: modelView.glRotate(90,0,0,1); if(isVFlipped()){ modelView.glScale(1,1,1); modelView.glTranslate(0,-height,0); }else{ modelView.glScale(1,-1,1); modelView.glTranslate(0,0,0); } break; case OF_ORIENTATION_DEFAULT: default: if(isVFlipped()){ modelView.glScale(-1,-1,1); modelView.glTranslate(-width,-height,0); } break; } };