示例#1
0
ITexture*
ResourceManager::getTextureByID (unsigned int id) {

	size_t siz = m_Textures.size();
	ITexture *tex;

	for (unsigned int i = 0; i < siz; i++) {
		tex = m_Textures[i];
		if (id == tex->getPropi(ITexture::ID)) {
			return(tex);
		}
	}

	return(NULL);
}
		const IntSize& getTextureSize(const std::string& _texture, bool _cache)
		{
			// предыдущя текстура
			static std::string old_texture;
			static IntSize old_size;

			if (old_texture == _texture && _cache)
				return old_size;
			old_texture = _texture;
			old_size.clear();

			if (_texture.empty())
				return old_size;

			RenderManager& render = RenderManager::getInstance();

			if (nullptr == render.getTexture(_texture))
			{
				if (!DataManager::getInstance().isDataExist(_texture))
				{
					MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
					return old_size;
				}
				else
				{
					ITexture* texture = render.createTexture(_texture);
					texture->loadFromFile(_texture);
				}
			}

			ITexture* texture = render.getTexture(_texture);
			if (texture == nullptr)
			{
				MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
				return old_size;
			}

			old_size.set(texture->getWidth(), texture->getHeight());

	#if MYGUI_DEBUG_MODE == 1
			if (!Bitwise::isPO2(old_size.width) || !Bitwise::isPO2(old_size.height))
			{
				MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
			}
	#endif

			return old_size;
		}
示例#3
0
//-----------------------------------------------------------------------------
// Purpose: Initializes all view systems
//-----------------------------------------------------------------------------
void CViewRender::Init( void )
{
	memset( &m_PitchDrift, 0, sizeof( m_PitchDrift ) );

	m_bDrawOverlay = false;

	m_pDrawEntities		= cvar->FindVar( "r_drawentities" );
	m_pDrawBrushModels	= cvar->FindVar( "r_drawbrushmodels" );

	beams->InitBeams();
	tempents->Init();

	m_TranslucentSingleColor.Init( "debug/debugtranslucentsinglecolor", TEXTURE_GROUP_OTHER );
	m_ModulateSingleColor.Init( "engine/modulatesinglecolor", TEXTURE_GROUP_OTHER );
	
	extern CMaterialReference g_material_WriteZ;
	g_material_WriteZ.Init( "engine/writez", TEXTURE_GROUP_OTHER );

	// FIXME:  
	QAngle angles;
	engine->GetViewAngles( angles );
	AngleVectors( angles, &m_vecLastFacing );

#if defined( REPLAY_ENABLED )
	m_pReplayScreenshotTaker = NULL;
#endif

#if defined( CSTRIKE_DLL )
	m_flLastFOV = default_fov.GetFloat();
#endif

	ITexture *depthOld = materials->FindTexture("_rt_FullFrameDepth", TEXTURE_GROUP_RENDER_TARGET);
	static int flags = TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_DEPTHRENDERTARGET;
	if (depthOld)
		flags = depthOld->GetFlags();

	int iW, iH;
	materials->GetBackBufferDimensions(iW, iH);
	materials->BeginRenderTargetAllocation();
	materials->CreateNamedRenderTargetTextureEx(
		"_rt_FullFrameDepth_Alt",
		iW, iH, RT_SIZE_NO_CHANGE,
		IMAGE_FORMAT_A8,
		MATERIAL_RT_DEPTH_NONE,
		flags,
		0);
	materials->EndRenderTargetAllocation();
}
示例#4
0
/*
*	Creates a render target
*	Param _kfWidth  : The width of the render terget
*	Param _kfHeight : The height of th erender target
*	Param _keFMT	: The render targets format
*	Return : ITexture, The render target
*/
ITexture* CDX9TextureManager::CreateRenderTarget( CAssetId& _rAssetId,const uint32 _kuWidth, const uint32 _kuHeight, const ESurfaceFormat _keFMT, const bool _bWriteOnly  )
{

	// Check if the render target has already been created.
	ITexture* pRenderTarget = NULL;
	pRenderTarget = GetAssetById( _rAssetId );
	if( pRenderTarget )
	{
		pRenderTarget->AddRef( );
		return pRenderTarget;
	}

	static const D3DFORMAT pFormats[] = 
	{
		D3DFMT_R32F,
		D3DFMT_X8R8G8B8,
		D3DFMT_D16,
	};

	
	// Do we want to crate a depth stencile?
	if( _keFMT == SF_uDepth )
	{
		// Create a depth stencile texture
		IDirect3DSurface9* pSurface = NULL;
		if( FAILED( CDX9Renderer::GetDevice( )->CreateDepthStencilSurface( _kuWidth, _kuHeight, pFormats[_keFMT], D3DMULTISAMPLE_NONE, 0, !_bWriteOnly, &pSurface, 0 ) ) )
		{
			// no
			// assert
			return NULL;
		}
		return new CDX9Texture( pSurface, CDX9Renderer::GetDevice( ), true );
	}

	// Create a render target

	IDirect3DTexture9* pTexture = NULL;
	//NOTE: The 0 may need to be a 1
	if( FAILED( CDX9Renderer::GetDevice( )->CreateTexture( _kuWidth, _kuHeight, 0, D3DUSAGE_RENDERTARGET, pFormats[_keFMT], D3DPOOL_DEFAULT, &pTexture, 0 ) ) )
	{
		// no 
		// assert
		assert_now( "Failed to texture!" );
		return NULL;
	}

	return new CDX9Texture( pTexture, CDX9Renderer::GetDevice( ) ) ;
}
//-----------------------------------------------------------------------------
// paint it!
//-----------------------------------------------------------------------------
void CVMTPanel::OnPaint3D()
{
	if (!m_pMaterial)
		return;

	// Deal with refraction
	if ( m_pMaterial->NeedsPowerOfTwoFrameBufferTexture() )
	{
		ITexture *pTexture = GetPowerOfTwoFrameBufferTexture();
		if ( pTexture && !pTexture->IsError() )
		{
			CMatRenderContextPtr pRenderContext( MaterialSystem() );
			pRenderContext->CopyRenderTargetToTexture( pTexture );
			pRenderContext->SetFrameBufferCopyTexture( pTexture );
		}
	}

	// Draw a background (translucent objects will appear that way)

	// FIXME: Draw the outline of this panel?

//	pRenderContext->CullMode(MATERIAL_CULLMODE_CCW);

	RenderSphere( vec3_origin, SPHERE_RADIUS, 20, 20 );
	/*
	pRenderContext->MatrixMode( MATERIAL_PROJECTION );
	pRenderContext->LoadIdentity();
	pRenderContext->Ortho( 0, 0, m_iViewableWidth, m_iViewableHeight, 0, 1 );

	pRenderContext->Bind( m_pMaterial );
	IMesh *pMesh = pRenderContext->GetDynamicMesh();
	CMeshBuilder meshBuilder;

	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	if (!m_bUseActualSize)
	{
		DrawStretchedToPanel( meshBuilder );
	}
	else
	{
		DrawActualSize( meshBuilder );
	}

	meshBuilder.End();
	pMesh->Draw();
	*/
}
		const IntSize& getTextureSize(const std::string& _texture, bool _cache)
		{
			static std::string prevTexture;
			static IntSize prevSize;

			if (prevTexture == _texture && _cache)
				return prevSize;

			prevTexture.clear();
			prevSize.clear();

			if (_texture.empty())
				return Constants::getZeroIntSize();

			RenderManager& render = RenderManager::getInstance();

			ITexture* texture = render.getTexture(_texture);
			if (texture == nullptr)
			{
				if (!DataManager::getInstance().isDataExist(_texture))
				{
					MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
					return Constants::getZeroIntSize();
				}
				else
				{
					texture = render.createTexture(_texture);
					if (texture == nullptr)
					{
						MYGUI_LOG(Error, "Texture '" + _texture + "' not found");
						return Constants::getZeroIntSize();
					}
					texture->loadFromFile(_texture);
				}
			}

			prevSize = IntSize(texture->getWidth(), texture->getHeight());
			prevTexture = _texture;

#if MYGUI_DEBUG_MODE == 1
			if (!Bitwise::isPO2(prevSize.width) || !Bitwise::isPO2(prevSize.height))
			{
				MYGUI_LOG(Warning, "Texture '" + _texture + "' have non power of two size");
			}
#endif

			return prevSize;
		}
//------------------------------------------------------------------------------
// CExampleEffect render
//------------------------------------------------------------------------------
void CExampleEffect::Render( int x, int y, int w, int h )
{
	if ( !IsEnabled() )
		return;

	// Render Effect
	Rect_t actualRect;
	UpdateScreenEffectTexture( 0, x, y, w, h, false, &actualRect );
	ITexture *pTexture = GetFullFrameFrameBufferTexture( 0 );

	CMatRenderContextPtr pRenderContext( materials );

	pRenderContext->DrawScreenSpaceRectangle( m_Material, x, y, w, h,
											actualRect.x, actualRect.y, actualRect.x+actualRect.width-1, actualRect.y+actualRect.height-1, 
											pTexture->GetActualWidth(), pTexture->GetActualHeight() );
}
// ***************************************************************************
void			IDriver::getTextureShareName (const ITexture& tex, string &output)
{
	// Create the shared Name.
	output= toLower(tex.getShareName());

	// append format Id of the texture.
	static char	fmt[256];
	smprintf(fmt, 256, "@Fmt:%d", (uint32)tex.getUploadFormat());
	output+= fmt;

	// append mipmap info
	if(tex.mipMapOn())
		output+= "@MMp:On";
	else
		output+= "@MMp:Off";
}
示例#9
0
INLINE void OGL14RendererDevice::UploadData(void *userData)
{
	RendererPacket *packet = static_cast<RendererPacket *>(userData);

	ITexture *texture = packet->pTexture;
	GLuint *t = static_cast<GLuint *>(texture->GetTextureName());
	GLuint tex = (GLuint)t;

	sVertex *data = static_cast<sVertex *>(packet->pVertexData);

	glPushMatrix();
	glLoadIdentity();

	this->SetBlendingOperation(packet->nBlendMode, packet->iColor.pixel);

	glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

/*
	eTextureFilter min = texture->GetFilter(Seed::TextureFilterTypeMin);
	eTextureFilter mag = texture->GetFilter(Seed::TextureFilterTypeMag);

	if (min == Seed::TextureFilterLinear)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	else if (min == Seed::TextureFilterNearest)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	if (mag == Seed::TextureFilterLinear)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	else if (mag == Seed::TextureFilterNearest)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
*/

	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glBegin(this->GetOpenGLMeshType(packet->nMeshType));
	for (u32 i = 0; i < packet->iSize; i++)
	{
		glTexCoord2f(data[i].cCoords.x, data[i].cCoords.y);
		glVertex3f(data[i].cVertex.x, data[i].cVertex.y, data[i].cVertex.z);
	}
	glEnd();

	glPopMatrix();
}
示例#10
0
void CPupilProxy::OnBind( C_BaseEntity *pBaseEntity )
{
	if (!pBaseEntity || !m_pAnimatedTextureVar )
		return;

	if( m_pAnimatedTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE )
		return;

	ITexture *pTexture = m_pAnimatedTextureVar->GetTextureValue();
	int nFrameCount = pTexture->GetNumAnimationFrames();

	// Compute the lighting at the eye position of the entity; use it to dialate the pupil
	Vector forward;
	pBaseEntity->GetVectors( &forward, NULL, NULL );

	Vector eyePt = pBaseEntity->EyePosition();
	Vector color;
	engine->ComputeLighting( eyePt, &forward, false, color );

	// Compute the intensity...
	float flIntensity = ( 0.299f * color[0] + 0.587f * color[1] + 0.114f * color[2] ) * 0.5;
	flIntensity = clamp( flIntensity, 0, 1 );
	float flLastIntensity = m_pLightingVar->GetFloatValue( );
	if ( flIntensity > flLastIntensity )
	{
		float flMaxChange = m_flPupilCloseRate.GetFloat() * gpGlobals->frametime;
		if ( flIntensity > (flMaxChange + flLastIntensity) )
		{
			flIntensity = flLastIntensity + flMaxChange;
		}
	}
	else
	{
		float flMaxChange = m_flPupilOpenRate.GetFloat() * gpGlobals->frametime;
		if ( flIntensity < (flLastIntensity - flMaxChange) )
		{
			flIntensity = flLastIntensity - flMaxChange;
		}
	}

	int nFrame = nFrameCount * flIntensity;
	nFrame = clamp( nFrame, 0, nFrameCount - 1 );

	m_pAnimatedTextureFrameNumVar->SetIntValue( nFrame );
	m_pLightingVar->SetFloatValue( flIntensity );
}
void CUIDraw::GetTextureSize(int iTextureID,float &rfSizeX,float &rfSizeY)
{
	TTexturesMap::iterator Iter = m_texturesMap.find(iTextureID);
	if(Iter != m_texturesMap.end())
	{
		ITexture *pTexture = (*Iter).second;
		rfSizeX = (float) pTexture->GetWidth	();
		rfSizeY = (float) pTexture->GetHeight	();
	}
	else
	{
		// Unknow texture !
		CRY_ASSERT(0);
		rfSizeX = 0.0f;
		rfSizeY = 0.0f;
	}
}
void CTextureSystem::OnFileChange( const char *pFilename, int context, CTextureSystem::EFileType eFileType )
{
	// It requires the forward slashes later...
	char fixedSlashes[MAX_PATH];
	V_StrSubst( pFilename, "\\", "/", fixedSlashes, sizeof( fixedSlashes ) );	

	// Get rid of the extension.
	if ( V_strlen( fixedSlashes ) < 5 )
	{
		Assert( false );
		return;
	}
	fixedSlashes[ V_strlen( fixedSlashes ) - 4 ] = 0;


	// Handle it based on what type of file we've got.
	if ( eFileType == k_eFileTypeVMT )
	{
		IEditorTexture *pTex = FindActiveTexture( fixedSlashes, NULL, FALSE );
		if ( pTex )
		{
			pTex->Reload( true );
		}
		else
		{
			EnumMaterial( fixedSlashes, context );
			IEditorTexture *pTex = FindActiveTexture( fixedSlashes, NULL, FALSE );
			if ( pTex )
			{
				GetMainWnd()->m_TextureBar.NotifyNewMaterial( pTex );
				GetMainWnd()->GetFaceEditSheet()->NotifyNewMaterial( pTex );
			}
		}
	}
	else if ( eFileType == k_eFileTypeVTF )
	{
		// Whether a VTF was added, removed, or modified, we do the same thing.. refresh it and any materials that reference it.
		ITexture *pTexture = materials->FindTexture( fixedSlashes, TEXTURE_GROUP_UNACCOUNTED, false );
		if ( pTexture )
		{
			pTexture->Download( NULL );
			ReloadMaterialsUsingTexture( pTexture );
		}
	}
}
示例#13
0
ZombieLeader::~ZombieLeader()
{
    delete m_pStateMachine;

    // remove this scene node from parent
    m_p2DSprite->remove();

    // release texture resource
    IVideoDriver* pDriver = IrrDvc.GetDriver();
    ITexture* pTexture = pDriver->getTexture(ZOMBIELEADER_TEXTUREFILENAME);
    if (pTexture)
    {
        pTexture->drop();
    }

    // remove physics model - it will be deleted in parents
    //delete m_pZombiePhaysics;
}
示例#14
0
void CZZMaterialProxy::Release()
{
	// Disconnect the texture regenerator...
	if (m_pTexture)
	{
		//ITexture *pTexture = m_pTextureVar->GetTextureValue(); <- powoduje access violation
		if (m_pTexture)
			m_pTexture->SetTextureRegenerator(NULL);
	}
}
示例#15
0
nau::material::ITexture* 
ResourceManager::addTexture (std::vector<std::string> &filenames, std::string &label, bool mipmap) {

	size_t siz = m_Textures.size();
	ITexture *tex;

	for (unsigned int i = 0; i < siz; i++) {
		tex = m_Textures[i];
		if (label == tex->getLabel()) {
			return(tex);
		}
	}

	// if the texture does not exist yet
	tex = ITextureCubeMap::Create (filenames, label, mipmap);
	m_Textures.push_back(tex);

	return(tex);
}
void C_AwesomiumBrowserManager::OnCreateWebViewDocumentReady(WebView* pWebView, std::string id)
{
	// The master webview has created a new webview on demand.
	DevMsg("AwesomiumBrowserManager: OnCreateWebViewDocumentReady: %s\n", id.c_str());

	// TODO: Add global JS API object to the web view.

	//C_WebTab* pWebTab = g_pAnarchyManager->GetWebManager()->FindWebTab(id);
	C_AwesomiumBrowserInstance* pBrowserInstance = this->FindAwesomiumBrowserInstance(id);
	if (pBrowserInstance)
	{
		pBrowserInstance->SetWebView(pWebView);
		pBrowserInstance->SetState(2);
		//m_webViews[pBrowserInstance] = pWebView;	// obsolete perhaps??
		
		ITexture* pTexture = pBrowserInstance->GetTexture();
		if (pTexture && pTexture->GetImageFormat() == IMAGE_FORMAT_BGRA8888)
			pWebView->SetTransparent(true);

		std::string initialURI = pBrowserInstance->GetInitialURL();
		std::string uri = initialURI;
		//if (id == "network")
	//		uri = initialURI;
		//else if (id == "images")
		//	uri = initialURI;	// this should never happen, so comment it out to avoid confusion
			//uri = "asset://ui/imageLoader.html";
		//else if (id == "hud")
		//	uri = initialURI;
			//uri = (initialURI == "") ? "asset://ui/default.html" : initialURI;	// this should never happen, so comment it out to avoid confusion
		//else
	//		uri = initialURI;

		DevMsg("Loading initial URL: %s\n", uri.c_str());
		pWebView->LoadURL(WebURL(WSLit(uri.c_str())));
		/*
		if (id == "hud" )	// is this too early??
			g_pAnarchyManager->IncrementState();
		else if (id == "images" && AASTATE_AWESOMIUMBROWSERMANAGERIMAGESWAIT)
			g_pAnarchyManager->IncrementState();
		*/
	}
}
//-----------------------------------------------------------------------------
// Does the dirty deed
//-----------------------------------------------------------------------------
void CBaseToggleTextureProxy::OnBind( void *pC_BaseEntity )
{
	assert ( m_TextureVar );

	if (!pC_BaseEntity)
		return;

	if( m_TextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE )
	{
		return;
	}

	ITexture *pTexture = NULL;

	pTexture = m_TextureVar->GetTextureValue();

	if ( pTexture == NULL )
		 return;

	C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );

	if ( pEntity == NULL )
		 return;
	
	int numFrames = pTexture->GetNumAnimationFrames();
	int frame = pEntity->GetTextureFrameIndex();

	int intFrame = ((int)frame) % numFrames; 

	if ( m_WrapAnimation == false )
	{
		if ( frame > numFrames )
			 intFrame = numFrames;
	}
		
	m_TextureFrameNumVar->SetIntValue( intFrame );

	if ( ToolsEnabled() )
	{
		ToolFramework_RecordMaterialParams( GetMaterial() );
	}
}
示例#18
0
Human::~Human()
{
	if(m_pStateMachine != NULL)
		delete m_pStateMachine;	
	
	// remove this scene node from parent
	if(m_p2DSprite != NULL)
		m_p2DSprite->remove();

	// release texture resource
	IVideoDriver* pDriver = IrrDvc.GetDriver();
	ITexture* pTexture = pDriver->getTexture(HUMAN_TEXTUREFILENAME);
	if (pTexture)
	{
		pTexture->drop();
	}

	// remove physics model
	delete m_pHumanPhaysics;
}
示例#19
0
void CCrowdTextureProxy::OnBind( void *pEntity )
{
	Assert ( m_AnimatedTextureVar );

	if( m_AnimatedTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE )
	{
		return;
	}

	ITexture *pTexture;
	pTexture = m_AnimatedTextureVar->GetTextureValue();
	int numFrames = pTexture->GetNumAnimationFrames();

	if ( numFrames <= 0 )
	{
		Assert( !"0 frames in material calling animated texture proxy" );
		return;
	}

	// NOTE: Must not use relative time based methods here
	// because the bind proxy can be called many times per frame.
	// Prevent multiple Wrap callbacks to be sent for no wrap mode

	if (SDKGameRules())
		m_FrameRate = max(0, (int)(30 * abs(SDKGameRules()->m_nBallZone) / 100.0f));
	else
		m_FrameRate = 0;

	if (m_nFrameCount != gpGlobals->framecount)
	{
		m_nFrameCount = gpGlobals->framecount;
		m_flFrame = fmod(m_flFrame + m_FrameRate * gpGlobals->frametime, numFrames);
	}

	m_AnimatedTextureFrameNumVar->SetIntValue( (int)m_flFrame );

	if ( ToolsEnabled() )
	{
		ToolFramework_RecordMaterialParams( GetMaterial() );
	}
}
示例#20
0
文件: interface.cpp 项目: lymber/tdm
//---------------------------------------------------------------------------------------
//Converte uma textura para o tamanho da tela, partindo do que seria 800x600
video::ITexture* Interface::LeTexturaConvertida(const c8 *filename)
{
   IImage *temp = central->Device()->getVideoDriver()->createImageFromFile(filename);

   if (temp == NULL) return NULL; //deu pau
   core::dimension2di tamanhoOriginal = temp->getDimension();
      
   //calculo qual deveria ser o tamanho
   core::dimension2di novoTamanho(ConverteX(tamanhoOriginal.Width), ConverteY(tamanhoOriginal.Height));
   ITexture* buf = central->Device()->getVideoDriver()->addTexture(novoTamanho, "Texture"); 
   IImage *nova = central->Device()->getVideoDriver()->createImageFromData(temp->getColorFormat(), novoTamanho, buf->lock());
   buf->unlock();
   temp->copyToScaling(nova);
      
   ITexture *retorno = central->Device()->getVideoDriver()->addTexture(filename, nova);

   nova->drop();
   //free(buffer);
   
   return retorno;   
} 
示例#21
0
FugitivePlayer::~FugitivePlayer()
{
	delete m_pStateMachine;
	delete m_pRushLine ;
	for(int i=0; i < WEAPON_INVENTORY_NUM ; i++)
	{
		if(m_pWeapon[i])
			delete 	m_pWeapon[i];
	}
	
	// remove this scene node from parent
	m_p2DSprite->remove();

	// release texture resource
	IVideoDriver* pDriver = IrrDvc.GetDriver();
	ITexture* pTexture = pDriver->getTexture("Rsrc/hero.tga");
	if (pTexture)
	{
		pTexture->drop();		
	}
}
示例#22
0
/**	Add an animation frame
 *
 *	@param tr A Rect object containing the texture coordinates for another animation frame
 *
 *	Operation:
 *		-#	Retrieve a pointer to the texture for this overlay
 *		-#	Find it's dimensions
 *		-#	Precalculate a scale value to convert 0->max to 0->1 so you can specify the rectangle in pixels, but convert them into texture coordinates
 *		-#	Convert the rectangle passed into the method into texture coordinates
 *		-#	Invert the y coordinates of the texture coordinates (rectangles are specified where 
 *				the origin is the top left, but texture coordinates specify the origin as the bottom left (hence why the y must be inverted)
 *		-#	Stores the texture coordinates generated, sets the default animation frame to be the first frame
 */
void Overlay::AddFrame(Rect *tr)
{
	int		x,y;
	float	tw,th;

	ITexture *t = m_vertexbuffer[0]->GetTexture();

	if(t != NULL){
		t->GetDimensions(x,y);
		
		tw = (float)x;
		th = (float)y;

		tw = 1/tw;
		th = 1/th;

		if(tr == NULL) tr = new Rect(0,0,x,y);
		
		//	Assign default texture coords
		Vertex2f *texcoords = new Vertex2f[4];

		texcoords[0].x	=	tw*tr->left;
		texcoords[0].y	=	th*tr->top;

		texcoords[1].x	=	tw*tr->left;
		texcoords[1].y	=	th*tr->bottom;

		texcoords[2].x	=	tw*tr->right;
		texcoords[2].y	=	th*tr->bottom;

		texcoords[3].x	=	tw*tr->right;
		texcoords[3].y	=	th*tr->top;

		//	Store the texture coords and set the default frame to zero
		m_texcoords.push_back(texcoords);
		SetFrame(0);
	}

	delete tr;
}
示例#23
0
INLINE void OGLES1RendererDevice::UploadData(void *userData)
{
	RendererPacket *packet = static_cast<RendererPacket *>(userData);

	ITexture *texture = packet->pTexture;
	GLuint *t = static_cast<GLuint *>(texture->GetTextureName());
	GLuint tex = (GLuint)t;

	sVertex *data = static_cast<sVertex *>(packet->pVertexData);

	this->SetBlendingOperation(packet->nBlendMode, packet->iColor.pixel);

	sVertex v1 = data[0];
	sVertex v2 = data[1];
	sVertex v3 = data[2];
	sVertex v4 = data[3];

	glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	eTextureFilter min = texture->GetFilter(Seed::TextureFilterTypeMin);
	eTextureFilter mag = texture->GetFilter(Seed::TextureFilterTypeMag);

	if (min == Seed::TextureFilterLinear)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	else if (min == Seed::TextureFilterNearest)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	if (mag == Seed::TextureFilterLinear)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	else if (mag == Seed::TextureFilterNearest)
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	glVertexPointer(3, GL_FLOAT, sizeof(sVertex), &data[0].cVertex);
	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(sVertex), &data[0].iColor);
	glTexCoordPointer(2, GL_FLOAT, sizeof(sVertex), &data[0].cCoords);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, packet->iSize);
}
int CUIDraw::CreateTexture(const char *strName, bool dontRelease)
{
	for(TTexturesMap::iterator iter=m_texturesMap.begin(); iter!=m_texturesMap.end(); ++iter)
	{
		if(0 == strcmpi((*iter).second->GetName(),strName))
		{
			return (*iter).first;
		}
	}
	uint32 flags = FT_NOMIPS|FT_DONT_RESIZE|FT_DONT_STREAM|FT_STATE_CLAMP;
	if (dontRelease)
	{
		GameWarning("Are you sure you want to permanently keep this UI texture '%s'?!", strName);
	}
	
	flags |= dontRelease ? FT_DONT_RELEASE : 0;
	ITexture *pTexture = m_pRenderer->EF_LoadTexture(strName,flags);
	pTexture->SetClamp(true);
	int iTextureID = pTexture->GetTextureID();
	m_texturesMap.insert(std::make_pair(iTextureID,pTexture));
	return iTextureID;
}
示例#25
0
void draw_pp_shader( const CViewSetup &view, IMaterial *pMaterial)
{
	int x = view.x;
	int y = view.y;
	int w = view.width;
	int h = view.height;

	Rect_t actualRect;
	UpdateScreenEffectTexture( 0, x, y, w, h, false, &actualRect);
	int u1 = actualRect.x;
	int v1 = actualRect.y;
	int u2 = actualRect.x+actualRect.width-1;
	int v2 = actualRect.y+actualRect.height-1;

	ITexture *pTexture = GetFullFrameFrameBufferTexture( 0 );
	int aw = pTexture->GetActualWidth();
	int ah = pTexture->GetActualHeight();

	CMatRenderContextPtr pRenderContext( materials );
	pRenderContext->DrawScreenSpaceRectangle( pMaterial, x, y, w, h, u1, v1, u2, v2, aw, ah );
	pRenderContext.SafeRelease();
}
示例#26
0
//! creates a Texture
ITexture* CNullDriver::addTexture(const dimension2d<u32>& size,
				  const path& name, ECOLOR_FORMAT format)
{
	if(IImage::isRenderTargetOnlyFormat(format))
	{
		Printer::log("Could not create ITexture, format only supported for render target textures.", ELL_WARNING);
		return 0;
	}

	if ( 0 == name.size () )
		return 0;

	IImage* image = new CImage(format, size);
	ITexture* t = createDeviceDependentTexture(image, name);
	image->releaseRef();
	addTexture(t);

	if (t)
		t->releaseRef();

	return t;
}
示例#27
0
// ----------------------------------------------------------------------------
void Track::exportElements(std::ofstream& stream, bool obj)
{
    ISceneManager* sm = Editor::getEditor()->getSceneManager();
    ISceneNode* node;
    stringc name;
    int i = 1;
    while ((node = sm->getSceneNodeFromId(MAGIC_NUMBER + i)))
    {
        name = node->getName();
        vector3df pos, rot, sca;
        if (node->isVisible() && name != "banana" && name != "item"
            && name != "small-nitro" && name != "big-nitro"
            && (name.equalsn("obj/", 4) == obj))
        {
            pos = node->getPosition();
            rot = node->getRotation();
            sca = node->getScale();
            if (name.equalsn("obj/", 4))
            {
                stream << "    <static-object model=\"" << Editor::toRelative(name).c_str();
                copyObj(name);

                ITexture* tex;
                for (int j = 0; (tex = node->getMaterial(0).getTexture(j)); j++)
                    copyObj(stringc("obj/") + Editor::toRelative(tex->getName()));
            } // export as static-object
            else
            {
                stream << "  <library name=\"" << Editor::getLib(node->getName()).c_str();
            } // export as library
            stream << "\" xyz=\"";
            stream << pos.X << " " << pos.Y << " " << pos.Z << "\" hpr=\"";
            stream << rot.X << " " << rot.Y << " " << rot.Z << "\" scale=\"";
            stream << sca.X << " " << sca.Y << " " << sca.Z << "\"/>\n";
        }
        i++;
    }
} // exportElements
void VFSPlugin_Q2BSP::AssignTextureCoords(IVertexBuffer *vb)
{
	int					a,b;
	Mesh				*m	=	m_fileinfo->mesh;
	Vertex3f		*v	=	m->GetPosition();
	Vertex2f		*tc	=	NULL;
	BSPTexInfo	*ti	=	NULL;
	int					*i	= vb->GetIndex();

	if((tc = (Vertex2f *)m->GetTexcoord()) == NULL){
		tc = new Vertex2f[m->GetNumVertex()];
		memset(tc,0,m->GetNumVertex()*sizeof(Vertex2f));
		m->SetTexcoord(tc);
	}

	for(a=0;a<m_numtexinfo;a++){
		ti = &m_texinfo[a];

		if(strcmp(vb->GetName(),ti->name) == 0){
			Maths::Vector tu_vec(ti->u_axis);
			Maths::Vector tv_vec(ti->v_axis);

			ITexture *texture = vb->GetTexture();

			for(b=0;b<vb->GetNumIndex();b++){
				Maths::Vector vec(v[i[b]]);
				
				tc[i[b]].x	=	( vec.DotProduct(tu_vec) + ti->u_offset) / texture->GetWidth();
				tc[i[b]].y	=	( vec.DotProduct(tv_vec) + ti->v_offset) / texture->GetHeight();
			}
		}
	}

	//for(a=0;a<m->GetNumVertex();a++)	logfile << "texcoord["<<a<<"] = { " << tc[a].x << ", " << tc[b].y << " };" << std::endl;

//	vb->SetTexcoord((float *)tc);
	vb->SetTextureLayer(0,(float *)tc,vb->GetTexture());
}
//-----------------------------------------------------------------------------
// Paints the texture
//-----------------------------------------------------------------------------
void CVMTPreviewPanel::Paint( void )
{
	CMatRenderContextPtr pRenderContext( MaterialSystem() );
	int w, h;
	GetSize( w, h );
	vgui::MatSystemSurface()->Begin3DPaint( 0, 0, w, h );

	// Deal with refraction
	if ( m_Material->NeedsPowerOfTwoFrameBufferTexture() )
	{
		ITexture *pTexture = GetPowerOfTwoFrameBufferTexture();
		if ( pTexture && !pTexture->IsError() )
		{
			pRenderContext->CopyRenderTargetToTexture( pTexture );
			pRenderContext->SetFrameBufferCopyTexture( pTexture );
		}
	}

	pRenderContext->ClearColor4ub( 76, 88, 68, 255 ); 
	pRenderContext->ClearBuffers( true, true );
	 			   
	pRenderContext->FogMode( MATERIAL_FOG_NONE );
	pRenderContext->SetNumBoneWeights( 0 );
	pRenderContext->Bind( m_Material );
 	pRenderContext->BindLightmapTexture( m_pLightmapTexture );
	pRenderContext->BindLocalCubemap( m_DefaultEnvCubemap );

	if ( m_bDrawIn3DMode || m_Material->IsSpriteCard() )
	{
		DrawSphere();
	}
	else
	{
		DrawRectangle();
	}

	vgui::MatSystemSurface()->End3DPaint( );
}
示例#30
0
/**	Creates an Image based Texture
 *
 *	@param image	The filename containing the image to use as a texture
 *
 *	@returns An ITexture object or NULL if texture failed to create
 *
 *	Operation:
 *		-#	If the number of textures is zero, enable GL_TEXTURE_COORD_ARRAY
 *		-#	Loop through the current existing textures and attempt to find
 *				a copy of the texture you are attempting to load
 *		-#	If a copy is found, return an ITexture pointer to that texture
 *		-#	If the texture is not found, Create a new ImageTexture object
 *		-#	Update the texture (this will load the image contents into the opengl texture object)
 *		-#	Store the texture pointer
 *		-#	Return the texture pointer
 */
ITexture * OGLGraphics::CreateTexture(std::string image)
{
	ITexture *texture = NULL;
	
	for(unsigned int a=0;a<Textures.size();a++){
		std::string test = Textures[a]->m_filename;

		if(image == test)	texture = Textures[a];
	}
	
	if(texture == NULL){
		texture	= new OGLImageTexture(image);

		if(texture->UpdateTexture() >= 0){
			Textures.push_back(texture);
		}else{
			delete texture;
			texture = NULL;
		}
	}

	return texture;
}