本文整理汇总了C++中sf::RenderTexture::setView方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderTexture::setView方法的具体用法?C++ RenderTexture::setView怎么用?C++ RenderTexture::setView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RenderTexture
的用法示例。
在下文中一共展示了RenderTexture::setView方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: adjustRenderTexture
void GuiElement::adjustRenderTexture(sf::RenderTexture& texture)
{
P<WindowManager> window_manager = engine->getObject("windowManager");
//Hack the rectangle for this element so it sits perfectly on pixel boundaries.
sf::Vector2f half_pixel = (window_manager->mapPixelToCoords(sf::Vector2i(1, 1)) - window_manager->mapPixelToCoords(sf::Vector2i(0, 0))) / 2.0f;
sf::Vector2f top_left = window_manager->mapPixelToCoords(window_manager->mapCoordsToPixel(sf::Vector2f(rect.left, rect.top) + half_pixel));
sf::Vector2f bottom_right = window_manager->mapPixelToCoords(window_manager->mapCoordsToPixel(sf::Vector2f(rect.left + rect.width, rect.top + rect.height) + half_pixel));
rect.left = top_left.x;
rect.top = top_left.y;
rect.width = bottom_right.x - top_left.x;
rect.height = bottom_right.y - top_left.y;
sf::Vector2i texture_size = window_manager->mapCoordsToPixel(sf::Vector2f(rect.width, rect.height) + half_pixel) - window_manager->mapCoordsToPixel(sf::Vector2f(0, 0));
unsigned int sx = powerOfTwo(texture_size.x);
unsigned int sy = powerOfTwo(texture_size.y);
if (texture.getSize().x != sx && texture.getSize().y != sy)
{
texture.create(sx, sy, false);
}
//Set the view so it covers this elements normal rect. So we can draw exactly the same on this texture as no the normal screen.
sf::View view(rect);
view.setViewport(sf::FloatRect(0, 0, float(texture_size.x) / float(sx), float(texture_size.y) / float(sy)));
texture.setView(view);
}
示例2:
void setView (const sf::View & view)
{
texture.setView(view);
}
示例3: 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);
}
}
//.........这里部分代码省略.........
示例4: render
void LightPointEmission::render(const sf::View &view, sf::RenderTexture &lightTempTexture, sf::RenderTexture &emissionTempTexture, sf::RenderTexture &antumbraTempTexture, const std::vector<QuadtreeOccupant*> &shapes, sf::Shader &unshadowShader, sf::Shader &lightOverShapeShader) {
LightSystem::clear(emissionTempTexture, sf::Color::Black);
emissionTempTexture.setView(view);
emissionTempTexture.draw(_emissionSprite);
emissionTempTexture.display();
LightSystem::clear(lightTempTexture, sf::Color::Black);
lightTempTexture.setView(view);
lightTempTexture.draw(_emissionSprite);
sf::Transform t;
t.translate(_emissionSprite.getPosition());
t.rotate(_emissionSprite.getRotation());
t.scale(_emissionSprite.getScale());
sf::Vector2f castCenter = t.transformPoint(_localCastCenter);
float shadowExtension = _shadowOverExtendMultiplier * (getAABB().width + getAABB().height);
struct OuterEdges {
std::vector<int> _outerBoundaryIndices;
std::vector<sf::Vector2f> _outerBoundaryVectors;
};
std::vector<OuterEdges> outerEdges(shapes.size());
// Mask off light shape (over-masking - mask too much, reveal penumbra/antumbra afterwards)
for (unsigned i = 0; i < shapes.size(); i++) {
LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);
// Get boundaries
std::vector<int> innerBoundaryIndices;
std::vector<sf::Vector2f> innerBoundaryVectors;
std::vector<LightSystem::Penumbra> penumbras;
LightSystem::getPenumbrasPoint(penumbras, innerBoundaryIndices, innerBoundaryVectors, outerEdges[i]._outerBoundaryIndices, outerEdges[i]._outerBoundaryVectors, pLightShape->_shape, castCenter, _sourceRadius);
if (innerBoundaryIndices.size() != 2 || outerEdges[i]._outerBoundaryIndices.size() != 2)
continue;
// Render shape
if (!pLightShape->_renderLightOverShape) {
pLightShape->_shape.setFillColor(sf::Color::Black);
lightTempTexture.draw(pLightShape->_shape);
}
sf::RenderStates maskRenderStates;
maskRenderStates.blendMode = sf::BlendNone;
sf::Vector2f as = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(outerEdges[i]._outerBoundaryIndices[0]));
sf::Vector2f bs = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(outerEdges[i]._outerBoundaryIndices[1]));
sf::Vector2f ad = outerEdges[i]._outerBoundaryVectors[0];
sf::Vector2f bd = outerEdges[i]._outerBoundaryVectors[1];
sf::Vector2f intersectionOuter;
// Handle antumbras as a seperate case
if (rayIntersect(as, ad, bs, bd, intersectionOuter)) {
sf::Vector2f asi = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[0]));
sf::Vector2f bsi = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[1]));
sf::Vector2f adi = innerBoundaryVectors[0];
sf::Vector2f bdi = innerBoundaryVectors[1];
LightSystem::clear(antumbraTempTexture, sf::Color::White);
antumbraTempTexture.setView(view);
sf::Vector2f intersectionInner;
if (rayIntersect(asi, adi, bsi, bdi, intersectionInner)) {
sf::ConvexShape maskShape;
maskShape.setPointCount(3);
maskShape.setPoint(0, asi);
maskShape.setPoint(1, bsi);
maskShape.setPoint(2, intersectionInner);
maskShape.setFillColor(sf::Color::Black);
antumbraTempTexture.draw(maskShape);
}
else {
sf::ConvexShape maskShape;
maskShape.setPointCount(4);
maskShape.setPoint(0, asi);
maskShape.setPoint(1, bsi);
maskShape.setPoint(2, bsi + vectorNormalize(bdi) * shadowExtension);
maskShape.setPoint(3, asi + vectorNormalize(adi) * shadowExtension);
maskShape.setFillColor(sf::Color::Black);
//.........这里部分代码省略.........