예제 #1
0
/*
=============
  GetTextureCoords
  Загрузка текстуры, размещение в атласе, выдача реальных текстурных координат
=============
*/
Vec4 Texture::Atlas::GetTextureCoords( const std::string& textureFileName, const Vec4& textureCoords )
{
  //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::GetTextureCoords => textureFileName['%s'] textureCoords[%3.3f; %3.3f]-[%3.3f; %3.3f]", textureFileName.c_str(), textureCoords.x, textureCoords.y, textureCoords.z, textureCoords.w );
  Texture::Atlas::Item *item = this->IsTextureLoaded( textureFileName );
  if( item )
  {
    Vec3 leftTop, rightBottom;
    leftTop = Vec3( textureCoords.x, textureCoords.y, 0.0f ) * item->matTransform;
    rightBottom = Vec3( textureCoords.z, textureCoords.w, 0.0f ) * item->matTransform;
    //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::GetTextureCoords => existing texture['%s'] t0[%3.5f; %3.5f] t1[%3.5f; %3.5f]", textureFileName.c_str(), leftTop.x, leftTop.y, rightBottom.x, rightBottom.y );
    return Vec4( leftTop.x, leftTop.y, rightBottom.x, rightBottom.y );
  }
  else
  {
    Texture::Atlas::Item *item = this->LoadTexture( textureFileName );
    if( !item ) {
      __log.PrintInfo( Filelevel_ERROR, "Texture::Atlas::GetTextureCoords => LoadTexture('%s') => failed", textureFileName.c_str() );
      return Vec4( 0.0f, 0.0f, 1.0f, 1.0f );
    }
    Vec3 tex0( textureCoords.x, textureCoords.y, 0 ), tex1( textureCoords.z, textureCoords.w, 0 );
    tex0 *= item->matTransform;
    tex1 *= item->matTransform;
    //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::GetTextureCoords => loaded texture['%s'] t0[%3.5f; %3.5f] t1[%3.5f; %3.5f]", textureFileName.c_str(), tex0.x, tex0.y, tex1.x, tex1.y );
    return Vec4( tex0.x, tex0.y, tex1.x, tex1.y );
  }
}//GetTextureCoords
예제 #2
0
osg::ref_ptr< osg::Geode > BranchXML::InitBranchGeode( int iLOD )
{
	//инициировать корневой узел данными

	osg::ref_ptr< osg::Geode > geode = new osg::Geode;

	// Create an object to store geometry in.
	osg::ref_ptr< osg::Geometry > geom = new osg::Geometry;

	// Create an array of vertices.
	osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;

	// Create an array of normals.
	osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;

	// Create a Vec2Array of texture coordinates for texture unit 0
	// and attach it to the geom.
	osg::ref_ptr<osg::Vec4Array> tc = new osg::Vec4Array;

	//получить ссылку на данные веток
	dataBranch &_data = xmlRoot::Instance().GetDataBranch();

	//копируем координаты
	for ( int i = 0 ; i < _data.m_vLOD[ iLOD ].m_vCoords.size() / 3 ; ++i )
	{
		osg::Vec3 coord( _data.m_vLOD[ iLOD ].m_vCoords[ i * 3 ] , 
			_data.m_vLOD[ iLOD ].m_vCoords[ i * 3 + 1 ] ,
			_data.m_vLOD[ iLOD ].m_vCoords[ i * 3 + 2 ] );
		v->push_back( coord );

		osg::Vec3 normal( _data.m_vLOD[ iLOD ].m_vNormals[ i * 3 ] , 
			_data.m_vLOD[ iLOD ].m_vNormals[ i * 3 + 1 ] ,
			_data.m_vLOD[ iLOD ].m_vNormals[ i * 3 + 2 ] );
		n->push_back( normal );

		osg::Vec4 tex0( _data.m_vLOD[ iLOD ].m_vTexCoords0[ i * 4 ] ,
			_data.m_vLOD[ iLOD ].m_vTexCoords0[ i * 4 + 1 ] ,
			_data.m_vLOD[ iLOD ].m_vTexCoords0[ i * 4 + 2 ] ,
			_data.m_vLOD[ iLOD ].m_vTexCoords0[ i * 4 + 3 ] );
		tc->push_back( tex0 );
	}

	geom->setVertexArray( v.get() );
	geom->setNormalArray( n.get() );
	geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
	geom->setTexCoordArray( 0, tc.get() );

	for ( int i = 0 ; i < _data.m_vLOD[ iLOD ].m_Strips.size() ; ++i )
	{
		geom->addPrimitiveSet( new osg::DrawElementsUShort(
			osg::PrimitiveSet::TRIANGLE_STRIP, _data.m_vLOD[ iLOD ].m_Strips[ i ].size() , &_data.m_vLOD[ iLOD ].m_Strips[ i ][ 0 ] ) );
	}

	geode->addDrawable( geom.get() );

	//настроить альфа канал
	SetupAlfaFunc( geode.get() , iLOD );

	return geode.get();
}
예제 #3
0
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow)
int main(int _argc, char** _argv)
{
	EEDesc desc;
	desc.applicationName = L"Emerald";	//窗口名称
	desc.isFullScreen = false;			//是否全屏
	desc.width = 800;					//窗口宽度
	desc.height = 450;					//窗口高度
	desc.isSSAA = true;					//是开启抗锯齿
	desc.isVsync = false;				//是否垂直同步
	EEInitialize();

	EETexture tex0(L"Texture\\etc\\101087.jpg");
	EETexture tex1(L"Texture\\etc\\xmyrz.jpg");
	//EETexture bgTex(L"Texture\\test3.gif");

	//EETexture bgTex(L"Texture\\Project Diva Freedom\\主界面\\默认主题\\背景.jpg");
	EEQuad2D quad(Rect_Float(0, 0, (float)EEGetWidth(), (float)EEGetHeight()), tex1);
	EEContrastAndBrightC cb(tex1);
	cb.SetContrast(200.f);
	cb.SetBright(0.1f);

	while (EERun())
	{
		EEBeginScene(EEColor::BLACK);

		quad.Process();

		printf("%d ", EEGetFPS());
		EEEndScene();
	}

	EEShutdown();
	return 0;
}
예제 #4
0
void RenderableConcave::tessellate(const Polygon3D& polygon) {
	if (polygon.size() < 3) return;

	float minX = (std::numeric_limits<float>::max)();
	float maxX = (std::numeric_limits<float>::min)();
	float minY = (std::numeric_limits<float>::max)();
	float maxY = (std::numeric_limits<float>::min)();

	for (int i = 0; i < polygon.size(); i++) {
		minX = std::min<float>(polygon[i].x(), minX);
		maxX = std::max<float>(polygon[i].x(), maxX);
		minY = std::min<float>(polygon[i].y(), minY);
		maxY = std::max<float>(polygon[i].y(), maxY);
	}

	std::vector<Polygon3D> trapezoids = polygon.tessellate();

	for (int i = 0; i < trapezoids.size(); ++i) {
		if (trapezoids[i].size() < 3) continue;

		QVector2D tex0((trapezoids[i][0].x() - minX) / (maxX - minX), (trapezoids[i][0].y() - minY) / (maxY - minY));
		for (int j = 1; j < trapezoids[i].size() - 1; ++j) {
			generateMeshVertex(trapezoids[i][0].x(), trapezoids[i][0].y(), trapezoids[i][0].z(), 0, 0, 1, tex0.x(), tex0.y());
			generateMeshVertex(trapezoids[i][j].x(), trapezoids[i][j].y(), trapezoids[i][j].z(), 0, 0, 1, (trapezoids[i][j].x() - minX) / (maxX - minX), (trapezoids[i][j].y() - minY) / (maxY - minY));
			generateMeshVertex(trapezoids[i][j+1].x(), trapezoids[i][j+1].y(), trapezoids[i][j+1].z(), 0, 0, 1, (trapezoids[i][j+1].x() - minX) / (maxX - minX), (trapezoids[i][j+1].y() - minY) / (maxY - minY));
		}
	}
}
예제 #5
0
void GlobeView::drawLocalClient(){
	if(!mEarth) return;

	ci::gl::ScopedFaceCulling cull(true, GL_BACK);
	ci::gl::ScopedTextureBind tex0(mTexDiffuse, 0);
	ci::gl::ScopedTextureBind tex1(mTexNormal, 1);
	ci::gl::ScopedTextureBind tex2(mTexMask, 2);

	mEarth->draw();
}
예제 #6
0
void WarpPerspective::draw( const gl::Texture2dRef &texture, const Area &srcArea, const Rectf &destRect )
{
	// clip against bounds
	Area  area = srcArea;
	Rectf rect = destRect;
	clip( area, rect );

	// save current drawing color
	const ColorA &  currentColor = gl::context()->getCurrentColor();
	gl::ScopedColor color( currentColor );

	// adjust brightness
	if( mBrightness < 1.f ) {
		ColorA drawColor = mBrightness * currentColor;
		drawColor.a = currentColor.a;

		gl::color( drawColor );
	}

	// create shader if necessary
	createShader();

	// draw texture
	gl::pushModelMatrix();
	gl::multModelMatrix( getTransform() );

	gl::ScopedTextureBind tex0( texture );
	gl::ScopedGlslProg    shader( mShader );
	mShader->uniform( "uLuminance", mLuminance );
	mShader->uniform( "uGamma", mGamma );
	mShader->uniform( "uEdges", mEdges );
	mShader->uniform( "uExponent", mExponent );

  
	//auto coords = texture->getAreaTexCoords( srcArea );
  float w = static_cast<float>(texture->getActualWidth());
  float h = static_cast<float>(texture->getActualHeight());
  Rectf coords(area.x1 / w, area.y1 / h, area.x2 / w, area.y2 / h);
	gl::drawSolidRect( rect, coords.getUpperLeft(), coords.getLowerRight() );

	gl::popModelMatrix();

	// draw interface
	draw();
}
예제 #7
0
void DOFFilter::drawFullscreen() {
  mGlslProg->uniform("uRenderedTexture", 0);
  mGlslProg->uniform("uDepthTexture", 1);
  mGlslProg->uniform("uFocalDepth", mManualFocalDepth);
  mGlslProg->uniform("uMaxBlur", mMaxBlur * displayScale());
#ifdef ADVANCED_SHADER
  mGlslProg->uniform("uRenderedTextureWidth", (float)mSceneFBO->getWidth());
  mGlslProg->uniform("uRenderedTextureHeight", (float)mSceneFBO->getHeight());
  mGlslProg->uniform("uUseAutofocus", mUseAutofocus);
  mGlslProg->uniform("uAutofocusCenter", mAutofocusCenter);
  mGlslProg->uniform("uNumRings", mNumRings);
  mGlslProg->uniform("uNumSamples", mNumSamples);
  mGlslProg->uniform("uHighlightThreshold", mHighlightThreshold);
  mGlslProg->uniform("uHighlightGain", mHighlightGain);
  mGlslProg->uniform("uBokehEdgeBias", mBokehEdgeBias);
  mGlslProg->uniform("uBokehFringe", mBokehFringe);
  mGlslProg->uniform("uAperture", mAperture / displayScale());
#else
  mGlslProg->uniform("uAspectRatio", getWindowAspectRatio());
  mGlslProg->uniform("uAperture", mAperture / displayScale() / 15);
#endif

  gl::ScopedTextureBind tex0(mSceneFBO->getColorTexture(), 0);
  gl::ScopedTextureBind tex1(mSceneFBO->getDepthTexture(), 1);
  
  const gl::ScopedViewport scopedViewport(ivec2(0), toPixels(getWindowSize()));
  const gl::ScopedMatrices scopedMatrices;
  gl::setMatricesWindow(toPixels(getWindowSize()));
  gl::translate(toPixels(getWindowSize() / 2));
  gl::scale(toPixels(getWindowSize()));
  
  gl::disableDepthRead();
  gl::disableDepthWrite();

  gl::clear(Color::black());
  mQuadBatch->draw();
}