本文整理汇总了C++中sf::RenderTexture::getDefaultView方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderTexture::getDefaultView方法的具体用法?C++ RenderTexture::getDefaultView怎么用?C++ RenderTexture::getDefaultView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RenderTexture
的用法示例。
在下文中一共展示了RenderTexture::getDefaultView方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render
void LightDirectionEmission::render(const sf::View &view, sf::RenderTexture &lightTempTexture, sf::RenderTexture &antumbraTempTexture, const std::vector<QuadtreeOccupant*> &shapes, sf::Shader &unshadowShader, float shadowExtension) {
lightTempTexture.setView(view);
LightSystem::clear(lightTempTexture, sf::Color::White);
// Mask off light shape (over-masking - mask too much, reveal penumbra/antumbra afterwards)
for (int i = 0; i < shapes.size(); i++) {
LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);
// Get boundaries
std::vector<LightSystem::Penumbra> penumbras;
std::vector<int> innerBoundaryIndices;
std::vector<int> outerBoundaryIndices;
std::vector<sf::Vector2f> innerBoundaryVectors;
std::vector<sf::Vector2f> outerBoundaryVectors;
LightSystem::getPenumbrasDirection(penumbras, innerBoundaryIndices, innerBoundaryVectors, outerBoundaryIndices, outerBoundaryVectors, pLightShape->_shape, _castDirection, _sourceRadius, _sourceDistance);
if (innerBoundaryIndices.size() != 2 || outerBoundaryIndices.size() != 2)
continue;
LightSystem::clear(antumbraTempTexture, sf::Color::White);
antumbraTempTexture.setView(view);
sf::ConvexShape maskShape;
float maxDist = 0.0f;
for (int j = 0; j < pLightShape->_shape.getPointCount(); j++)
maxDist = std::max(maxDist, vectorMagnitude(view.getCenter() - pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(j))));
float totalShadowExtension = shadowExtension + maxDist;
maskShape.setPointCount(4);
maskShape.setPoint(0, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[0])));
maskShape.setPoint(1, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[1])));
maskShape.setPoint(2, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[1])) + vectorNormalize(innerBoundaryVectors[1]) * totalShadowExtension);
maskShape.setPoint(3, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[0])) + vectorNormalize(innerBoundaryVectors[0]) * totalShadowExtension);
maskShape.setFillColor(sf::Color::Black);
antumbraTempTexture.draw(maskShape);
sf::VertexArray vertexArray;
vertexArray.setPrimitiveType(sf::PrimitiveType::Triangles);
vertexArray.resize(3);
{
sf::RenderStates states;
states.blendMode = sf::BlendAdd;
states.shader = &unshadowShader;
// Unmask with penumbras
for (int j = 0; j < penumbras.size(); j++) {
unshadowShader.setParameter("lightBrightness", penumbras[j]._lightBrightness);
unshadowShader.setParameter("darkBrightness", penumbras[j]._darkBrightness);
vertexArray[0].position = penumbras[j]._source;
vertexArray[1].position = penumbras[j]._source + vectorNormalize(penumbras[j]._lightEdge) * totalShadowExtension;
vertexArray[2].position = penumbras[j]._source + vectorNormalize(penumbras[j]._darkEdge) * totalShadowExtension;
vertexArray[0].texCoords = sf::Vector2f(0.0f, 1.0f);
vertexArray[1].texCoords = sf::Vector2f(1.0f, 0.0f);
vertexArray[2].texCoords = sf::Vector2f(0.0f, 0.0f);
antumbraTempTexture.draw(vertexArray, states);
}
}
antumbraTempTexture.display();
// Multiply back to lightTempTexture
sf::RenderStates antumbraRenderStates;
antumbraRenderStates.blendMode = sf::BlendMultiply;
sf::Sprite s;
s.setTexture(antumbraTempTexture.getTexture());
lightTempTexture.setView(lightTempTexture.getDefaultView());
lightTempTexture.draw(s, antumbraRenderStates);
lightTempTexture.setView(view);
}
for (int i = 0; i < shapes.size(); i++) {
LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);
if (pLightShape->_renderLightOverShape) {
pLightShape->_shape.setFillColor(sf::Color::White);
lightTempTexture.draw(pLightShape->_shape);
}
}
//.........这里部分代码省略.........
示例2: render
//.........这里部分代码省略.........
vertexArray.setPrimitiveType(sf::PrimitiveType::Triangles);
vertexArray.resize(3);
sf::RenderStates penumbraRenderStates;
penumbraRenderStates.blendMode = sf::BlendAdd;
penumbraRenderStates.shader = &unshadowShader;
// Unmask with penumbras
for (unsigned j = 0; j < penumbras.size(); j++) {
unshadowShader.setParameter("lightBrightness", penumbras[j]._lightBrightness);
unshadowShader.setParameter("darkBrightness", penumbras[j]._darkBrightness);
vertexArray[0].position = penumbras[j]._source;
vertexArray[1].position = penumbras[j]._source + vectorNormalize(penumbras[j]._lightEdge) * shadowExtension;
vertexArray[2].position = penumbras[j]._source + vectorNormalize(penumbras[j]._darkEdge) * shadowExtension;
vertexArray[0].texCoords = sf::Vector2f(0.0f, 1.0f);
vertexArray[1].texCoords = sf::Vector2f(1.0f, 0.0f);
vertexArray[2].texCoords = sf::Vector2f(0.0f, 0.0f);
antumbraTempTexture.draw(vertexArray, penumbraRenderStates);
}
antumbraTempTexture.display();
// Multiply back to lightTempTexture
sf::RenderStates antumbraRenderStates;
antumbraRenderStates.blendMode = sf::BlendMultiply;
sf::Sprite s;
s.setTexture(antumbraTempTexture.getTexture());
lightTempTexture.setView(lightTempTexture.getDefaultView());
lightTempTexture.draw(s, antumbraRenderStates);
lightTempTexture.setView(view);
}
else {
sf::ConvexShape maskShape;
maskShape.setPointCount(4);
maskShape.setPoint(0, as);
maskShape.setPoint(1, bs);
maskShape.setPoint(2, bs + vectorNormalize(bd) * shadowExtension);
maskShape.setPoint(3, as + vectorNormalize(ad) * shadowExtension);
maskShape.setFillColor(sf::Color::Black);
lightTempTexture.draw(maskShape);
sf::VertexArray vertexArray;
vertexArray.setPrimitiveType(sf::PrimitiveType::Triangles);
vertexArray.resize(3);
sf::RenderStates penumbraRenderStates;
penumbraRenderStates.blendMode = sf::BlendMultiply;
penumbraRenderStates.shader = &unshadowShader;
// Unmask with penumbras
for (unsigned j = 0; j < penumbras.size(); j++) {
unshadowShader.setParameter("lightBrightness", penumbras[j]._lightBrightness);
unshadowShader.setParameter("darkBrightness", penumbras[j]._darkBrightness);
vertexArray[0].position = penumbras[j]._source;
vertexArray[1].position = penumbras[j]._source + vectorNormalize(penumbras[j]._lightEdge) * shadowExtension;
vertexArray[2].position = penumbras[j]._source + vectorNormalize(penumbras[j]._darkEdge) * shadowExtension;
vertexArray[0].texCoords = sf::Vector2f(0.0f, 1.0f);
vertexArray[1].texCoords = sf::Vector2f(1.0f, 0.0f);
vertexArray[2].texCoords = sf::Vector2f(0.0f, 0.0f);
lightTempTexture.draw(vertexArray, penumbraRenderStates);
}
}
}
for (unsigned i = 0; i < shapes.size(); i++) {
LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);
if (pLightShape->_renderLightOverShape) {
pLightShape->_shape.setFillColor(sf::Color::White);
lightTempTexture.draw(pLightShape->_shape, &lightOverShapeShader);
}
else {
pLightShape->_shape.setFillColor(sf::Color::Black);
lightTempTexture.draw(pLightShape->_shape);
}
}
lightTempTexture.display();
}