1
General / Re: Derive from RenderTarget - override Draw() method
« on: November 15, 2013, 01:44:48 pm »Drawing to all sub-render-texures just removes the complexity of calculating where the entity is drawn, it doesn't solve the design problem. Note that SFML.Net is a special case, all functions are virtual (RenderTarget is an interface) because of implementation constraints -- it is based on the C binding.
You are right, the design Problem is still there, but it is a functional workaround that doesn't require to change anything on the SFML side. Additionally you want to reuse the draw-capabilities of RenderTexture and not reimplement the whole thing on OpenGL-Level. But even if you wanted to do that the SFML implementation and the current coupling of RenderTarget and Drawable won't allow you that. But maybe I misunderstood what you meant.
The solution now is to Derive the BigRenderTexture from the RenderTarget-Interface. Implement the pure virtual methods and hide the original Draw(drawable...) implementation of RenderTarget. It then behaves just like the RenderTexture from the outside. Note that it is not possible to do the same with the Draw(vertices...) method.
The draw methods looks as follows:
void BigRenderTexture::draw(const sf::Drawable& drawable, const sf::RenderStates& states)
{
sf::RenderStates statesTmp = states;
sf::Transform transform = statesTmp.transform;
for (unsigned int i = 0; i < mRenderTextures.size(); i++)
{
// Xindex Yindex
statesTmp.transform.translate( -1 * float(((i % mTableSize.x)) * mTextureMaxSize) , -1 * float(((i / mTableSize.x)) * mTextureMaxSize));
mRenderTextures[i]->draw(drawable, statesTmp);
}
}
{
sf::RenderStates statesTmp = states;
sf::Transform transform = statesTmp.transform;
for (unsigned int i = 0; i < mRenderTextures.size(); i++)
{
// Xindex Yindex
statesTmp.transform.translate( -1 * float(((i % mTableSize.x)) * mTextureMaxSize) , -1 * float(((i / mTableSize.x)) * mTextureMaxSize));
mRenderTextures[i]->draw(drawable, statesTmp);
}
}