Hello, All!
No bugs/major problems to report, but I'm curious as to how I'd accomplish a certain task.
I have a project in which an element on the screen is only rendered in a certain region of the screen, regardless of whether or not the element itself covers more than just that region (anything outside of the region isn't displayed).
It took a while to try to find out how to do this, but it works, and this is the code that I have to do it in the main rendering thread:
sf::View ElementView;
sf::FloatRect ElementRect;
sf::FloatRect Panel;
for (auto & element : m_elements)
{
ElementRect = sf::FloatRect(element->getPosition().x, element->getPosition().y, element->getSize().x, element->getSize().y);
Panel = sf::FloatRect(ElementRect.left / m_windowSize.x, ElementRect.top / m_windowSize.y, ElementRect.width / m_windowSize.x, ElementRect.height / m_windowSize.y);
ElementView.reset(ElementRect);
ElementView.setViewport(Panel);
wnd->setView(ElementView);
element->render(wnd, state);
}
The renderWindow's view is then set back to cover the whole screen (or windowed size) and displayed.
This is an example of what it looks like:(I'm sorry, I don't know to properly use the image tags)
A couple questions I have about this:
- Is this what the people here would say is a good way to accomplish this clipping that I want?
- If not, I'd love to hear suggestions! Any and all advice/feedback is appreciated! - Is it safe to set the window view to just the view to only render in this element's rendering region, clear it, and then render, then reset the renderWindow's view back to normal after doing this and then displaying? I seem to have a gap in my understanding of the API.
Any element may, without notice, update itself and need to be rendered again. Currently, the application does not render any object unless it absolutely has to.
For instance, just sitting there with the mouse just sitting there (no animations or anything) will cause no rendering to be done - it will wait for an event (actually wait by sleeping the event thread).
However, if a single element is updated, then I don't see any reason to wake up my main render thread and waste CPU time by rendering everything over again.
I could very well just be over-complicating this (I have a horrible habit of doing that).
I apologize if this has been asked before, but it seems questions regarding clipping and redrawing aren't the easiest to find/find answers to. I do know (some) raw OpenGL, but I love the usage of SFML and I really want to avoid jumping down into OpenGL (except shaders, I love making/playing with shaders).
If my method of clipping isn't right or should be done in a different way, please feel free to say so. I'm always learning, and I'd rather learn that I was doing it wrong and then learn how to do it right
Thank you!