void ShadedSphereApp::drawIntoRoomFbo() { mRoomFbo.bindFramebuffer(); gl::clear( ColorA( 0.0f, 0.0f, 0.0f, 0.0f ), true ); gl::setMatricesWindow( mRoomFbo.getSize(), false ); gl::setViewport( mRoomFbo.getBounds() ); gl::disableAlphaBlending(); gl::enable( GL_TEXTURE_2D ); glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); Matrix44f m; m.setToIdentity(); m.scale( mRoom.getDims() ); // mLightsTex.bind( 0 ); mRoomShader.bind(); mRoomShader.uniform( "mvpMatrix", mSpringCam.mMvpMatrix ); mRoomShader.uniform( "mMatrix", m ); mRoomShader.uniform( "eyePos", mSpringCam.getEye() ); mRoomShader.uniform( "roomDims", mRoom.getDims() ); mRoomShader.uniform( "mainPower", mRoom.getPower() ); mRoomShader.uniform( "lightPower", mRoom.getLightPower() ); mRoom.draw(); mRoomShader.unbind(); mRoomFbo.unbindFramebuffer(); glDisable( GL_CULL_FACE ); }
void BubbleChamberApp::drawIntoRoomFbo() { mRoomFbo.bindFramebuffer(); gl::clear( ColorA( 0.0f, 0.0f, 0.0f, 0.0f ), true ); gl::setMatricesWindow( mRoomFbo.getSize(), false ); gl::setViewport( mRoomFbo.getBounds() ); gl::disableAlphaBlending(); gl::enable( GL_TEXTURE_2D ); glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); Matrix44f m; m.setToIdentity(); m.scale( mRoom.getDims() ); mRoomShader.bind(); mRoomShader.uniform( "mvpMatrix", mActiveCam.mMvpMatrix ); mRoomShader.uniform( "mMatrix", m ); mRoomShader.uniform( "eyePos", mActiveCam.mCam.getEyePoint() ); mRoomShader.uniform( "roomDims", mRoom.getDims() ); mRoomShader.uniform( "power", mRoom.getPower() ); mRoomShader.uniform( "lightPower", mRoom.getLightPower() ); mRoomShader.uniform( "timePer", mRoom.getTimePer() * 1.5f + 0.5f ); mRoom.draw(); mRoomShader.unbind(); mRoomFbo.unbindFramebuffer(); glDisable( GL_CULL_FACE ); }
void TerrainApp::drawSphere() { Vec3f spherePos = mSphere.getCenter(); Vec3f roomDims = mRoom.getDims(); float x = ( spherePos.x + roomDims.x ) / ( roomDims.x * 2.0f ); float y = ( spherePos.z + roomDims.z ) / ( roomDims.z * 2.0f );; Vec2f texCoord = Vec2f( x, y ); mCubeMap.bind(); mRd.getHeightsTexture().bind( 1 ); mRd.getNormalsTexture().bind( 2 ); mSphereShader.bind(); mSphereShader.uniform( "cubeMap", 0 ); mSphereShader.uniform( "heightsTex", 1 ); mSphereShader.uniform( "normalsTex", 2 ); mSphereShader.uniform( "mvpMatrix", mSpringCam.mMvpMatrix ); mSphereShader.uniform( "terrainScale", mTerrainScale ); mSphereShader.uniform( "eyePos", mSpringCam.getEye() ); mSphereShader.uniform( "fogColor", mFogColor ); mSphereShader.uniform( "sandColor", mSandColor ); mSphereShader.uniform( "power", mRoom.getPower() ); mSphereShader.uniform( "roomDims", mRoom.getDims() ); mSphereShader.uniform( "texCoord", texCoord ); mSphereShader.uniform( "sphereRadius", mSphere.getRadius() * 0.45f ); mSphereShader.uniform( "zoomMulti", mZoomMulti ); mSphereShader.uniform( "timePer", mRoom.getTimePer() * 1.5f + 0.5f ); gl::draw( mSphere, 128 ); mSphereShader.unbind(); }
void BubbleChamberApp::drawInfoPanel() { gl::pushMatrices(); gl::translate( mRoom.getDims() ); gl::scale( Vec3f( -1.0f, -1.0f, 1.0f ) ); gl::color( Color( 1.0f, 1.0f, 1.0f ) * ( 1.0 - mRoom.getPower() ) ); gl::enableAlphaBlending(); float iconWidth = 50.0f; float X0 = 15.0f; float X1 = X0 + iconWidth; float Y0 = 300.0f; float Y1 = Y0 + iconWidth; // DRAW ICON AND MOTH float c = mRoom.getPower() * 0.5f + 0.5f; gl::color( ColorA( c, c, c, 0.5f ) ); gl::draw( mIconTex, Rectf( X0, Y0, X1, Y1 ) ); c = mRoom.getPower(); gl::color( ColorA( c, c, c, 0.5f ) ); gl::disable( GL_TEXTURE_2D ); // DRAW TIME BAR float timePer = mRoom.getTimePer(); gl::drawSolidRect( Rectf( Vec2f( X0, Y1 + 2.0f ), Vec2f( X0 + timePer * ( iconWidth ), Y1 + 2.0f + 4.0f ) ) ); // DRAW FPS BAR float fpsPer = getAverageFps()/60.0f; gl::drawSolidRect( Rectf( Vec2f( X0, Y1 + 4.0f + 4.0f ), Vec2f( X0 + fpsPer * ( iconWidth ), Y1 + 4.0f + 6.0f ) ) ); gl::popMatrices(); }
void RepulsionApp::drawIntoVelocityFbo() { gl::setMatricesWindow( mFboSize, false ); gl::setViewport( mFboBounds ); gl::disableAlphaBlending(); mVelocityFbos[ mThisFbo ].bindFramebuffer(); gl::clear( ColorA( 0, 0, 0, 0 ) ); mPositionFbos[ mPrevFbo ].bindTexture( 0 ); mVelocityFbos[ mPrevFbo ].bindTexture( 1 ); mVelocityShader.bind(); mVelocityShader.uniform( "position", 0 ); mVelocityShader.uniform( "velocity", 1 ); mVelocityShader.uniform( "roomBounds", mRoom.getDims() ); mVelocityShader.uniform( "w", FBO_WIDTH ); mVelocityShader.uniform( "h", FBO_HEIGHT ); mVelocityShader.uniform( "invWidth", 1.0f/(float)FBO_WIDTH ); mVelocityShader.uniform( "invHeight", 1.0f/(float)FBO_HEIGHT ); mVelocityShader.uniform( "dt", mRoom.getTimeDelta() ); mVelocityShader.uniform( "mainPower", mRoom.getPower() ); mVelocityShader.uniform( "gravity", mRoom.getGravity() ); gl::drawSolidRect( mFboBounds ); mVelocityShader.unbind(); mVelocityFbos[ mThisFbo ].unbindFramebuffer(); }
void TerrainApp::drawTerrain() { mRd.getHeightsTexture().bind( 0 ); mRd.getNormalsTexture().bind( 1 ); mGradientTex.bind( 2 ); mSandNormalTex.bind( 3 ); mTerrainShader.bind(); mTerrainShader.uniform( "heightsTex", 0 ); mTerrainShader.uniform( "normalsTex", 1 ); mTerrainShader.uniform( "gradientTex", 2 ); mTerrainShader.uniform( "sandNormalTex", 3 ); mTerrainShader.uniform( "mvpMatrix", mSpringCam.mMvpMatrix ); mTerrainShader.uniform( "terrainScale", mTerrainScale ); mTerrainShader.uniform( "roomDims", mRoom.getDims() ); mTerrainShader.uniform( "zoomMulti", mZoomMulti );//lerp( mZoomMulti, 1.0f, mRoom.getPower() ) ); mTerrainShader.uniform( "power", mRoom.getPower() ); mTerrainShader.uniform( "eyePos", mSpringCam.getEye() ); mTerrainShader.uniform( "lightPos", mLightPos ); mTerrainShader.uniform( "fogColor", mFogColor ); mTerrainShader.uniform( "sandColor", mSandColor ); mTerrainShader.uniform( "mousePosNorm", -( mMousePosNorm - Vec2f( 0.5f, 0.5f ) ) * getElapsedSeconds() * 2.0f ); mTerrainShader.uniform( "spherePos", mSphere.getCenter() ); mTerrainShader.uniform( "sphereRadius", mSphere.getRadius() ); mTerrain.draw(); mTerrainShader.unbind(); }
void ShadedSphereApp::drawSphere() { gl::color( ColorA( 1, 1, 1, 1 ) ); gl::disable( GL_TEXTURE_2D ); mCubeMap.bind(); mSphereShader.bind(); mSphereShader.uniform( "cubeMap", 0 ); mSphereShader.uniform( "radius", 70.0f ); mSphereShader.uniform( "mvpMatrix", mSpringCam.mMvpMatrix ); mSphereShader.uniform( "eyePos", mSpringCam.getEye() ); mSphereShader.uniform( "power", mRoom.getPower() ); mSphereShader.uniform( "roomDim", mRoom.getDims() ); gl::drawSphere( Vec3f::zero(), 1.0f, 128 ); mSphereShader.unbind(); }
int RoomThemeMaker::placeThemeFeatures(Room& room) { trace << "RoomThemeMaker::placeThemeFeatures()" << endl; vector<const FeatureData*> featureDataBelongingToTheme; featureDataBelongingToTheme.resize(0); for(unsigned int i = 0; i < endOfFeatureId; i++) { const FeatureData* const d = eng.featureDataHandler->getData((FeatureId)(i)); if(d->featureThemeSpawnRules.isBelongingToTheme(room.roomTheme)) { featureDataBelongingToTheme.push_back(d); } } vector<Pos> nextToWalls; vector<Pos> awayFromWalls; eng.mapPatterns->setPositionsInArea( room.getDims(), nextToWalls, awayFromWalls); vector<int> featuresSpawnCount(featureDataBelongingToTheme.size(), 0); int nrFeaturesLeftToPlace = getRandomNrFeaturesForTheme(room.roomTheme); int nrFeaturesPlaced = 0; while(true) { if(nrFeaturesLeftToPlace == 0) { trace << "RoomThemeMaker: Placed enough features, returning" << endl; return nrFeaturesPlaced; } const FeatureData* d = NULL; Pos pos(-1, -1); const int FEATURE_CANDIDATE_ELEMENT = trySetFeatureToPlace(&d, pos, nextToWalls, awayFromWalls, featureDataBelongingToTheme); if(d == NULL) { trace << "RoomThemeMaker: Could not find any more spots "; trace << "to place feature, returning" << endl; return nrFeaturesPlaced; } else { trace << "RoomThemeMaker: Placing " << d->name_a << endl; eng.featureFactory->spawnFeatureAt(d->id, pos); featuresSpawnCount.at(FEATURE_CANDIDATE_ELEMENT)++; nrFeaturesLeftToPlace--; nrFeaturesPlaced++; //Check if more of this feature can be spawned, //if not, delete it from feature candidates if( featuresSpawnCount.at(FEATURE_CANDIDATE_ELEMENT) >= d->featureThemeSpawnRules.getMaxNrInRoom()) { featuresSpawnCount.erase( featuresSpawnCount.begin() + FEATURE_CANDIDATE_ELEMENT); featureDataBelongingToTheme.erase( featureDataBelongingToTheme.begin() + FEATURE_CANDIDATE_ELEMENT); //Are there any more features left to place at all? if(featureDataBelongingToTheme.empty()) {return nrFeaturesPlaced;} } eraseAdjacentCellsFromVectors(pos, nextToWalls, awayFromWalls); } } }