예제 #1
0
int GPC_RenderTools::applyLights(int objectlayer, const MT_Transform& viewmat)
{
	// taken from blender source, incompatibility between Blender Object / GameObject	
	KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo;
	float glviewmat[16];
	unsigned int count;
	std::vector<struct	RAS_LightObject*>::iterator lit = m_lights.begin();

	for(count=0; count<m_numgllights; count++)
		glDisable((GLenum)(GL_LIGHT0+count));

	viewmat.getValue(glviewmat);
	
	glPushMatrix();
	glLoadMatrixf(glviewmat);
	for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
	{
		RAS_LightObject* lightdata = (*lit);
		KX_LightObject *kxlight = (KX_LightObject*)lightdata->m_light;

		if(kxlight->ApplyLight(kxscene, objectlayer, count))
			count++;
	}
	glPopMatrix();

	return count;
}
void RAS_OpenGLRasterizer::ProcessLighting(bool uselights, const MT_Transform& viewmat)
{
	bool enable = false;
	int layer= -1;

	/* find the layer */
	if (uselights) {
		if (m_clientobject)
			layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
	}

	/* avoid state switching */
	if (m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo)
		return;

	m_lastlightlayer = layer;
	m_lastauxinfo = m_auxilaryClientInfo;

	/* enable/disable lights as needed */
	if (layer >= 0) {
		//enable = ApplyLights(layer, viewmat);
		// taken from blender source, incompatibility between Blender Object / GameObject
		KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo;
		float glviewmat[16];
		unsigned int count;
		std::vector<struct	RAS_LightObject*>::iterator lit = m_lights.begin();

		for (count=0; count<m_numgllights; count++)
			glDisable((GLenum)(GL_LIGHT0+count));

		viewmat.getValue(glviewmat);

		glPushMatrix();
		glLoadMatrixf(glviewmat);
		for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
		{
			RAS_LightObject* lightdata = (*lit);
			KX_LightObject *kxlight = (KX_LightObject*)lightdata->m_light;

			if (kxlight->ApplyLight(kxscene, layer, count))
				count++;
		}
		glPopMatrix();

		enable = count > 0;
	}

	if (enable)
		EnableOpenGLLights();
	else
		DisableOpenGLLights();
}