示例#1
0
void GpGpuApp::drawInstanced( const gl::VboMeshRef &vbo, size_t count )
{
	vbo->enableClientStates();
	vbo->bindAllData();
	glDrawElementsInstancedARB( vbo->getPrimitiveType(), vbo->getNumIndices(), GL_UNSIGNED_INT, (GLvoid*)( sizeof(uint32_t) * 0 ), count );
	gl::VboMesh::unbindBuffers();
	vbo->disableClientStates();
}
void Corrdinate_spacesApp::update()
{
    vector<Vec3f> positions;
    positions.resize(4);
    for( int i=0;i<positions.size();i++ ){
        
        Perlin p;
        positions[i] = 3. * ( p.dnoise( getElapsedSeconds()+i,
                                       getElapsedSeconds()+i*2,
                                       getElapsedSeconds() ) * 2 - Vec3f(1.,1.,1.) );
        
    }
    
    mVboMesh->bufferPositions(positions);
    mVboMesh->unbindBuffers();
}
void ImageHFApp::updateData( ImageHFApp::ColorSwitch whichColor )
{
	Surface32f::Iter pixelIter = mImage.getIter();
	auto vertPosIter = mVboMesh->mapAttrib3f( geom::POSITION );
	auto vertColorIter = mVboMesh->mapAttrib3f( geom::COLOR );

	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			Color color( pixelIter.r(), pixelIter.g(), pixelIter.b() );
			float height;
			const float muteColor = 0.2f;

			// calculate the height based on a weighted average of the RGB, and emphasize either the red green or blue color in each of those modes
			switch( whichColor ) {
				case kColor:
					height = color.dot( Color( 0.3333f, 0.3333f, 0.3333f ) );
				break;
				case kRed:
					height = color.dot( Color( 1, 0, 0 ) );
					color *= Color( 1, muteColor, muteColor );
				break;
				case kGreen:
					height = color.dot( Color( 0, 1, 0 ) );
					color *= Color( muteColor, 1, muteColor );
				break;
				case kBlue:
					height = color.dot( Color( 0, 0, 1 ) );
					color *= Color( muteColor, muteColor, 1 );					
				break;            
			}

			// the x and the z coordinates correspond to the pixel's x & y
			float x = pixelIter.x() - mWidth / 2.0f;
			float z = pixelIter.y() - mHeight / 2.0f;

			*vertPosIter++ = vec3( x, height * 30.0f, z );
			*vertColorIter++ = vec3( color.r, color.g, color.b );
		}
	}

	vertPosIter.unmap();
	vertColorIter.unmap();
}
void Corrdinate_spacesApp::setup()
{
    vector<Vec3f> positions;
    vector<uint32_t> indices;
    
    positions.push_back( Vec3f( -1,  1, 0) ); //0
    positions.push_back( Vec3f( -1, -1, 0) ); //1
    positions.push_back( Vec3f(  1, -1, 0) ); //2
    positions.push_back( Vec3f(  1,  1, 0) ); //3
    
    indices.push_back(1);
    indices.push_back(3);
    indices.push_back(0);
    
    indices.push_back(1);
    indices.push_back(2);
    indices.push_back(3);

//    mMesh.appendVertices(positions.data(), positions.size());
//    mMesh.appendIndices(indices.data(), indices.size());
    
    gl::VboMesh::Layout layout;
    layout.setStaticPositions();
    layout.setStaticIndices();
    
    mVboMesh = gl::VboMesh::create( 4, 6, layout, GL_TRIANGLES );
    
    mVboMesh->bufferPositions(positions);
    mVboMesh->bufferIndices(indices);
    
    mVboMesh->unbindBuffers();
    
    mCam.setPerspective(60, getWindowAspectRatio(), .1, 10000);
    mCam.lookAt( Vec3f(0,0,5), Vec3f(0,0,0), Vec3f::yAxis() );
    
    
}
void BulletSpheresApp::createBuffers()
{
	gl::VboMesh::Layout layout;
	layout.attrib( geom::POSITION, 4 ).attrib( geom::NORMAL, 3 ).attrib( geom::TEX_COORD_0, 2 );
	mAttributes = gl::VboMesh::create( geom::Sphere().subdivisions( 16 ), {{ layout, nullptr }} );
	
	mMatrices = gl::Vbo::create( GL_ARRAY_BUFFER, (NUM_PARTICLES-2)*sizeof(mat4) );
	
	auto bufferLayout = geom::BufferLayout();
	bufferLayout.append( geom::CUSTOM_0, geom::FLOAT, 16, sizeof(mat4), 0, 1 );
	
	mAttributes->appendVbo( bufferLayout , mMatrices );
	  
	mRenderSphere = gl::Batch::create( mAttributes, mRenderGlsl );
	mShadowSphere = gl::Batch::create( mAttributes, mShadowGlsl );
}
示例#6
0
void RandomSpawn::setupParticles()
{
    mPointsParticles.clear();
    mDataInstance_P = gl::Vbo::create(GL_ARRAY_BUFFER, mPointsParticles, GL_DYNAMIC_DRAW);
    mAttribsInstance_P.append(geom::CUSTOM_0, 16, sizeof(CloudParticle), offsetof(CloudParticle, PModelMatrix), 1);
    mAttribsInstance_P.append(geom::CUSTOM_1, 1, sizeof(CloudParticle), offsetof(CloudParticle, PSize), 1);
    mAttribsInstance_P.append(geom::CUSTOM_2, 4, sizeof(CloudParticle), offsetof(CloudParticle, PColor), 1);

    mMesh_P = gl::VboMesh::create(geom::Icosahedron());
    mMesh_P->appendVbo(mAttribsInstance_P, mDataInstance_P);

    mShader_P = gl::GlslProg::create(loadAsset("shaders/particle.vert"), loadAsset("shaders/particle.frag"));
    mBatch_P = gl::Batch::create(mMesh_P, mShader_P, { { geom::CUSTOM_0, "iModelMatrix" }, { geom::CUSTOM_1, "iSize" }, { geom::CUSTOM_2, "iColor" } });

    mPerlin = Perlin();
}
示例#7
0
void FiretrailApp::update()
{
    const auto ray = mCamera.generateRay(getMousePos() - getWindowPos(), getWindowSize());
    float result = .0f;
    ray.calcPlaneIntersection(vec3(.0f, .0f, 5.0f), vec3(.0f, -2.0f, 1.0f), &result);
    
    mHeadPosition += (ray.calcPosition(result) - mHeadPosition) * .8f;
    mSpline.pushPoint(mHeadPosition);
    
    const auto length = mSpline.getLength();
    if (length <= .0f) return;
    
    auto mappedPosAttrib = mVboMesh->mapAttrib3f( geom::POSITION );
    
    const auto d = min(mMaxDSlice, length / (float)NUM_SPLINE_NODES);
    
    for (size_t i = 0; i < NUM_SPLINE_NODES; ++i)
    {
        *mappedPosAttrib++ = mSpline.positionAtLength(d * i);
    }
    
    mappedPosAttrib.unmap();
    
    mFps = getAverageFps();
    
    if (mRecordingMovie)
    {
        if( mMovieExporter && getElapsedFrames() > 1 && getElapsedFrames() < MAX_MOVIE_FRAMES )
        {
            mMovieExporter->addFrame( copyWindowSurface() );
        }
        else if( mMovieExporter && getElapsedFrames() >= MAX_MOVIE_FRAMES )
        {
            endMovieRecording();
        }
    }
}
void AudioVisualizerApp::setup()
{
	// initialize signals
	signalChannelEnd = false;

	// make a list of valid audio file extensions and initialize audio variables
	const char* extensions[] = { "mp3", "wav", "ogg" };
	mAudioExtensions = vector<string>( extensions, extensions + 2 );
	mAudioPath = getAssetPath( "" );
	mIsAudioPlaying = false;

	// setup camera
	mCamera.setPerspective( 50.0f, 1.0f, 1.0f, 10000.0f );
	mCamera.lookAt( vec3( -kWidth / 4, kHeight / 2, -kWidth / 8 ), vec3( kWidth / 4, -kHeight / 8, kWidth / 4 ) );

	mCameraUi.setCamera( &mCamera );

	// create channels from which we can construct our textures
	mChannelLeft = Channel32f( kBands, kHistory );
	mChannelRight = Channel32f( kBands, kHistory );
	memset( mChannelLeft.getData(), 0, mChannelLeft.getRowBytes() * kHistory );
	memset( mChannelRight.getData(), 0, mChannelRight.getRowBytes() * kHistory );

	// create texture format (wrap the y-axis, clamp the x-axis)
	mTextureFormat.setWrapS( GL_CLAMP_TO_BORDER );
	mTextureFormat.setWrapT( GL_REPEAT );
	mTextureFormat.setMinFilter( GL_LINEAR );
	mTextureFormat.setMagFilter( GL_LINEAR );
	mTextureFormat.loadTopDown( true );

	// compile shader
	try {
		mShader = gl::GlslProg::create( loadAsset( "shaders/spectrum.vert" ), loadAsset( "shaders/spectrum.frag" ) );
	}
	catch( const std::exception& e ) {
		console() << e.what() << std::endl;
		quit();
		return;
	}

	// create static mesh (all animation is done in the vertex shader)
	std::vector<vec3>		positions;
	std::vector<Colorf>		colors;
	std::vector<vec2>		coords;
	std::vector<uint32_t>	indices;

	for( size_t h = 0; h < kHeight; ++h ) {
		for( size_t w = 0; w < kWidth; ++w ) {
			// add polygon indices
			if( h < kHeight - 1 && w < kWidth - 1 ) {
				size_t offset = positions.size();

				indices.emplace_back( offset );
				indices.emplace_back( offset + kWidth );
				indices.emplace_back( offset + kWidth + 1 );
				indices.emplace_back( offset );
				indices.emplace_back( offset + kWidth + 1 );
				indices.emplace_back( offset + 1 );
			}

			// add vertex
			positions.emplace_back( vec3( float( w ), 0, float( h ) ) );

			// add texture coordinates
			// note: we only want to draw the lower part of the frequency bands,
			//  so we scale the coordinates a bit
			const float part = 0.5f;
			float s = w / float( kWidth - 1 );
			float t = h / float( kHeight - 1 );
			coords.emplace_back( vec2( part - part * s, t ) );

			// add vertex colors
			colors.emplace_back( Color( CM_HSV, s, 0.5f, 0.75f ) );
		}
	}

	gl::VboMesh::Layout layout;
	layout.usage( GL_STATIC_DRAW );
	layout.attrib( geom::Attrib::POSITION, 3 );
	layout.attrib( geom::Attrib::COLOR, 3 );
	layout.attrib( geom::Attrib::TEX_COORD_0, 2 );

	mMesh = gl::VboMesh::create( positions.size(), GL_TRIANGLES, { layout }, indices.size(), GL_UNSIGNED_INT );
	mMesh->bufferAttrib( geom::POSITION, positions.size() * sizeof( vec3 ), positions.data() );
	mMesh->bufferAttrib( geom::COLOR, colors.size() * sizeof( vec3 ), colors.data() );
	mMesh->bufferAttrib( geom::TEX_COORD_0, coords.size() * sizeof( vec2 ), coords.data() );
	mMesh->bufferIndices( indices.size() * sizeof( uint32_t ), indices.data() );

	// play audio using the Cinder FMOD block
	FMOD::System_Create( &mFMODSystem );
	mFMODSystem->init( 32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL );
	mFMODSound = nullptr;
	mFMODChannel = nullptr;

	playAudio( findAudio( mAudioPath ) );

	mIsMouseDown = false;
	mMouseUpDelay = 30.0;
	mMouseUpTime = getElapsedSeconds() - mMouseUpDelay;

	// the texture offset has two purposes:
	//  1) it tells us where to upload the next spectrum data
	//  2) we use it to offset the texture coordinates in the shader for the scrolling effect
	mOffset = 0;
}
示例#9
0
void FiretrailApp::setup()
{
    mCamera.lookAt(vec3(.0f, .0f, -1.0f), vec3(.0f));
    
    mParams = params::InterfaceGl::create( getWindow(), "App parameters", toPixels( ivec2( 200, 300 ) ) );
    mParams->addParam("FPS", &mFps);
    mParams->addParam("Max D Slice",  &mMaxDSlice);
    mParams->addParam("Time Factor",  &mTimeFactor);
    mParams->addParam("Gain",         &mGain      ).updateFn( [this] { mGlsl->uniform("gain", mGain);} );
    mParams->addParam("Lacunarity",   &mLacunarity).updateFn( [this] { mGlsl->uniform("lacunarity", mLacunarity);} );
    mParams->addParam("Magnitude",    &mMagnitude ).updateFn( [this] { mGlsl->uniform("magnitude", mMagnitude);} );
    mParams->addParam("Frag Mul",     &mFragMul   ).updateFn( [this] { mGlsl->uniform("fragMul", mFragMul);} );
    mParams->addParam("Noise Scale",  &mNoiseScale).updateFn( [this] { mGlsl->uniform("noiseScale", mNoiseScale);} );
    mParams->addParam("Layer Offset", &mLayerOffset).updateFn( [this] { mGlsl->uniform("layerOffset", mLayerOffset);} );
    
    mParams->addButton("Start Recording", [this]
    {
        if (!mRecordingMovie) startMovieRecording();
    });
    
    mParams->addButton("End Recording", [this]
    {
        if (mRecordingMovie) endMovieRecording();
    });
    
    gl::Texture::Format mTexFormat;
    mTexFormat.magFilter( GL_LINEAR ).minFilter( GL_LINEAR ).internalFormat( GL_RGBA );//.wrap(GL_REPEAT);
    mFireTex = gl::Texture::create( loadImage( loadAsset( "flame6.png" ) ), mTexFormat );
    
    mTexFormat.wrap(GL_REPEAT);
    mNoiseTex = gl::Texture::create( loadImage( loadAsset( "nzw.png" ) ), mTexFormat );
    
    mGlsl = gl::GlslProg::create(gl::GlslProg::Format()
                                 .vertex( loadAsset( "fire.vert" ) )
                                 .fragment( loadAsset( "fire.frag" ) )
                                 .geometry( loadAsset( "fire.geom" )).attrib( geom::CUSTOM_0, "vSize" ) );

    mGlsl->uniform("fireTex", 0);
    mGlsl->uniform("noiseTex", 1);
    mGlsl->uniform("fragMul", mFragMul);
    mGlsl->uniform("gain", mGain);
    mGlsl->uniform("magnitude", mMagnitude);
    mGlsl->uniform("lacunarity", mLacunarity);
    mGlsl->uniform("noiseScale", mNoiseScale);
    mGlsl->uniform("layerOffset", mLayerOffset);

    // compute texture coordinates
    vector<float> amp( NUM_SPLINE_NODES );
    amp.resize(NUM_SPLINE_NODES);
    
    for (size_t i = 0; i < NUM_SPLINE_NODES; ++i)
    {
        const auto t = (float)i / (float)(NUM_SPLINE_NODES - 1);
        amp[i] = 1.0f - easeInOutSine(t);
    }
    
    mVboMesh = gl::VboMesh::create( NUM_SPLINE_NODES, GL_POINTS, {
        gl::VboMesh::Layout().usage( GL_DYNAMIC_DRAW ).attrib( geom::POSITION, 3 ),
        gl::VboMesh::Layout().usage( GL_STATIC_DRAW ).attrib( geom::Attrib::CUSTOM_0, 1 ),
    });
    
    mVboMesh->bufferAttrib(geom::Attrib::CUSTOM_0, amp);
    
    mBatch = gl::Batch::create(mVboMesh, mGlsl);
    
    resize();
}