void CRenderingContext::RenderBillboard(const CMaterialHandle& hMaterial, float flRadius, Vector vecUp, Vector vecRight)
{
	TAssert(hMaterial.IsValid());
	if (!hMaterial.IsValid())
		return;

	vecUp *= flRadius;
	vecRight *= flRadius;

	// Clear out any existing rotation so that they don't interfere with the billboarding below.
	GetContext().m_mTransformations.SetAngles(EAngle(0, 0, 0));
	GetContext().m_bTransformUpdated = false;

	if (GetContext().m_hMaterial != hMaterial)
		UseMaterial(hMaterial);

	BeginRenderTriFan();
		TexCoord(0.0f, 1.0f);
		Vertex(-vecRight + vecUp);
		TexCoord(0.0f, 0.0f);
		Vertex(-vecRight - vecUp);
		TexCoord(1.0f, 0.0f);
		Vertex(vecRight - vecUp);
		TexCoord(1.0f, 1.0f);
		Vertex(vecRight + vecUp);
	EndRender();
}
CRenderingContext::CRenderingContext(CRenderer* pRenderer, bool bInherit)
{
	m_pRenderer = pRenderer;

	m_clrRender = ::Color(255, 255, 255, 255);

	s_aContexts.push_back();

	if (bInherit && s_aContexts.size() > 1)
	{
		CRenderContext& oLastContext = s_aContexts[s_aContexts.size()-2];
		CRenderContext& oThisContext = GetContext();

		oThisContext.m_mProjection = oLastContext.m_mProjection;
		oThisContext.m_mView = oLastContext.m_mView;
		oThisContext.m_mTransformations = oLastContext.m_mTransformations;

		oThisContext.m_hMaterial = oLastContext.m_hMaterial;
		oThisContext.m_pFrameBuffer = oLastContext.m_pFrameBuffer;
		tstrncpy(oThisContext.m_szProgram, PROGRAM_LEN, oLastContext.m_szProgram, PROGRAM_LEN);
		oThisContext.m_pShader = oLastContext.m_pShader;

		oThisContext.m_rViewport = oLastContext.m_rViewport;
		oThisContext.m_eBlend = oLastContext.m_eBlend;
		oThisContext.m_flAlpha = oLastContext.m_flAlpha;
		oThisContext.m_bDepthMask = oLastContext.m_bDepthMask;
		oThisContext.m_bDepthTest = oLastContext.m_bDepthTest;
		oThisContext.m_eDepthFunction = oLastContext.m_eDepthFunction;
		oThisContext.m_bCull = oLastContext.m_bCull;
		oThisContext.m_bWinding = oLastContext.m_bWinding;

		m_pShader = oThisContext.m_pShader;

		if (m_pShader)
			m_iProgram = m_pShader->m_iProgram;
		else
			m_iProgram = 0;
	}
	else
	{
		m_pShader = NULL;

		BindTexture(0);
		UseMaterial(CMaterialHandle());
		UseFrameBuffer(NULL);
		UseProgram("");

		SetViewport(Rect(0, 0, Application()->GetWindowWidth(), Application()->GetWindowHeight()));
		SetBlend(BLEND_NONE);
		SetAlpha(1);
		SetDepthMask(true);
		SetDepthTest(true);
		SetDepthFunction(DF_LESS);
		SetBackCulling(true);
		SetWinding(true);
	}
}
CRenderingContext::~CRenderingContext()
{
	TAssert(s_aContexts.size());

	s_aContexts.pop_back();

	if (s_aContexts.size())
	{
		CRenderContext& oContext = GetContext();

		UseMaterial(oContext.m_hMaterial);
		UseFrameBuffer(oContext.m_pFrameBuffer);
		UseProgram(oContext.m_pShader);

		if (*oContext.m_szProgram)
		{
			oContext.m_bProjectionUpdated = false;
			oContext.m_bViewUpdated = false;
			oContext.m_bTransformUpdated = false;
		}

		SetViewport(oContext.m_rViewport);
		SetBlend(oContext.m_eBlend);
		SetAlpha(oContext.m_flAlpha);
		SetDepthMask(oContext.m_bDepthMask);
		SetDepthTest(oContext.m_bDepthTest);
		SetDepthFunction(oContext.m_eDepthFunction);
		SetBackCulling(oContext.m_bCull);
		SetWinding(oContext.m_bWinding);
	}
	else
	{
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, 0);

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		if (m_pRenderer)
			glViewport(0, 0, (GLsizei)m_pRenderer->m_iWidth, (GLsizei)m_pRenderer->m_iHeight);
		else
			glViewport(0, 0, (GLsizei)Application()->GetWindowWidth(), (GLsizei)Application()->GetWindowHeight());

		glUseProgram(0);

		glDisablei(GL_BLEND, 0);

		glDepthMask(true);
		glEnable(GL_DEPTH_TEST);
		glEnable(GL_CULL_FACE);
		glDepthFunc(GL_LESS);

		glFrontFace(GL_CCW);
	}
}
Esempio n. 4
0
void CRenderingContext::RenderBillboard(const CMaterialHandle& hMaterial, float flRadius, Vector vecUp, Vector vecRight)
{
	TAssert(hMaterial.IsValid());
	if (!hMaterial.IsValid())
		return;

	vecUp *= flRadius;
	vecRight *= flRadius;

	UseMaterial(hMaterial);
	BeginRenderTriFan();
		TexCoord(0.0f, 1.0f);
		Vertex(-vecRight + vecUp);
		TexCoord(0.0f, 0.0f);
		Vertex(-vecRight - vecUp);
		TexCoord(1.0f, 0.0f);
		Vertex(vecRight - vecUp);
		TexCoord(1.0f, 1.0f);
		Vertex(vecRight + vecUp);
	EndRender();
}
Esempio n. 5
0
void CRenderingContext::UseMaterial(const tstring& sName)
{
	UseMaterial(CMaterialLibrary::FindAsset(sName));
}
Esempio n. 6
0
void _stdcall COBJModel::RenderToDisplayList(const Face *pFaces, 
									const unsigned int iFaceCount,
									const Material *pMaterials)
{
	////////////////////////////////////////////////////////////////////////
	// Render a list of faces into a display list
	////////////////////////////////////////////////////////////////////////

	int i, j;
	float fNormal[3];
	int iPreviousMaterial = -1;
	
	// Generate & save display list index
	

	// Render model into the display list
	glNewList(m_iDisplayList, GL_COMPILE);

		// Save texture bit to recover from the various texture state changes
		glPushAttrib(GL_TEXTURE_BIT);

			// Activate automatic texture coord generation if no coords loaded
			if (!pFaces[0].pTexCoords)
				GenTexCoords();
		
			// Use default material if no materials are loaded
			if (!pMaterials)
				UseMaterial(NULL);

			// Process all faces
			for (i=0; i<(int) iFaceCount; i++)
			{
				// Any materials loaded ?
				
				if (pMaterials)
					
					// Set material (if it differs from the previous one)
					if (iPreviousMaterial != (int) pFaces[i].iMaterialIndex)
					{
						iPreviousMaterial = pFaces[i].iMaterialIndex;
						UseMaterial(&pMaterials[pFaces[i].iMaterialIndex]);
					}

				// Set primitive of the current face
				switch (pFaces[i].iNumVertices)
				{
					case 3:
						glBegin(GL_TRIANGLES);
						break;
					case 4:
						glBegin(GL_QUADS);
						break;
					default:
						glBegin(GL_POLYGON);
				}
							
				// Calculate and set face normal if no vertex normals are specified
				if (!pFaces[i].pNormals)
				{
					GetFaceNormal(fNormal, &pFaces[i]);
					glNormal3fv(fNormal);
				}

				// Process all vertices
				for (j=0; j<(int) pFaces[i].iNumVertices; j++)
				{
					// Set vertex normal (if vertex normals are specified)
					if (pFaces[i].pNormals)
						glNormal3f(pFaces[i].pNormals[j].fX, 
							pFaces[i].pNormals[j].fY, pFaces[i].pNormals[j].fZ);

					// Set texture coordinates (if any specified)
					if (pFaces[i].pTexCoords)
						glTexCoord2f(pFaces[i].pTexCoords[j].fX, 
							pFaces[i].pTexCoords[j].fY);

					// Set vertex
					glVertex3f(pFaces[i].pVertices[j].fX, 
						pFaces[i].pVertices[j].fY, pFaces[i].pVertices[j].fZ);
				}

				glEnd();	
			}

		glPopAttrib();

	glEndList();
}