Esempio n. 1
0
void AudioObjApp::draw()
{
	gl::clear( Color( 0, 0, 0 ) );
    gl::enableAlphaBlending();
    gl::enableDepthRead();
    gl::enableDepthWrite();
    
    gl::pushMatrices();

	gl::setMatrices( mMayaCam.getCamera() );
	
	if ( mFeature && mFeatureTex )
	{
		mShader->bind();
		mFeatureTex.enableAndBind();
		mShader->uniform( "dataTex",		0 );
		mShader->uniform( "texWidth",		(float)mFeatureTex.getWidth() );
		mShader->uniform( "texHeight",		(float)mFeatureTex.getHeight() );
		mShader->uniform( "soundDataSize",  (float)mFeature->getSize() );
		mShader->uniform( "spread",         mFeatureSpread );
		mShader->uniform( "spreadOffset",   mFeatureSpreadOffset );
        mShader->uniform( "time",           (float)getElapsedSeconds() );
		mShader->uniform( "tintColor",      mObjColor );
	}
    
    if ( mRenderWireframe )
        gl::enableWireframe();
    
	gl::color( Color(1.0f, 0.0f, 0.0f ) );
    
	if ( mVbo )
	    gl::draw( mVbo );

    if ( mRenderWireframe )
        gl::disableWireframe();
    
	mShader->unbind();
	mFeatureTex.unbind();

	gl::color( Color::white() );
//	gl::drawCoordinateFrame();
  
	gl::popMatrices();
    
    gl::disableDepthRead();
    gl::disableDepthWrite();
    
	gl::setMatricesWindow( getWindowSize() );

	ciXtractReceiver::drawData( mFeature, Rectf( 15, getWindowHeight() - 150, 255, getWindowHeight() - 35 ) );
	
	gl::draw( mFeatureSurf );

    mParams->draw();
}
void ShaderLoadingApp::draw()
{
    // Clear the window
	gl::clear( Color( 0, 0, 0 ) );
    
    // Set a perspective projection matrix and center
    // the drawing at the center of the window
    gl::setMatricesWindowPersp( getWindowSize() );
    gl::translate( getWindowCenter() );
    
    // Draw a sphere and use our shader if available.
    // Wrapping the shader code into a "if" block ensure
    // that it won't be used if the shader hasn't been validated.
    if( mShader ) mShader->bind();
    gl::drawSphere( Vec3f::zero(), 180, 36 );
    if( mShader ) mShader->unbind();
}
void SyphonBasicApp::draw()
{
	gl::enableAlphaBlending();
	gl::clear(Color::white());
    gl::color(ColorA(1.f, 1.f, 1.f, 1.f));
	
    mShader->bind();
    mShader->uniform( "tex0", 0 );
    mShader->uniform( "sampleOffset", Vec2f( cos( mAngle ), sin( mAngle ) ) * ( 3.0f / getWindowWidth() ) );
    gl::draw(mLogo, Vec2f::zero());
    mShader->unbind();
    
    mClientSyphon.draw(Vec2f(16.f, 64.f)); //draw our client image
    
	mScreenSyphon.publishScreen(); //publish the screen's output
	mTextureSyphon.publishTexture(mLogo); //publish our texture without shader
	
	//anything that we draw after here will not be published
    gl::drawStringCentered("This text will not be published to Syphon.", Vec2f(getWindowCenter().x, 20.f), ColorA::black());
	
}
Esempio n. 4
0
void DelayFeedback::draw()
{
	gl::clear();

	if( ! mGlsl || ! mMesh )
		return;

	mGlsl->bind();

	for( const auto &splash : mSplashes ) {
		float radiusNormalized = splash.mRadius / MAX_RADIUS;
		mGlsl->uniform( "uRadius", radiusNormalized );

		Color splashColor( CM_HSV, splash.mColorHsv );
		gl::color( splashColor.r, splashColor.g, splashColor.b, splash.mAlpha() );

		gl::pushModelView();
			gl::translate( splash.mCenter );
			gl::draw( mMesh );
		gl::popModelView();
	}

	mGlsl->unbind();
}
void ProceduralAnimApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0.4f, 0.5f, 0.6f ) );
	gl::setMatrices( mMayaCam.getCamera() );
	gl::enableDepthRead();
	
	gl::Light light( gl::Light::DIRECTIONAL, 0 );
	light.setAmbient( Color::white() );
	light.setDiffuse( Color::white() );
	light.setSpecular( Color::white() );
	light.lookAt( mLightPos, Vec3f::zero() );
	light.update( mMayaCam.getCamera() );
	light.enable();
	
	gl::pushMatrices();
	float e = (float)getElapsedSeconds();
	gl::translate( math<float>::sin( 1.3f * e ), math<float>::cos( 2.7f * e ) );
	gl::enable( GL_LIGHTING );
	gl::enable( GL_NORMALIZE );
		
	if ( mEnableWireframe )
		gl::enableWireframe();
	if( mDrawMesh ) {
		SkinningRenderer::draw( mSkinnedVboBird );
	}
	if ( mEnableWireframe )
		gl::disableWireframe();
	
	gl::disable( GL_LIGHTING );
	gl::disable( GL_NORMALIZE );
	
	if( mDrawSkeleton) {
		SkinningRenderer::draw( mSkinnedVboBird->getSkeleton() );
	}
	
	if( mDrawLabels ) {
		SkinningRenderer::drawLabels( mSkinnedVboBird->getSkeleton(), mMayaCam.getCamera() );
	}

	gl::popMatrices();
	
	Vec3f mRight, mUp;
	mMayaCam.getCamera().getBillboardVectors(&mRight, &mUp);
//	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enableAlphaBlending();
	dustParticleTex->enableAndBind();
	
	mDustShader->bind();
	mDustShader->uniform( "tex", 0 );
	for( const auto& d : mDust ) {
		mDustShader->uniform( "transparency", 1.0f - math<float>::abs(d.z)/(SCENE_SIZE/2.0f) );
		gl::drawBillboard(d, Vec2f(60.f, 60.f), 0.0f, mRight, mUp);
	}
	mDustShader->unbind();
	
	dustParticleTex->unbind();

	mParams.draw();
}
Esempio n. 6
0
void redEyeApp::draw() {
	
    gl::clear(mColorBack);
    mTextureSnd.bind(0);
    mTextureFft.bind(1);
    if(mShader!=NULL) {
        mShader->bind();
        mShader->uniform("iResolution", (Vec2f)getWindowSize());
        mShader->uniform("iGlobalTime", (float)getElapsedSeconds());
        mShader->uniform("iAmplitude", mAmplitude);
        mShader->uniform("iChannel0", 0);   //sound
        mShader->uniform("iChannel1", 1);   //fft
    }
    //TODO more drawing modes (lines, bars, rects, cubes...)
    //TODO mDownSample
    
    glPushMatrix();
    gl::translate(getWindowCenter());
    gl::scale(mScale0);
    gl::rotate(mRotate0);
    gl::translate(mTranslate0);
    gl::color(mColor0);
    gl::lineWidth(mWidth);
    switch(mMode) {
        case 0:
            gl::drawSolidRect(Rectf(getWindowBounds()-(getWindowSize()*0.5)));
            break;
        case 1:
            gl::drawSolidRect(Rectf(getWindowBounds()-(getWindowSize()*0.5)).scaledCentered(0.8f));
            break;
        case 2:
            gl::drawSolidTriangle(
                                  (Vec2f)getWindowSize()*Vec2f(0.0f, -0.375f),
                                  (Vec2f)getWindowSize()*Vec2f(-0.375f, 0.375f),
                                  (Vec2f)getWindowSize()*Vec2f(0.375f, 0.375f));
            break;
        case 3:
            gl::drawSolidCircle(Vec2f::zero(), getWindowHeight()*0.4f, 100);
            break;
        case 4:
            gl::drawSphere(Vec3f::zero(), getWindowHeight()*0.4f, 12);   //sphere detail
            break;
        case 5:
            drawWaveform(false);
            break;
        case 6:
            drawWaveform(true);
            break;
        case 7:
            drawSpectrum(false);
            break;
        case 8:
            drawSpectrum(true);
            break;
    }
    glPopMatrix();
    if(mShader!=NULL) {
        mShader->unbind();
        mTextureSnd.unbind();
        mTextureFft.unbind();
    }
    
    if(!mHide) {
        mParams->draw();
    }
}
void ShaderToyApp::draw()
{
	// Bind textures.
	if(mChannel0) mChannel0->bind(0);
	if(mChannel1) mChannel1->bind(1);
	if(mChannel2) mChannel2->bind(2);
	if(mChannel3) mChannel3->bind(3);

	// Render the current shader to a frame buffer.
	if(mShaderCurrent && mBufferCurrent) {
		mBufferCurrent.bindFramebuffer();

		// Bind shader.
		bindShader(mShaderCurrent);

		// Clear buffer and draw full screen quad (flipped).
		gl::clear();
		gl::drawSolidRect( Rectf(0, getWindowHeight(), getWindowWidth(), 0) );

		// Done.
		mShaderCurrent->unbind();
		mBufferCurrent.unbindFramebuffer();
	}
	
	// Render the next shader to a frame buffer.
	if(mShaderNext && mBufferNext) {
		mBufferNext.bindFramebuffer();

		// Bind shader.
		bindShader(mShaderNext);

		// Clear buffer and draw full screen quad (flipped).
		gl::clear();
		gl::drawSolidRect( Rectf(0, getWindowHeight(), getWindowWidth(), 0) );

		// Done.
		mShaderNext->unbind();
		mBufferCurrent.unbindFramebuffer();
	}

	// Perform a cross-fade between the two shaders.
	double time = getElapsedSeconds() - mTransitionTime;
	double fade = math<double>::clamp( time / mTransitionDuration, 0.0, 1.0 );

	if(fade <= 0.0) {
		// Transition has not yet started. Keep drawing current buffer.
		gl::draw( mBufferCurrent.getTexture(), getWindowBounds() );
	}
	else if(fade < 1.0) {
		// Transition is in progress.
		// Use a transition shader to avoid having to draw one buffer on top of another.
		mBufferNext.getTexture().bind(1);

		mShaderTransition->bind();
		mShaderTransition->uniform("iSrc", 0);
		mShaderTransition->uniform("iDst", 1);
		mShaderTransition->uniform("iFade", (float)fade);

		gl::draw( mBufferCurrent.getTexture(), getWindowBounds() );

		mShaderTransition->unbind();
	}
	else if(mShaderNext) {
		// Transition is done. Swap shaders.
		gl::draw( mBufferNext.getTexture(), getWindowBounds() );

		mShaderCurrent = mShaderNext;
		mShaderNext.reset();

		mPathCurrent = mPathNext;
		mPathNext.clear();

		getWindow()->setTitle( std::string("ShaderToyApp - Showing ") + mPathCurrent.filename().string() );
	}
	else {
		// No transition in progress.
		gl::draw( mBufferCurrent.getTexture(), getWindowBounds() );
	}
}
Esempio n. 8
0
void MeshViewApp::draw()
{
	// Clear the window
	gl::clear();
	gl::color(Color::white());

	if(isInitialized())
	{
		// Get ready to draw in 3D
		gl::pushMatrices();
		gl::setMatrices(m_camera);

		gl::enableDepthRead();
		gl::enableDepthWrite();

		// Bind textures
		if(m_texDiffuse)
			m_texDiffuse->enableAndBind();

		if (m_texNormal)
			m_texNormal->bind(1);

		if (m_texSpecular)
			m_texSpecular->bind(2);

		if(m_texAO)
			m_texAO->bind(3);

		if(m_texEmissive)
			m_texEmissive->bind(4);

		// Bind shader
		m_shader->bind();
		m_shader->uniform("texDiffuse", 0);
		m_shader->uniform("texNormal", 1);
		m_shader->uniform("texSpecular", 2);
		m_shader->uniform("texAO", 3);
		m_shader->uniform("texEmissive", 4);
		m_shader->uniform("texDiffusePower", m_texDiffusePower);
		m_shader->uniform("texNormalPower", m_texNormalPower);
		m_shader->uniform("texSpecularPower", m_texSpecularPower);
		m_shader->uniform("texAOPower", m_texAOPower);
		m_shader->uniform("texEmissivePower", m_texEmissivePower);
		m_shader->uniform("diffuseEnabled", m_diffuseEnabled);
		m_shader->uniform("normalEnabled", m_normalEnabled);
		m_shader->uniform("specularEnabled", m_specularEnabled);
		m_shader->uniform("aoEnabled", m_aoEnabled);
		m_shader->uniform("emissiveEnabled", m_emissiveEnabled);

		m_shader->uniform("material.Ka", m_matAmbient);
		m_shader->uniform("material.Kd", m_matDiffuse);
		m_shader->uniform("material.Ks", m_matSpecular);
		m_shader->uniform("material.Shininess", m_matShininess);
		m_shader->uniform("gamma", m_gamma);

		// Enable lights
		m_light1->enable();
		m_light2->enable();

		// Render model
		gl::pushModelView();
		gl::multModelView(m_matrix);
		m_assimpLoader.draw();
		gl::popModelView();

		// Disable lights
		m_light1->disable();
		m_light2->disable();

		// Unbind shader
		m_shader->unbind();

		// Unbind textures
		gl::disable(m_texDiffuse->getTarget());

		// Disable 3D rendering
		gl::disableDepthWrite();
		gl::disableDepthRead();

		// Restore matrices
		gl::popMatrices();

		// Enable 2D rendering
		gl::setMatricesWindow(getWindowSize());
		gl::setViewport(getWindowBounds());

		// Render parameter window
		if(m_params)
			m_params->draw();
	}

	// Render debug information
	Debug::get().draw(ColorAf::white());
}
void shader02vertexApp::draw() {
    
	gl::clear(Color(0, 0, 0));
    if(mPcmBuffer) {
        mTextureSnd.bind(0);
        mTextureFft.bind(1);
    }
    mShader->bind();
    mShader->uniform("iResolution", (Vec2f)getWindowSize());
    mShader->uniform("iGlobalTime", (float)getElapsedSeconds());
    mShader->uniform("iAmplitude", mAmplitude);
    if(mPcmBuffer) {
        mShader->uniform("iChannel0", 0);   //sound
        mShader->uniform("iChannel1", 1);   //fft
    }
    mShader->uniform("iMouse", mMouse);
    
    gl::color(1.0f, 1.0f, 1.0f);
    switch(mMode) {
        case 0:
            gl::drawSolidRect(Rectf(getWindowBounds()));
            break;
        case 1:
            gl::drawSolidRect(Rectf(getWindowBounds()).scaledCentered(0.8f));
            break;
        case 2:
            gl::drawSolidTriangle(
                                  getWindowCenter()*Vec2f(1.0f, 0.25f),
                                  getWindowCenter()*Vec2f(0.25f, 1.75f),
                                  getWindowCenter()*Vec2f(1.75f, 1.75f));
            break;
        case 3:
            gl::drawSolidCircle(getWindowCenter(), getWindowHeight()*0.4f, 100);
            break;
        case 4:
            gl::drawSphere((Vec3f)getWindowCenter(), getWindowHeight()*0.4f, 12);   //sphere detail
            break;
        case 5:
            drawWaveform(false);
            break;
        case 6:
            drawWaveform(true);
            break;
        case 7:
            drawSpectrum(false);
            break;
        case 8:
            drawSpectrum(true);
            break;
    }
    mShader->unbind();
    if(mPcmBuffer) {
        mTextureSnd.unbind();
        mTextureFft.unbind();
    }
    
    if(!mHide) {
        Color col= Color(1, 1, 1);
        Font fnt= Font("Verdana", 12);
        gl::drawString("mode (m): "+toString(mMode), Vec2f(30.0f, getWindowHeight()-100.0f), col, fnt);
        gl::drawString("frag (f): "+toString(mPathFrag.filename()), Vec2f(30.0f, getWindowHeight()-80.0f), col, fnt);
        gl::drawString("vert (v): "+toString(mPathVert.filename()), Vec2f(30.0f, getWindowHeight()-60.0f), col, fnt);
        gl::drawString("error: "+mError, Vec2f(30.0f, getWindowHeight()-40.0f), col, fnt);
        gl::drawString("fps: "+toString(getAverageFps()), Vec2f(30.0f, getWindowHeight()-20.0f), col, fnt);
    }
}