Example #1
0
//----------------------------------------------------------------------------
RenderObject* Sample5::CreatePlane()
{
	const UInt tileXCount = 30;
	const UInt tileYCount = 20;
	const Float xSizeTotal = 12.0F;
	const Float ySizeTotal = 8.0F;
	RenderObject* pPlane = StandardMesh::CreatePlane(tileXCount, tileYCount,
		xSizeTotal, ySizeTotal, 0, 1, true);
	pPlane->GetMesh()->GenerateNormals();

	Texture2D* pTexture = CreateTexture();
	pTexture->SetWrapType(0, Texture2D::WT_REPEAT);
	pTexture->SetWrapType(1, Texture2D::WT_REPEAT);
	Material* pMaterial = WIRE_NEW Material;
	pMaterial->AddTexture(pTexture, Material::BM_MODULATE);
	pPlane->SetMaterial(pMaterial);

	// attach a material state and a light to the plane geometry directly
	StateMaterial* pStateMaterial = WIRE_NEW StateMaterial;
	pStateMaterial->Ambient = ColorRGBA(1, 1, 1, 1);
	pPlane->GetStates()[State::MATERIAL] = pStateMaterial;

	mspSpotLight = WIRE_NEW Light(Light::LT_SPOT);
	mspSpotLight->Position = Vector3F(0, 0, 10);
	mspSpotLight->Direction = Vector3F(0, 0, -1);
	mspSpotLight->Angle = 0.5F;
	mspSpotLight->Ambient = ColorRGB(0.2F, 0.2F, 0.2F);
	return pPlane;
}
Example #2
0
//----------------------------------------------------------------------------
Node* Sample5::CreateCube(Bool useTexture, Bool useNormals,
	Bool useVertexColor, ColorRGBA vertexColor)
{
	RenderObject* pCube = StandardMesh::CreateCube24(useVertexColor ? 4 : 0,
		useTexture ? 1 : 0, useNormals);
	VertexBuffer* const pVBuffer = pCube->GetMesh()->GetVertexBuffer();

	for (UInt i = 0; i < pVBuffer->GetQuantity(); i++)
	{
		if (useVertexColor)
		{
			if (pVBuffer->Position3(i).Z() > 0)
			{
				pVBuffer->Color4(i) = vertexColor;
			}
			else
			{
				pVBuffer->Color4(i) = vertexColor * 0.5F;
			}
		}
	}

	pCube->GetMesh()->GenerateNormals();

	if (useTexture)
	{
		Material* pMaterial = WIRE_NEW Material;
		pMaterial->AddTexture(CreateTexture(), Material::BM_MODULATE);
		pCube->SetMaterial(pMaterial);
	}

	Node* pCubeNode = WIRE_NEW Node(pCube);
	return pCubeNode;
}
Example #3
0
//----------------------------------------------------------------------------
void NodeSkybox::AddQuad(const Vector3F& v0, const Vector3F& v1, const
	Vector3F& v2, const Vector3F& v3, Texture2D* pTexture,
	VertexBuffer* pVBuffer, IndexBuffer* pIBuffer, UInt side)
{
	pVBuffer->Position3(side*4+0) = v0;
	pVBuffer->Position3(side*4+1) = v1;
	pVBuffer->Position3(side*4+2) = v2;
	pVBuffer->Position3(side*4+3) = v3;

	Material* pMaterial = WIRE_NEW Material;
	pMaterial->AddTexture(pTexture, Material::BM_REPLACE);

	Mesh* pMesh = WIRE_NEW Mesh(pVBuffer, pIBuffer, side*6, 6);
	Node* pQuad = WIRE_NEW Node(pMesh, pMaterial);
	AttachChild(pQuad);
}
Example #4
0
void Grafkit::SceneLoader::SceneLoaderHelper::PersistMaterials(Archive &ar, IResourceManager * const & resman)
{
	UINT materialCount = 0;
	if (ar.IsStoring())
		materialCount = m_materials.size();

	PERSIST_FIELD(ar, materialCount);
	for (UINT i = 0; i < materialCount; ++i) {

		Material *material = nullptr;
		if (ar.IsStoring())
			material = m_materials[i];

		PERSIST_OBJECT(ar, material);

		if (!ar.IsStoring())
			m_materials.push_back(material);

		// materials_to_textures
		std::vector<texture_bind_t> tx_bind;
		UINT textureCount = 0;

		if (ar.IsStoring()) {
			tx_bind = m_textures_to_materials[i];
			textureCount = tx_bind.size();
		}

		PERSIST_FIELD(ar, textureCount);

		for (UINT j = 0; j < textureCount; ++j) {
			texture_bind_t tx;
			if (ar.IsStoring())
				tx = tx_bind[j];

			PERSIST_STRING(ar, tx.first);
			PERSIST_STRING(ar, tx.second);

			if (!ar.IsStoring()) {
				TextureResRef texture = resman->Get<Texture2DRes>(tx.first);
				material->AddTexture(texture, tx.second);
			}
		}
	}
}
Example #5
0
void MyGLWindow::InitFloor()
{
	// load scene floor (textured)
	float floor_vertices[] = {
		-2.0f, 0.0f, 2.0f,
		 2.0f, 0.0f, 2.0f,
		 2.0f, 0.0f,-2.0f,
		-2.0f, 0.0f,-2.0f
	};

	float floor_textCoord[] = {
		0.0f, 0.0f,
		1.0f, 0.0f,
		1.0f, 1.0f,
		0.0f, 1.0f
	};

	unsigned int floor_indices[] = { 0, 3, 1, 1, 3, 2 };

	TextureT floorTexture(new Texture);
	floorTexture->LoadFromFile("./data/texture/BlueMarblePersian-ColorMap.png");
	_textureLib["BlueMarble"] = floorTexture;

	MeshT floorMesh(new Mesh);
	floorMesh->SetBufferData(ShaderLocation::Position, floor_vertices, 4 * 3, 3);
	floorMesh->SetBufferData(ShaderLocation::TexCoord, floor_textCoord, 4 * 2, 2);
	floorMesh->SetIndicesBufferData(floor_indices, 6);
	floorMesh->SetPrimitiveType(GL_TRIANGLES);

	Material floorMaterial;
	floorMaterial.SetAmbientColor( glm::vec3(0.2f, 0.9f, 0.3f) );
	floorMaterial.SetDiffuseColor( glm::vec3(0.2f, 0.9f, 0.3f) );
	floorMaterial.SetSpecularColor( glm::vec3(0.8f, 0.8f, 0.8f) );
	floorMaterial.AddTexture(floorTexture);

	ActorT floor(new Actor);
	floor->AddDrawableMesh(floorMesh, floorMaterial);
	floor->SetShaderProgram(_shaderProgLib["defaultShader"]);
	_actorLib["Floor"] = floor;

}
Example #6
0
//----------------------------------------------------------------------------
void RenderText::Init(Texture2D* pFontTexture, UInt maxLength)
{
	WIRE_ASSERT(mUvs.GetQuantity() == mCharSizes.GetQuantity()*4);
	WIRE_ASSERT(maxLength < (0x10000/4));

	VertexAttributes attr;
	attr.SetPositionChannels(3);
	attr.SetTCoordChannels(2);
	attr.SetColorChannels(4);
	VertexBuffer* pVertexBuffer = WIRE_NEW VertexBuffer(attr, maxLength*4,
		Buffer::UT_DYNAMIC_WRITE_ONLY);

	IndexBuffer* pIndexBuffer = WIRE_NEW IndexBuffer(maxLength*3*2);
	for (UShort i = 0; i < maxLength; i++)
	{
		(*pIndexBuffer)[i*6] = 0 + i*4;
		(*pIndexBuffer)[i*6+1] = 1 + i*4;
		(*pIndexBuffer)[i*6+2] = 2 + i*4;
		(*pIndexBuffer)[i*6+3] = 0 + i*4;
		(*pIndexBuffer)[i*6+4] = 2 + i*4;
		(*pIndexBuffer)[i*6+5] = 3 + i*4;
	}

	Mesh* pMesh = WIRE_NEW Mesh(pVertexBuffer, pIndexBuffer);
	SetMesh(pMesh);

	Clear();

	Material* pMaterial = WIRE_NEW Material;
	pMaterial->AddTexture(pFontTexture);
	SetMaterial(pMaterial);

	State::Init(GetStates());

	StateAlpha* pAlpha = WIRE_NEW StateAlpha;
	pAlpha->BlendEnabled = true;
	GetStates()[State::ALPHA] = pAlpha;
}