Example #1
0
void gpuPSApp::setupTextures(){
	// Position 2D texture array
	mInitPos = Surface32f( SIDE, SIDE, true);
	Surface32f::Iter pixelIter = mInitPos.getIter();
	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			/* Initial particle positions are passed in as R,G,B 
			 float values. Alpha is used as particle mass. */
			mInitPos.setPixel( pixelIter.getPos(), ColorAf( Rand::randFloat()-0.5f, Rand::randFloat()-0.5f, Rand::randFloat()-0.5f, Rand::randFloat(0.2f, 1.0f) ) );
		}
	}
	gl::Texture::Format tFormat;
	tFormat.setInternalFormat(GL_RGBA32F_ARB);
	mPositions = gl::Texture( mInitPos, tFormat);
	mPositions.setWrap( GL_REPEAT, GL_REPEAT );
	mPositions.setMinFilter( GL_NEAREST );
	mPositions.setMagFilter( GL_NEAREST );
	
	//Velocity 2D texture array
	mInitVel = Surface32f( SIDE, SIDE, true);
	pixelIter = mInitVel.getIter();
	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			/* Initial particle velocities are
			 passed in as R,G,B float values. */
			mInitVel.setPixel( pixelIter.getPos(), ColorAf( 0.0f, 0.0f, 0.0f, 1.0f ) );
		}
	}
	mVelocities = gl::Texture( mInitVel, tFormat);
	mVelocities.setWrap( GL_REPEAT, GL_REPEAT );
	mVelocities.setMinFilter( GL_NEAREST );
	mVelocities.setMagFilter( GL_NEAREST );
}
Example #2
0
void RDiffusionApp::setup()
{
	mReactionU = 0.25f;
	mReactionV = 0.04f;
	mReactionK = 0.047f;
	mReactionF = 0.1f;

	mMousePressed = false;
	
	// Setup the parameters
	mParams = params::InterfaceGl( "Parameters", Vec2i( 175, 100 ) );
	mParams.addParam( "Reaction u", &mReactionU, "min=0.0 max=0.4 step=0.01 keyIncr=u keyDecr=U" );
	mParams.addParam( "Reaction v", &mReactionV, "min=0.0 max=0.4 step=0.01 keyIncr=v keyDecr=V" );
	mParams.addParam( "Reaction k", &mReactionK, "min=0.0 max=1.0 step=0.001 keyIncr=k keyDecr=K" );	
	mParams.addParam( "Reaction f", &mReactionF, "min=0.0 max=1.0 step=0.001 keyIncr=f keyDecr=F" );
	
	gl::Fbo::Format format;
	format.enableDepthBuffer( false );
	
	mCurrentFBO = 0;
	mOtherFBO = 1;
	mFBOs[0] = gl::Fbo( FBO_WIDTH, FBO_HEIGHT, format );
	mFBOs[1] = gl::Fbo( FBO_WIDTH, FBO_HEIGHT, format );
	
	mShader = gl::GlslProg( loadResource( RES_PASS_THRU_VERT ), loadResource( RES_GSRD_FRAG ) );
	mTexture = gl::Texture( loadImage( loadResource( RES_STARTER_IMAGE ) ) );
	mTexture.setWrap( GL_REPEAT, GL_REPEAT );
	mTexture.setMinFilter( GL_LINEAR );
	mTexture.setMagFilter( GL_LINEAR );
	mTexture.bind( 1 );
	
	resetFBOs();
}
Example #3
0
void KaleidoscopeApp::setup()
{
    mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 300 ) );
    mParams.addParam( "Fps", &mFps, "", true );
    mParams.addParam( "Vertical sync", &mVerticalSyncEnabled );
    mParams.addSeparator();
    mNumReflectionLines = 3;
    mParams.addParam( "Reflection lines", &mNumReflectionLines, "min=0, max=32" );
    mRotation = 0.f;
    mParams.addParam( "Rotation", &mRotation, "step=.01" );
    mCenter = Vec2f( .5f, .5f );
    mParams.addParam( "Center X", &mCenter.x, "min=0 max=1 step=.005 group='Center'" );
    mParams.addParam( "Center Y", &mCenter.y, "min=0 max=1 step=.005 group='Center'" );

    mTexture = loadImage( loadAsset( "tx.jpg" ) );
    mTexture.setWrap( true, true );

    try
    {
        mShader = gl::GlslProg( loadAsset( "Kaleidoscope.vert" ),
                                loadAsset( "Kaleidoscope.frag" ) );
    }
    catch ( gl::GlslProgCompileExc &exc )
    {
        console() << exc.what() << endl;
    }
}
Example #4
0
void MemExploreApp::draw()
{
  mTexture = gl::Texture(mDataPointer, GL_RGBA, mVolumeDim * mTilesDim, mVolumeDim * mTilesDim);
  mTexture.setWrap(GL_REPEAT, GL_REPEAT);
  mTexture.setMinFilter(GL_NEAREST);
  mTexture.setMagFilter(GL_NEAREST);
  
  float frustum[6];
  mCamera.getFrustum(&frustum[0], &frustum[1], &frustum[2], &frustum[3], &frustum[4], &frustum[5]);

  mFbo.bindFramebuffer();
  gl::setMatricesWindow(mFbo.getSize(), false);

  mProgram.bind();
  mProgram.uniform("uTexture", 0);
  mProgram.uniform("uVolumeDim", mVolumeDim);
  mProgram.uniform("uTilesDim", mTilesDim);
  mProgram.uniform("uTime", (float)getElapsedSeconds());
  mProgram.uniform("uEyePoint", mCamera.getEyePoint());
  mProgram.uniform("uXAxis", mCamera.getOrientation() * Vec3f::xAxis());
  mProgram.uniform("uYAxis", mCamera.getOrientation() * Vec3f::yAxis());
  mProgram.uniform("uViewDistance", mCamera.getAspectRatio() / abs(frustum[2] - frustum[0]) * mCamera.getNearClip());
  mProgram.uniform("uNegViewDir", -mCamera.getViewDirection().normalized());
  mProgram.uniform("uAspectRatio", mCamera.getAspectRatio());
  mTexture.enableAndBind();
  gl::drawSolidRect(mFbo.getBounds());
  mTexture.unbind();
  mProgram.unbind();
  
  mFbo.unbindFramebuffer();
  
  gl::setMatricesWindow(getWindowSize());
  gl::draw(mFbo.getTexture(), getWindowBounds());
}
void shaderExternalFileExampleApp::update(){
    if( mCapture && mCapture.checkNewFrame() ) {
		mTexture = gl::Texture( mCapture.getSurface() );
        mTexture.setWrap(GL_CLAMP, GL_CLAMP);
		mTexture.setMinFilter(GL_NEAREST);
		mTexture.setMagFilter(GL_NEAREST);
	}
}
void RodSoundApp::setup()
{
//  std::cout << solveBEM(constants::radius) << "\n\n";
//  std::cout << "Expected:\n" << -constants::pi * constants::radius * constants::radius * Mat2e::Identity() << "\n\n";
  
  // Setup scene
  cam.setPerspective(40.0, getWindowAspectRatio(), 0.1, 1000.0);
  cam.lookAt(eyePos, targetPos, Vec3c(0.0, 1.0, 0.0));
  
  // Setup rendering stuff
  spheredl = new gl::DisplayList(GL_COMPILE);
  spheredl->newList();
  gl::drawSphere(Vec3c::zero(), constants::radius);
  spheredl->endList();
  
  cylinderdl = new gl::DisplayList(GL_COMPILE);
  cylinderdl->newList();
  gl::drawCylinder(constants::radius, constants::radius, 1.0);
  cylinderdl->endList();
  
  l = new gl::Light(gl::Light::POINT, 0);
  
  try {
    rodTex = loadImage(loadResource(RES_SIM_YARN_TEX));
  } catch (ImageIoException e) {
    std::cerr << "Error loading textures: " << e.what();
    exit(1);
  }
  
  // Load and compile shaders
  try {
    diffuseProg = gl::GlslProg(loadResource(RES_SIM_VERT_GLSL), loadResource(RES_SIM_FRAG_GLSL));
    rodProg = gl::GlslProg(loadResource(RES_SIM_VERT_TEX_GLSL), loadResource(RES_SIM_FRAG_TEX_GLSL));
  } catch (gl::GlslProgCompileExc e) {
    std::cerr << "Error compiling GLSL program: " << e.what();
    exit(1);
  } catch (ResourceLoadExc e) {
    std::cerr << "Error loading shaders: " << e.what();
    exit(1);
  }
  
  floor.appendVertex(Vec3c(-100.0, 0.0, -100.0));
  floor.appendNormal(Vec3c(0.0, 1.0, 0.0));
  floor.appendTexCoord(Vec2c(-12.0, -12.0));
  floor.appendVertex(Vec3c(100.0, 0.0, -100.0));
  floor.appendNormal(Vec3c(0.0, 1.0, 0.0));
  floor.appendTexCoord(Vec2c(12.0, -12.0));
  floor.appendVertex(Vec3c(100.0, 0.0, 100.0));
  floor.appendNormal(Vec3c(0.0, 1.0, 0.0));
  floor.appendTexCoord(Vec2c(12.0, 12.0));
  floor.appendVertex(Vec3c(-100.0, 0.0, 100.0));
  floor.appendNormal(Vec3c(0.0, 1.0, 0.0));
  floor.appendTexCoord(Vec2c(-12.0, 12.0));
  floor.appendTriangle(0, 1, 2);
  floor.appendTriangle(0, 3, 2);
  
  ci::Surface s(4, 4, false);
  auto iter = s.getIter();
  do {
    do {
      Vec2i pos = iter.getPos();
      unsigned char val = pos.x > 0 && pos.x < 3 && pos.y > 0 && pos.y < 3 ? 100 : 150;
      iter.r() = iter.g() = iter.b() = val;
    } while (iter.pixel());
  } while (iter.line());
  floorTex = gl::Texture(s);
  floorTex.setMagFilter(GL_NEAREST);
  floorTex.setWrap(GL_REPEAT, GL_REPEAT);
  
  // Load the rod
  loadDefaultRod(50);
  // loadRodFile("");
  loadStdEnergies();
  
  PROFILER_START("Total");
}
void millionParticlesApp::setup()
{
    gl::clear();

    try {
        mPosShader = gl::GlslProg(ci::app::loadResource(POS_VS),ci::app::loadResource(POS_FS));
        mVelShader = gl::GlslProg(ci::app::loadResource(VEL_VS),ci::app::loadResource(VEL_FS));
    }
    catch( gl::GlslProgCompileExc &exc ) {
        std::cout << "Shader compile error: " << std::endl;
        std::cout << exc.what();
    }
    catch( ... ) {
        std::cout << "Unable to load shader" << std::endl;
    }

    //controls
    mDrawTextures = false;
    mIsFullScreen = false;

    mFrameCounter = 0;

    mPerlin = Perlin(32,clock() * .1f);

    //initialize buffer
    Surface32f mPosSurface = Surface32f(PARTICLES,PARTICLES,true);
    Surface32f mVelSurface = Surface32f(PARTICLES,PARTICLES,true);
    Surface32f mInfoSurface = Surface32f(PARTICLES,PARTICLES,true);
    Surface32f mNoiseSurface = Surface32f(PARTICLES,PARTICLES,true);

    Surface32f::Iter iterator = mPosSurface.getIter();


    while(iterator.line())
    {
        while(iterator.pixel())
        {

            mVertPos = Vec3f(Rand::randFloat(getWindowWidth()) / (float)getWindowWidth(),
                             Rand::randFloat(getWindowHeight()) / (float)getWindowHeight(),0.0f);

            //velocity
            Vec2f vel = Vec2f(Rand::randFloat(-.005f,.005f),Rand::randFloat(-.005f,.005f));

            float nX = iterator.x() * 0.005f;
            float nY = iterator.y() * 0.005f;
            float nZ = app::getElapsedSeconds() * 0.1f;
            Vec3f v( nX, nY, nZ );
            float noise = mPerlin.fBm( v );

            float angle = noise * 15.0f ;

            //vel = Vec3f( cos( angle ) * 6.28f, cos( angle ) * 6.28f, 0.0f );

            //noise
            mNoiseSurface.setPixel(iterator.getPos(),
                                   Color( cos( angle ) * Rand::randFloat(.00005f,.0002f), sin( angle ) * Rand::randFloat(.00005f,.0002f), 0.0f ));

            //position + mass
            mPosSurface.setPixel(iterator.getPos(),
                                 ColorA(mVertPos.x,mVertPos.y,mVertPos.z,
                                        Rand::randFloat(.00005f,.0002f)));
            //forces + decay
            mVelSurface.setPixel(iterator.getPos(), Color(vel.x,vel.y, Rand::randFloat(.01f,1.00f)));

            //particle age
            mInfoSurface.setPixel(iterator.getPos(),
                                  ColorA(Rand::randFloat(.007f,1.0f), 1.0f,0.00f,1.00f));

        }
    }

    //gl texture settings
    gl::Texture::Format tFormat;
    tFormat.setInternalFormat(GL_RGBA16F_ARB);

    gl::Texture::Format tFormatSmall;
    tFormat.setInternalFormat(GL_RGBA8);

    mSpriteTex = gl::Texture( loadImage( loadResource( "point.png" ) ), tFormatSmall);


    mNoiseTex = gl::Texture(mNoiseSurface, tFormatSmall);
    mNoiseTex.setWrap( GL_REPEAT, GL_REPEAT );
    mNoiseTex.setMinFilter( GL_NEAREST );
    mNoiseTex.setMagFilter( GL_NEAREST );

    mPosTex = gl::Texture(mPosSurface, tFormat);
    mPosTex.setWrap( GL_REPEAT, GL_REPEAT );
    mPosTex.setMinFilter( GL_NEAREST );
    mPosTex.setMagFilter( GL_NEAREST );

    mVelTex = gl::Texture(mVelSurface, tFormat);
    mVelTex.setWrap( GL_REPEAT, GL_REPEAT );
    mVelTex.setMinFilter( GL_NEAREST );
    mVelTex.setMagFilter( GL_NEAREST );

    mInfoTex = gl::Texture(mInfoSurface, tFormatSmall);
    mInfoTex.setWrap( GL_REPEAT, GL_REPEAT );
    mInfoTex.setMinFilter( GL_NEAREST );
    mInfoTex.setMagFilter( GL_NEAREST );

    //initialize fbo
    gl::Fbo::Format format;
    format.enableDepthBuffer(false);
    format.enableColorBuffer(true, 3);
    format.setMinFilter( GL_NEAREST );
    format.setMagFilter( GL_NEAREST );
    format.setWrap(GL_CLAMP,GL_CLAMP);
    format.setColorInternalFormat( GL_RGBA16F_ARB );

    mFbo[0] = gl::Fbo(PARTICLES,PARTICLES, format);
    mFbo[1] = gl::Fbo(PARTICLES,PARTICLES, format);

    initFBO();

    //fill dummy fbo
    vector<Vec2f> texCoords;
    vector<Vec3f> vertCoords, normCoords;
    vector<uint32_t> indices;

    gl::VboMesh::Layout layout;
    layout.setStaticIndices();
    layout.setStaticPositions();
    layout.setStaticTexCoords2d();
    layout.setStaticNormals();

    mVbo = gl::VboMesh(PARTICLES*PARTICLES,PARTICLES*PARTICLES,layout,GL_POINTS);

    for (int x = 0; x < PARTICLES; ++x) {
        for (int y = 0; y < PARTICLES; ++y) {
            indices.push_back( x * PARTICLES + y);
            texCoords.push_back( Vec2f( x/(float)PARTICLES, y/(float)PARTICLES));
        }
    }

    mVbo.bufferIndices(indices);
    mVbo.bufferTexCoords2d(0, texCoords);

}
Example #8
0
void TerrainApp::setup()
{	
	// CAMERA	
	mSpringCam		= SpringCam( -500.0f, getWindowAspectRatio() );

	// LOAD SHADERS
	try {
		mRoomShader		= gl::GlslProg( loadResource( "room.vert" ), loadResource( "room.frag" ) );
		mRdShader		= gl::GlslProg( loadResource( "passThru.vert" ), loadResource( "rd.frag" ) );
		mHeightsShader	= gl::GlslProg( loadResource( "passThru.vert" ), loadResource( "heights.frag" ) );
		mNormalsShader	= gl::GlslProg( loadResource( "passThru.vert" ), loadResource( "normals.frag" ) );
		mTerrainShader	= gl::GlslProg( loadResource( "terrain.vert" ), loadResource( "terrain.frag" ) );
		mSphereShader	= gl::GlslProg( loadResource( "sphere.vert" ), loadResource( "sphere.frag" ) );
	} catch( gl::GlslProgCompileExc e ) {
		std::cout << e.what() << std::endl;
		quit();
	}
	
	// TEXTURE FORMAT
	gl::Texture::Format mipFmt;
    mipFmt.enableMipmapping( true );
    mipFmt.setMinFilter( GL_LINEAR_MIPMAP_LINEAR );    
    mipFmt.setMagFilter( GL_LINEAR );
	
	// LOAD TEXTURES
	mIconTex		= gl::Texture( loadImage( loadResource( "iconTerrain.png" ) ) );
	mGlowTex		= gl::Texture( loadImage( loadResource( "glow.png" ) ) );
	mCubeMap		= CubeMap( GLsizei(512), GLsizei(512),
							   Surface8u( loadImage( loadResource( RES_CUBE1_ID ) ) ),
							   Surface8u( loadImage( loadResource( RES_CUBE2_ID ) ) ),
							   Surface8u( loadImage( loadResource( RES_CUBE3_ID ) ) ),
							   Surface8u( loadImage( loadResource( RES_CUBE4_ID ) ) ),
							   Surface8u( loadImage( loadResource( RES_CUBE5_ID ) ) ),
							   Surface8u( loadImage( loadResource( RES_CUBE6_ID ) ) )
							   );
	
	// ROOM
	gl::Fbo::Format roomFormat;
	roomFormat.setColorInternalFormat( GL_RGB );
	mRoomFbo			= gl::Fbo( APP_WIDTH/ROOM_FBO_RES, APP_HEIGHT/ROOM_FBO_RES, roomFormat );
	bool isPowerOn		= false;
	bool isGravityOn	= true;
	mRoom				= Room( Vec3f( 300.0f, 200.0f, 300.0f ), isPowerOn, isGravityOn );	
	mRoomBackWallTex	= gl::Texture( loadImage( loadResource( "roomWall0.png" ) ) );
	mRoomLeftWallTex	= gl::Texture( loadImage( loadResource( "roomWall1.png" ) ) );
	mRoomRightWallTex	= gl::Texture( loadImage( loadResource( "roomWall1.png" ) ) );
	mRoomCeilingTex		= gl::Texture( loadImage( loadResource( "roomCeiling.png" ) ) );
	mRoomFloorTex		= gl::Texture( loadImage( loadResource( "roomFloor.png" ) ) );
	mRoomBlankTex		= gl::Texture( loadImage( loadResource( "roomBlank.png" ) ) );
	
	// ENVIRONMENT AND LIGHTING
	mFogColor		= Color( 255.0f/255.0f, 255.0f/255.0f, 230.0f/255.0f );
	mSandColor		= Color( 255.0f/255.0f, 133.0f/255.0f,  67.0f/255.0f );
	mBlueSkyColor	= Color( 1.0f/255.0f, 78.0f/255.0f, 174.0f/255.0f );
	mLightPos		= Vec3f( 0.0f, 0.6f, 1.0f );
	mLightDist		= 500.0f;
	mLightDir		= mLightPos.normalized();
	
	// TERRAIN
	mTerrainScale	= Vec3f( 1.0f, 2.0f, 1.0f );
	mTerrain		= Terrain( VBO_SIZE, VBO_SIZE );
	mZoomMulti		= 1.0f;
	mZoomMultiDest	= 1.0f;
	mGradientTex	= gl::Texture( loadImage( loadResource( "gradient.png" ) ) );
	mSandNormalTex	= gl::Texture( loadImage( loadResource( "sandNormal.png" ) ) );
	mSandNormalTex.setWrap( GL_REPEAT, GL_REPEAT );
	
	// REACTION DIFFUSION
	mRd				= RDiffusion( FBO_SIZE, FBO_SIZE );

	// SPHERE
	mSpherePos		= Vec3f::zero();
	mSpherePosDest	= Vec3f::zero();
	mSphere.setCenter( mSpherePosDest );
	mSphere.setRadius( 20.0f );
	
	// MOUSE
	mMouseRightPos	= getWindowCenter();
	mMousePos		= Vec2f::zero();
	mMouseDownPos	= Vec2f::zero();
	mMouseOffset	= Vec2f::zero();
	mMousePosNorm	= Vec2f::zero();
	mMouseLeftDown	= false;
	mMouseRightDown	= false;
	
	mRoom.init();
}