Example #1
0
DGLE_RESULT DGLE_API CFixedFunctionPipeline::GetSpotLightConfiguration(uint uiIdx, TPoint3 &stPosition, TVector3 &stDirection, float &fRange, float &fSpotAngle)
{
	E_LIGHT_TYPE type;
	GetLightType(uiIdx, type);

	if (uiIdx >= (uint)_iMaxLights || type != LT_SPOT)
		return E_INVALIDARG;

	GLfloat pos[4];
	glGetLightfv(GL_LIGHT0 + uiIdx, GL_POSITION, pos);
	glGetLightfv(GL_LIGHT0 + uiIdx, GL_SPOT_DIRECTION, stDirection);

	// May work wrong when light position was set or changed directly via OpenGL outside this class.
	const TMatrix4x4 inv_mview = MatrixInverse(_pLights[uiIdx].mview);
	stPosition = inv_mview.ApplyToPoint(TPoint3(pos[0], pos[1], pos[2])); 
	stDirection = inv_mview.ApplyToVector(stDirection);
	
	glGetLightfv(GL_LIGHT0 + uiIdx, GL_SPOT_CUTOFF, &fSpotAngle);
	fSpotAngle *= 2.f;

	glGetLightfv(GL_LIGHT0 + uiIdx, GL_LINEAR_ATTENUATION, &fRange);
	fRange = _c_fAttenuationFactor / fRange;
	
	return S_OK;
}
Example #2
0
void Light::SetupLight(int lightIndex){
    glEnable(GL_LIGHT0+lightIndex);
    // Setup and enable light 0
    glLightfv(GL_LIGHT0+lightIndex,GL_AMBIENT, glm::value_ptr(GetAmbient()));
    glLightfv(GL_LIGHT0+lightIndex,GL_DIFFUSE, glm::value_ptr(GetDiffuse()));
    glLightfv(GL_LIGHT0+lightIndex,GL_SPECULAR, glm::value_ptr(GetSpecular()));
	glLighti(GL_LIGHT0+lightIndex, GL_SPOT_CUTOFF, spotCutoff); 
	glLightfv(GL_LIGHT0+lightIndex,GL_SPOT_DIRECTION, glm::value_ptr(spotDirection));
    float w = 0;
    if (GetLightType()==PointLight){
        w = 1;
    } else if (GetLightType()==DirectionalLight){
        w = 0;
    }
    SceneObject *sceneObject = GetOwner();
    assert(sceneObject != NULL);
    glm::vec4 lightPos(sceneObject->GetTransform()->GetPosition(), w);

    glLightfv(GL_LIGHT0+lightIndex,GL_POSITION, glm::value_ptr(lightPos));
}
Example #3
0
	Light* Renderer::GetLightDirectional()
	{
		auto entities = m_entities[Renderable_Light];

		for (const auto& entity : entities)
		{
			auto light = entity->GetComponent<Light>().get();
			if (light->GetLightType() == LightType_Directional)
				return light;
		}

		return nullptr;
	}
Example #4
0
DGLE_RESULT DGLE_API CFixedFunctionPipeline::GetDirectionalLightConfiguration(uint uiIdx, TVector3 &stDirection)
{
	E_LIGHT_TYPE type;
	GetLightType(uiIdx, type);

	if (uiIdx >= (uint)_iMaxLights || type != LT_DIRECTIONAL)
		return E_INVALIDARG;

	GLfloat dir[4];
	glGetLightfv(GL_LIGHT0 + uiIdx, GL_POSITION, dir);

	// May work wrong when light position was set or changed directly via OpenGL outside this class.
	stDirection = MatrixInverse(_pLights[uiIdx].mview).ApplyToVector(TVector3(dir[0], dir[1], dir[2]));

	return S_OK;
}
Example #5
0
DGLE_RESULT DGLE_API CFixedFunctionPipeline::GetPointLightConfiguration(uint uiIdx, TPoint3 &stPosition, float &fRange)
{
	E_LIGHT_TYPE type;
	GetLightType(uiIdx, type);

	if (uiIdx >= (uint)_iMaxLights || type != LT_POINT)
		return E_INVALIDARG;

	GLfloat pos[4];
	glGetLightfv(GL_LIGHT0 + uiIdx, GL_POSITION, pos);

	// May work wrong when light position was set or changed directly via OpenGL outside this class.
	stPosition = MatrixInverse(_pLights[uiIdx].mview).ApplyToPoint(TPoint3(pos[0], pos[1], pos[2]));
	
	glGetLightfv(GL_LIGHT0 + uiIdx, GL_LINEAR_ATTENUATION, &fRange);
	fRange = _c_fAttenuationFactor / fRange;

	return S_OK;
}