bool LoadDrawable::operator()(
	const std::string & meshname,
	const std::vector<std::string> & texname,
	const PTree & cfg,
	SCENENODE & topnode,
	keyed_container<SCENENODE>::handle * nodeptr,
	keyed_container<DRAWABLE>::handle * drawptr)
{
	DRAWABLE drawable;

	// set textures
	TEXTUREINFO texinfo;
	texinfo.mipmap = true;
	texinfo.anisotropy = anisotropy;
	std::tr1::shared_ptr<TEXTURE> tex;
	if (texname.size() == 0)
	{
		error << "No texture defined" << std::endl;
		return false;
	}
	if (texname.size() > 0)
	{
		if (!content.load(path, texname[0], texinfo, tex)) return false;
		drawable.SetDiffuseMap(tex);
	}
	if (texname.size() > 1)
	{
		if (!content.load(path, texname[1], texinfo, tex)) return false;
		drawable.SetMiscMap1(tex);
	}
	if (texname.size() > 2)
	{
		if (!content.load(path, texname[2], texinfo, tex)) return false;
		drawable.SetMiscMap2(tex);
	}

	// set mesh
	std::tr1::shared_ptr<MODEL> mesh;
	if (!content.load(path, meshname, mesh)) return false;

	std::string scalestr;
	if (cfg.get("scale", scalestr) &&
		!content.get(path, meshname + scalestr, mesh))
	{
		MATHVECTOR<float, 3> scale;
		std::stringstream s(scalestr);
		s >> scale;

		VERTEXARRAY meshva = mesh->GetVertexArray();
		meshva.Scale(scale[0], scale[1], scale[2]);
		content.load(path, meshname + scalestr, meshva, mesh);
	}
Beispiel #2
0
void TEXT_DRAW::SetText(
	DRAWABLE & draw,
	const FONT & font, const std::string & text,
	float x, float y, float scalex, float scaley,
	float r, float g, float b,
	VERTEXARRAY & output_array)
{
	RenderText(font, text, x, y, scalex, scaley, output_array);
	draw.SetDiffuseMap(font.GetFontTexture());
	draw.SetVertArray(&output_array);
	draw.SetCull(false, false);
	draw.SetColor(r, g, b, 1.0);
}
///returns true if the object was culled and should not be drawn
bool RENDER_INPUT_SCENE::FrustumCull(DRAWABLE & tocull)
{
	//return false;

	DRAWABLE * d (&tocull);
	//if (d->GetRadius() != 0.0 && d->parent != NULL && !d->skybox)
	if (d->GetRadius() != 0.0 && !d->GetSkybox() && d->GetCameraTransformEnable())
	{
		//do frustum culling
		MATHVECTOR <float, 3> objpos(d->GetObjectCenter());
		d->GetTransform().TransformVectorOut(objpos[0],objpos[1],objpos[2]);
		float dx=objpos[0]-cam_position[0]; float dy=objpos[1]-cam_position[1]; float dz=objpos[2]-cam_position[2];
		float rc=dx*dx+dy*dy+dz*dz;
		float temp_lod_far = lod_far + d->GetRadius();
		if (rc > temp_lod_far*temp_lod_far)
			return true;
		else if (rc < d->GetRadius()*d->GetRadius())
			return false;
		else
		{
			float bound, rd;
			bound = d->GetRadius();
			for (int i=0; i<6; i++)
			{
				rd=frustum.frustum[i][0]*objpos[0]+
						frustum.frustum[i][1]*objpos[1]+
						frustum.frustum[i][2]*objpos[2]+
						frustum.frustum[i][3];
				if (rd <= -bound)
				{
					return true;
				}
			}
		}
	}

	return false;
}
void RENDER_INPUT_SCENE::DrawList(GLSTATEMANAGER & glstate, std::vector <DRAWABLE*> & drawlist, bool preculled)
{
	unsigned int drawcount = 0;
	unsigned int loopcount = 0;

	for (vector <DRAWABLE*>::iterator ptr = drawlist.begin(); ptr != drawlist.end(); ptr++, loopcount++)
	{
		DRAWABLE * i = *ptr;
		if (preculled || !FrustumCull(*i))
		{
			drawcount++;

			SelectFlags(*i, glstate);

			if (shaders) SelectAppropriateShader(*i);

			SelectTexturing(*i, glstate);

			bool need_pop = SelectTransformStart(*i, glstate);

			//assert(i->GetDraw()->GetVertArray() || i->GetDraw()->IsDrawList() || !i->GetDraw()->GetLine().empty());

			if (i->IsDrawList())
			{
				// FLOW_VIS // 
				if (shader && shader->program == 4 && shader->vertex_shader == 5 && i->activeMVMatrix == 0) {
					shader->UploadAttributeMat16("oldModelViewMatrix", i->oldModelViewMatrix[i->activeMVMatrix]);
					//memcpy(i->oldModelViewMatrix, tmp_matrix, sizeof(float) * 16);
					glGetFloatv(GL_MODELVIEW_MATRIX, i->oldModelViewMatrix[i->activeMVMatrix]);
					i->activeMVMatrix = 1;
				}

				const unsigned int numlists = i->GetDrawLists().size();
				for (unsigned int n = 0; n < numlists; ++n)
					glCallList(i->GetDrawLists()[n]);
			}
			else if (i->GetVertArray())
			{
				const float * verts;
				int vertcount;
				i->GetVertArray()->GetVertices(verts, vertcount);
				if (vertcount > 0 && verts)
				{
					glVertexPointer(3, GL_FLOAT, 0, verts);
					glEnableClientState(GL_VERTEX_ARRAY);

					const int * faces;
					int facecount;
					i->GetVertArray()->GetFaces(faces, facecount);
					if (facecount > 0 && faces)
					{
						const float * norms;
						int normcount;
						i->GetVertArray()->GetNormals(norms, normcount);
						if (normcount > 0 && norms)
						{
							glNormalPointer(GL_FLOAT, 0, norms);
							glEnableClientState(GL_NORMAL_ARRAY);
						}

						const float * tc[1];
						int tccount[1];
						if (i->GetVertArray()->GetTexCoordSets() > 0)
						{
							i->GetVertArray()->GetTexCoords(0, tc[0], tccount[0]);
							if (tc[0] && tccount[0])
							{
								glEnableClientState(GL_TEXTURE_COORD_ARRAY);
								glTexCoordPointer(2, GL_FLOAT, 0, tc[0]);
							}
						}

						glDrawElements(GL_TRIANGLES, facecount, GL_UNSIGNED_INT, faces);
			
						glDisableClientState(GL_TEXTURE_COORD_ARRAY);
						glDisableClientState(GL_NORMAL_ARRAY);
					}
					else if (i->GetLineSize() > 0)
					{
						glstate.Enable(GL_LINE_SMOOTH);
						glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
						glLineWidth(i->GetLineSize());
						glDrawArrays(GL_LINES,  0, vertcount/3);
					}
					glDisableClientState(GL_VERTEX_ARRAY);
				}
			}
			SelectTransformEnd(*i, need_pop);
		}
	}
}