void gpuPSApp::resetFBOs(){ mCurrentFBO = 0; mOtherFBO = 1; mFBO[0].bindFramebuffer(); mFBO[1].bindFramebuffer(); // Attachment 0 - Positions glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); gl::setMatricesWindow( mFBO[0].getSize(), false ); gl::setViewport( mFBO[0].getBounds() ); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mPositions.enableAndBind(); gl::draw( mPositions, mFBO[0].getBounds() ); mPositions.unbind(); // Attachment 1 - Velocities glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mVelocities.enableAndBind(); gl::draw( mVelocities, mFBO[0].getBounds() ); mVelocities.unbind(); mFBO[1].unbindFramebuffer(); mFBO[0].unbindFramebuffer(); mPositions.disable(); mVelocities.disable(); }
void ICPApp::draw() { gl::clear(); if( ! mCameraTexture ) return; gl::setMatricesWindow( getWindowSize() ); gl::enableAlphaBlending(); // draw the webcam image gl::color( Color( 1, 1, 1 ) ); gl::draw( mCameraTexture ); mCameraTexture.disable(); //// FOR TESTING PURPOSES ////// // gl::draw (mTexture); // gl::draw( faceResized ); // gl::draw(mTexture); ////////////////////////////////// // Draw the corresponding coloured squares over the identified expressions for( vector<Rectf>::const_iterator expressionIter = mExpressions.begin(); expressionIter != mExpressions.end(); ++expressionIter ){ ColourTheAura(mPredictions[expressionIter-mExpressions.begin()]); gl::drawSolidRect( *expressionIter ); } }
void QuaternionAccumApp::drawBall() { Vec3f pos = mSpline.getPosition( mSplineValue ); Vec3f delta = pos - mLastPos; // our axis of rotation is the normal to the spline at this point Vec3f normal = Vec3f( delta.z, 0, -delta.x ); // rotation amount (in radians) is the distance we've traveled divided by the radius of the ball float rotation = delta.length() / BALL_RADIUS; if( rotation ) { // increment our quaternion by a new quaternion representing how much rotating we did since the last frame Quatf incQuat( normal, rotation ); mQuat *= incQuat; mQuat.normalize(); } gl::translate( Vec3f( 0.0f, BALL_RADIUS, 0.0f ) + pos ); gl::scale( Vec3f( BALL_RADIUS, BALL_RADIUS, BALL_RADIUS ) ); gl::rotate( mQuat ); gl::color( Color( 1, 1, 1 ) ); mBallTexture.enableAndBind(); gl::drawSphere( Vec3f::zero(), 1.0f, 60 ); mBallTexture.disable(); mLastPos = pos; }
void millionParticlesApp::initFBO() { mPos = 0; mBufferIn = 0; mBufferOut = 1; mFbo[0].bindFramebuffer(); mFbo[1].bindFramebuffer(); //Positionen glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); gl::setMatricesWindow( mFbo[0].getSize(), false ); gl::setViewport( mFbo[0].getBounds() ); glClearColor(0.0f,0.0f,0.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mPosTex.enableAndBind(); gl::draw(mPosTex,mFbo[0].getBounds()); mPosTex.unbind(); //velocity buffer glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mVelTex.enableAndBind(); gl::draw(mVelTex,mFbo[0].getBounds()); mVelTex.unbind(); //particle information buffer glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mInfoTex.enableAndBind(); gl::draw(mInfoTex,mFbo[0].getBounds()); mInfoTex.unbind(); mFbo[1].unbindFramebuffer(); mFbo[0].unbindFramebuffer(); mPosTex.disable(); mVelTex.disable(); mInfoTex.disable(); }
void QuaternionAccumApp::drawPlane() { // draw the plane gl::color( Color( 1, 1, 1 ) ); mPlaneTexture.enableAndBind(); glBegin( GL_QUADS ); glTexCoord2f( 0, 0 ); glVertex3f( -10.0f, 0.0f, -10.0f ); glTexCoord2f( 1, 0 ); glVertex3f( 10.0f, 0.0f, -10.0f ); glTexCoord2f( 1, 1 ); glVertex3f( 10.0f, 0.0f, 10.0f ); glTexCoord2f( 0, 1 ); glVertex3f( -10.0f, 0.0f, 10.0f ); glEnd(); mPlaneTexture.disable(); }
void VoronoiGpuApp::draw() { gl::clear(); gl::setMatricesWindow( getWindowSize() ); gl::color( Color( 1, 1, 1 ) ); if( mTexture ) { gl::draw( mTexture ); mTexture.disable(); } // draw the voronoi sites in yellow gl::color( Color( 1.0f, 1.0f, 0.0f ) ); for( vector<Vec2i>::const_iterator ptIt = mPoints.begin(); ptIt != mPoints.end(); ++ptIt ) gl::drawSolidCircle( Vec2f( *ptIt ), 2.0f ); /* gl::enableAlphaBlending(); gl::drawStringRight( "Click to add a point", Vec2f( getWindowWidth() - 10, getWindowHeight() - 20 ), Color( 1, 0.3, 0 ) ); gl::disableAlphaBlending(); */ }
void ocvFaceDetectApp::draw() { if( ! mCameraTexture ) return; gl::setMatricesWindow( getWindowSize() ); gl::enableAlphaBlending(); // draw the webcam image gl::color( Color( 1, 1, 1 ) ); gl::draw( mCameraTexture ); mCameraTexture.disable(); // draw the faces as transparent yellow rectangles gl::color( ColorA( 1, 1, 0, 0.45f ) ); for( vector<Rectf>::const_iterator faceIter = mFaces.begin(); faceIter != mFaces.end(); ++faceIter ) gl::drawSolidRect( *faceIter ); // draw the eyes as transparent blue ellipses gl::color( ColorA( 0, 0, 1, 0.35f ) ); for( vector<Rectf>::const_iterator eyeIter = mEyes.begin(); eyeIter != mEyes.end(); ++eyeIter ) gl::drawSolidCircle( eyeIter->getCenter(), eyeIter->getWidth() / 2 ); }
void RodSoundApp::draw() { while (running && // app::getElapsedSeconds() - tAtLastDraw < 1.0/app::getFrameRate() && fe.nextTimestep(c) > 1.0 / (real) SampleRate) { update(); } tAtLastDraw = app::getElapsedSeconds(); PROFILER_START("Draw"); // Clear out the window with grey gl::clear(Color(0.45, 0.45, 0.5)); // Enable alpha blending and depth testing gl::enableAlphaBlending(); gl::enableDepthRead(true); gl::enableDepthWrite(true); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw framerate counter gl::setMatricesWindow(getWindowSize()); std::stringstream ss; ss << getAverageFps(); gl::drawStringRight(ss.str(), Vec2c(getWindowWidth()-toPixels(10), getWindowHeight()-toPixels(20)), Color(0.0, 0.0, 0.0), Font("Arial", toPixels(12))); // Set projection/modelview matrices gl::setMatrices(cam); // Draw the rod and the normal of the bishop frame for(int i=0; i<r->numEdges(); i++) { Vec3c p0 = EtoC(r->cur().POS(i)); Vec3c p1 = EtoC(r->cur().POS(i+1)); gl::drawLine(p0, p1); gl::color(1.0, 1.0, 0.0); gl::lineWidth(1.0); Vec3c u = EtoC(r->cur().u[i]); gl::drawLine((p0+p1)/2.0, (p0+p1)/2.0+u*(p1-p0).length()*2.0); } m.apply(); l->setDiffuse(Color::white()); l->setAmbient(Color::white()); l->setPosition(Vec3c(0.0, 50.0, 0.0)); l->enable(); diffuseProg.bind(); for (int i=0; i<r->numCPs(); i++) { gl::pushModelView(); gl::translate(EtoC(r->cur().POS(i))); spheredl->draw(); gl::popModelView(); } diffuseProg.unbind(); rodProg.bind(); floorTex.enableAndBind(); gl::draw(floor); floorTex.disable(); rodProg.unbind(); // Draw rod edges rodProg.bind(); rodTex.enableAndBind(); for (int i=0; i<r->numEdges(); i++) { gl::pushModelView(); Vec3c v = EtoC(r->cur().edge(i).normalized()); gl::translate(EtoC(r->cur().POS(i))); Quaternion<real> q(Vec3c(0.0, 1.0, 0.0), v); real angle = acos(std::max((real)-1.0, std::min((real)1.0, (q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().u[i]))))); if ((q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().v(i))) > 0.0) angle = -angle; gl::rotate(Quaternion<real>(v, angle)); gl::rotate(q); gl::rotate(Vec3c(0.0, r->cur().rot(i)*180.0/constants::pi, 0.0)); gl::scale(1.0, r->cur().edgeLength(i), 1.0); cylinderdl->draw(); gl::popModelView(); } rodTex.unbind(); rodProg.unbind(); for (RodEnergy* e : energies) { e->draw(c.timestep()); } integrator->draw(); fe.record(c); PROFILER_STOP("Draw"); }
void GesichtertauschApp::draw() { glClearColor( 0, 0, 0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); if ( ! mCameraTexture ) { return; } // gl::setMatricesWindow( getWindowSize() ), gl::setMatricesWindow(WINDOW_WIDTH, WINDOW_HEIGHT); gl::enableAlphaBlending(); glScalef(-1.0, 1.0, 1.0); glTranslatef(-WINDOW_WIDTH, 0, 0); /* shader */ // TODO make this more opt'd if (ENABLE_SHADER) { mShader.bind(); const int STEPS = 32; float mThresholds[STEPS];// = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; for (int i=0; i < STEPS; ++i) { mThresholds[i] = float(i) / float(STEPS - 1); } mShader.uniform("thresholds", mThresholds, STEPS); mShader.uniform( "tex0", 0 ); } /* draw the webcam image */ gl::color( BACKGROUND_IMAGE_COLOR ); gl::draw( mCameraTexture, Rectf(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) ); mCameraTexture.disable(); /* normalize texture coordinates */ Vec2f mNormalizeScale = Vec2f(1.0 / float(WINDOW_WIDTH), 1.0 / float(WINDOW_HEIGHT)); glMatrixMode(GL_TEXTURE); glPushMatrix(); glScalef(mNormalizeScale.x, mNormalizeScale.y, 1.0); glMatrixMode(GL_MODELVIEW); /* draw orgiginal faces */ if (mEntities.size() < 2) { gl::enableAlphaBlending(); mCameraTexture.enableAndBind(); for( vector<FaceEntity>::const_iterator mIter = mEntities.begin(); mIter != mEntities.end(); ++mIter ) { drawEntity(*mIter, FACE_COLOR_UNO); } mCameraTexture.disable(); gl::disableAlphaBlending(); } /* HACK // swap faces */ mCameraTexture.enableAndBind(); if (mEntities.size() >= 2) { const FaceEntity A = mEntities[0]; const FaceEntity B = mEntities[1]; if (A.visible && B.visible) { FaceEntity mEntityA = FaceEntity(); FaceEntity mEntityB = FaceEntity(); mEntityA.border = B.border; mEntityB.border = A.border; mEntityA.slice = A.slice; mEntityB.slice = B.slice; mEntityA.visible = A.visible; mEntityB.visible = B.visible; mEntityA.ID = A.ID; mEntityB.ID = B.ID; drawEntity(mEntityA, FACE_COLOR_DUO); drawEntity(mEntityB, FACE_COLOR_DUO); } } /* restore texture coordinates */ glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); mCameraTexture.disable(); /* shader */ if (ENABLE_SHADER) { mShader.unbind(); } /* mask */ float MASK_LEFT_TOP = 1; float MASK_LEFT_BOTTOM = 1; float MASK_RIGHT_TOP = 1; float MASK_RIGHT_BOTTOM = 1; gl::color(0, 0, 0, 1); Path2d mPathLeft; mPathLeft.moveTo(0, 0); mPathLeft.lineTo(MASK_LEFT_TOP, 0); mPathLeft.lineTo(MASK_LEFT_BOTTOM, WINDOW_HEIGHT); mPathLeft.lineTo(0, WINDOW_HEIGHT); mPathLeft.close(); gl::drawSolid(mPathLeft); Path2d mPathRight; mPathRight.moveTo(WINDOW_WIDTH, 0); mPathRight.lineTo(WINDOW_WIDTH-MASK_RIGHT_TOP, 0); mPathRight.lineTo(WINDOW_WIDTH-MASK_RIGHT_BOTTOM, WINDOW_HEIGHT); mPathRight.lineTo(WINDOW_WIDTH, WINDOW_HEIGHT); mPathRight.close(); gl::drawSolid(mPathRight); /* draw entity IDs */ const bool DRAW_ENTITY_ID = false; if (DRAW_ENTITY_ID) { for( vector<FaceEntity>::const_iterator mIter = mEntities.begin(); mIter != mEntities.end(); ++mIter ) { const FaceEntity mEntity = *mIter; std::stringstream mStr; mStr << mEntity.ID; gl::drawStringCentered(mStr.str(), mEntity.border.getCenter(), Color(1, 0, 0), mFont); } } /* gooey */ mGui->draw(); }