CUnit3DLoader::UnitModel* CUnit3DLoader::GetModel(string name,int team)
{
	char c[50];
	sprintf(c,"team%d_",team);
	string modname=string(c)+name;

	map<string,UnitModel*>::iterator ui;
	if((ui=models.find(modname))!=models.end())
			return ui->second;
	
	if(texturehandler==0)
		texturehandler=new CTextureHandler;

	UnitModel* model=new UnitModel;

	model->team=team;
	model->name=name;

	Parse(name,*model);
	CreateNormals(*model);
	CreateDispList(*model);
	for(std::vector<UnitModel*>::iterator umi=model->subModels.begin();umi!=model->subModels.end();++umi)
		CreateDispList(**umi);
	CreateFarTexture(*model);

	models[modname]=model;
	return model;
}
Esempio n. 2
0
void CFarTextureHandler::Draw()
{
	if (queuedForRender.empty()) {
		return;
	}

	if (!fbo.IsValid()) {
		queuedForRender.clear();
		return;
	}

	// create new far-icons
	for (GML_VECTOR<const CSolidObject*>::iterator it = queuedForRender.begin(); it != queuedForRender.end(); ++it) {
		const CSolidObject* obj = *it;
		if (!HaveFarIcon(obj)) {
			CreateFarTexture(obj);
		}
	}

	// render current queued far icons on the screen
	{
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.5f);
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, farTextureID);
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
		glNormal3fv((const GLfloat*) &unitDrawer->camNorm.x);

		ISky::SetupFog();

		CVertexArray* va = GetVertexArray();
		va->Initialize();
		va->EnlargeArrays(queuedForRender.size() * 4, 0, VA_SIZE_T);
		for (GML_VECTOR<const CSolidObject*>::iterator it = queuedForRender.begin(); it != queuedForRender.end(); ++it) {
			DrawFarTexture(*it, va);
		}

		va->DrawArrayT(GL_QUADS);
		glDisable(GL_ALPHA_TEST);
	}

	queuedForRender.clear();
}
Esempio n. 3
0
void CFarTextureHandler::Draw()
{
	if (queuedForRender.empty()) {
		return;
	}

	//! create new faricons
	for (GML_VECTOR<const CSolidObject*>::iterator it = queuedForRender.begin(); it != queuedForRender.end(); ++it) {
		const CSolidObject& obj = **it;
		if (cache.size()<=obj.team || cache[obj.team].size()<=obj.model->id || !cache[obj.team][obj.model->id]) {
			CreateFarTexture(*it);
		}
	}

	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.5f);
	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, farTexture);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glNormal3fv((const GLfloat*) &unitDrawer->camNorm.x);

	if (globalRendering->drawFog) {
		glFogfv(GL_FOG_COLOR, mapInfo->atmosphere.fogColor);
		glEnable(GL_FOG);
	}

	CVertexArray* va = GetVertexArray();
	va->Initialize();
	va->EnlargeArrays(queuedForRender.size() * 4, 0, VA_SIZE_T);
	for (GML_VECTOR<const CSolidObject*>::iterator it = queuedForRender.begin(); it != queuedForRender.end(); ++it) {
		DrawFarTexture(*it, va);
	}

	va->DrawArrayT(GL_QUADS);
	glDisable(GL_ALPHA_TEST);

	queuedForRender.clear();
}
Esempio n. 4
0
void CFarTextureHandler::Draw()
{
	if (queuedForRender.empty()) {
		return;
	}

	{
		// check if there is enough free space in the atlas, if not try resizing
		// it (as many times as the number of models queued for iconification)
		unsigned int maxNewIcons = 0;

		for (unsigned int n = 0; n < queuedForRender.size(); n++) {
			if (!CheckResizeAtlas(n + 1)) { break; } maxNewIcons++;
		}

		// now create the new far-icons
		// NOTE:
		//    the icons are RTT'ed using a snapshot of the
		//    current state (advModelShading, sunDir, etc)
		//    and will not track later state-changes
		unitDrawer->SetupForUnitDrawing();

		GML_VECTOR<const CSolidObject*>::iterator it;

		for (it = queuedForRender.begin(); it != queuedForRender.end() && maxNewIcons > 0; ++it) {
			maxNewIcons--;

			const CSolidObject* obj = *it;
			const S3DModel* mdl = obj->model;

			unitDrawer->GetOpaqueModelRenderer(mdl->type)->PushRenderState();
			unitDrawer->SetTeamColour(obj->team);

			if (mdl->type != MODELTYPE_3DO) {
				texturehandlerS3O->SetS3oTexture(mdl->textureType);
			}

			if ((int)cache.size() <= obj->team || (int)cache[obj->team].size() <= mdl->id || !cache[obj->team][mdl->id]) {
				CreateFarTexture(obj);
			}

			unitDrawer->GetOpaqueModelRenderer(mdl->type)->PopRenderState();
		}

		unitDrawer->CleanUpUnitDrawing();
	}

	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.5f);
	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, farTextureID);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glNormal3fv((const GLfloat*) &unitDrawer->camNorm.x);

	ISky::SetupFog();

	CVertexArray* va = GetVertexArray();
	va->Initialize();
	va->EnlargeArrays(queuedForRender.size() * 4, 0, VA_SIZE_T);
	for (GML_VECTOR<const CSolidObject*>::iterator it = queuedForRender.begin(); it != queuedForRender.end(); ++it) {
		DrawFarTexture(*it, va);
	}

	va->DrawArrayT(GL_QUADS);
	glDisable(GL_ALPHA_TEST);

	queuedForRender.clear();
}