Example #1
0
bool GTextureMgr::Release()
{
	GTexture *pPoint;
	for (TemplateMapItor itor = TMap.begin(); itor != TMap.end(); itor++)
	{
		pPoint = (GTexture *)(*itor).second;
		pPoint->Release();
	}
	TMap.clear();
	return true;
}
Example #2
0
GTextureMgr::~GTextureMgr(void)
{
	GTexture *pPoint;
	for (TemplateMapItor itor = TMap.begin(); itor != TMap.end(); itor++)
	{
		pPoint = (GTexture *)(*itor).second;
		pPoint->Release();
		SAFE_DEL(pPoint);
	}
	TMap.clear();
	m_iCurIndex = 0;
}
Example #3
0
//-------------------------------------------------------------------------
//	draw texture 
//-------------------------------------------------------------------------
void GSkyBox::Draw(GCamera& Camera)
{
	//	get texture
	GTexture* pTexture = GAssets::g_Textures.Find(m_Texture);
	if ( !pTexture )
		return;

	float2& Min = Camera.m_OrthoMin;
	float2& Max = Camera.m_OrthoMax;

	glPushAttrib( GL_ALL_ATTRIB_BITS );
	
	glEnable(GL_TEXTURE_2D);
	pTexture->Select();

	float2 WorldVisibility = Camera.GetWorldVisibility();
	float2 WorldEnvMapScroll = Camera.GetEnvMapScroll();

	//GDebug_Print("%3.3f\n",skyscroll);
	
	//	only use "top half" of what would be an enviroment map
	WorldEnvMapScroll.y -= 0.5f;
	WorldVisibility.y *= 2.f;
	//if ( WorldEnvMapScroll.y < 0.f )
	//	WorldEnvMapScroll.y = 0.f;

	float skyxmin = WorldEnvMapScroll.x - ( WorldVisibility.x * 0.5f );
	float skyxmax = WorldEnvMapScroll.x + ( WorldVisibility.x * 0.5f );
	float skyymin = WorldEnvMapScroll.y - ( WorldVisibility.y * 0.5f );
	float skyymax = WorldEnvMapScroll.y + ( WorldVisibility.y * 0.5f );
	//float skyymin = 0.f;
	//float skyymax = 1.f;

	glColor3f( 1, 1, 1 );
	glBegin(GL_QUADS);

		glTexCoord2f( skyxmin, skyymin );
		glVertex3f( Min.x, Min.y, Camera.m_NearZ );
		
		glTexCoord2f( skyxmax, skyymin );
		glVertex3f( Max.x, Min.y, Camera.m_NearZ );

		glTexCoord2f( skyxmax, skyymax );
		glVertex3f( Max.x, Max.y, Camera.m_NearZ );

		glTexCoord2f( skyxmin, skyymax );
		glVertex3f( Min.x, Max.y, Camera.m_NearZ );

	glEnd();

	glPopAttrib();
}
int
FeatureStrokeTexture::read_gtexture(
   istream & is,
   str_list & leftover )
{
   // XXX much from Patch::read_gtexture()
   leftover.clear();
   const int namelen = 256;
   char name1[namelen];
   char name[namelen];
   char *wherecr;
   is.getline(name1, namelen); // Finish "#BEGIN GTEXTURE" line
   is.getline(name, namelen); // Get name of texture

   // Strip out CR
   // XXX - also in ViewStroke::read_stroke()
   while ((wherecr = strchr(name, '\015'))) {
      *wherecr = 0;
   }

   ARRAY<GTexture *> all_tex;
   all_tex += _sil_and_crease_tex;

   GTexture *tex = 0;
   Cstr_ptr &name_str = name;
   for (int i = 0; !tex && i< all_tex.num(); i++) {
      if (all_tex[i]->class_name() == name_str) {
         tex = all_tex[i];
      }
   }

   if (!tex) {
      err_mesg(ERR_LEV_WARN, "FeatureStrokeTexture::read_gtexture() - Warning! Texture subclasses not supported '%s'", name);

      tex = (GTexture*) DATA_ITEM::lookup(name);

      if (!tex) {
         err_mesg(ERR_LEV_ERROR, "FeatureStrokeTexture::read_gtexture() - Could not find GTexture '%s' (skipping)...", name);
         return 1;
      }
      if (!(tex = (GTexture*)tex->dup())) {
         err_mesg(ERR_LEV_ERROR, "FeatureStrokeTexture::find_gtexture() - tex->dup() returned nil");
         return -1;
      }
   }

   return tex->read_stream(is, leftover);
}
Example #5
0
//********************** DRAWING **********************
int
Patch::draw(CVIEWptr& v)
{
   GTexture* cur = cur_tex(v);
   if (!cur)
      return 0;

   // if we just switched GTextures then setup a fade from
   // the old one to the new one:
   static const double FADE_DUR = Config::get_var_dbl("FADE_DUR", 0.5,true);
   if (_prev_tex && _prev_tex != cur && _init_fade)
      (*_init_fade)(cur, _prev_tex, v->frame_time(), FADE_DUR);
   _prev_tex = cur;
   int ret = cur->draw(v);
   _pixels.clear();
   return ret;
}
Example #6
0
INT GTextureMgr::Add(ID3D11Device*	 pDevice, const TCHAR *pFileName)
{
	TCHAR szFileName[MAX_PATH];
	TCHAR Drive[MAX_PATH];
	TCHAR Dir[MAX_PATH];
	TCHAR FName[MAX_PATH];
	TCHAR Ext[MAX_PATH];
	if (pFileName)
	{
		_tsplitpath(pFileName, Drive, Dir, FName, Ext);
		Ext[4] = 0;
		memset(szFileName, 0, sizeof(TCHAR) * MAX_PATH);
		//D3DX11_IMAGE_FILE_FORMAT 
		if (_tcsicmp(Ext, _T(".tga")) == 0)
		{
			_tcscpy(Ext, _T(".bmp"));
		}
		_stprintf_s(szFileName, _T("%s%s"), FName, Ext);

		for (TemplateMapItor itor = TMap.begin(); itor != TMap.end(); itor++)
		{
			GTexture *pPoint = (GTexture *)(*itor).second;
			if (!_tcsicmp(pPoint->m_szName.c_str(), szFileName))
			{
				return (*itor).first;
			}
		}
	}
	GTexture *pPoint = NULL;
	SAFE_NEW(pPoint, GTexture);

	TCHAR szPath[MAX_PATH] = { 0, };
	_stprintf_s(szPath, _T("%s%s"), Drive, Dir);
	pPoint->SetPath(szPath);

	if (FAILED(pPoint->Load(pDevice, szFileName)))
	{
		return 0;
	}
	TMap.insert(make_pair(++m_iCurIndex, pPoint));
	return m_iCurIndex;
}
Example #7
0
/*!
 *  Returns a texture by class name.
 *  Finds one or gets one.
 *
 */
GTexture*
Patch::get_tex(const string& tex_name)
{

   // first try to find one
   GTexture* tex = find_tex(tex_name);
   if (tex)
      return tex;

   // if not found, instantiate it.
   tex = (GTexture*)DATA_ITEM::lookup(tex_name);
   if (!tex)
      return nullptr;        // can't look it up

   // got one of the right type, now duplicate it
   if ((tex = (GTexture*)tex->dup())) {
      tex->set_patch(this);
      _textures += tex;
      return tex;
   } else {
      err_msg("Patch::get_tex: tex->dup() returned nil");
      return nullptr;        // can't duplicate it
   }
}