FINALLY! Finished the RenderWindow though I got some weird bug with it which I'll have to look into deeper. RenderWindow inherits from Window of course so it already got the RenderWindow#display function defined for it. But when I tried to override that method ruby crashed at exit whining about that the stack wasn't consistent any more. I don't understand, the sf::RenderWindow::Display function is inherited from sf::Window, could it be something there being the problem?
Also another problem I ran into was that I couldn't just simply have a generic function with a sf::RenderTarget pointer to either a window or render image but I had to have 2 separate functions for each separate type. Well the problem originated in that the sf::RenderTarget::Draw function wasn't virtual which I thought.
Everything works now and you can draw shapes onto a RenderWindow or RenderImage which is pretty cool. Though I'll commit all the new changes tomorrow at the university. I'd like to do some more tests before actually committing the new code.
*EDIT*
This is really bugging me so I can't go to sleep. How come then that this works:
void MyDrawable::Render( sf::RenderTarget& aTarget, sf::Renderer& aRenderer ) const
{
aTarget.Draw( /* Something */ );
}
And this don't?
static VALUE RenderTarget_Draw( int argc, VALUE *args, VALUE self )
{
sf::RenderTarget *object = NULL;
Data_Get_Struct( self, sf::RenderTarget, object );
switch( argc )
{
case 2:
{
VALIDATE_CLASS( args[0], globalDrawableModule, "object" );
VALIDATE_CLASS( args[1], globalShaderClass, "shader" );
sf::Drawable *drawable = NULL;
Data_Get_Struct( args[0], sf::Drawable, drawable );
sf::Shader *shader = NULL;
Data_Get_Struct( args[1], sf::Shader, shader );
object->Draw( *drawable, *shader );
break;
}
case 1:
{
VALIDATE_CLASS( args[0], globalDrawableModule, "object" );
sf::Drawable *drawable = NULL;
Data_Get_Struct( args[0], sf::Drawable, drawable );
object->Draw( *drawable );
break;
}
default:
rb_raise( rb_eArgError, "Expected 1 or 2 arguments but was given %d", argc );
}
return Qnil;
}
It crashes when calling the sf::RenderTarget::Draw function, this really bothers me. How come it doesn't work here? What's the main difference that I do? Just ignore all the Ruby specific code. I've checked, the returned objects are correct, I get a sf::RenderTarget in the object pointer and a sf::Drawable in the drawable pointer. If I just change the type of object into sf::RenderWindow then it works without a problem.
*ANOTHER EDIT*
Aaah wait! I get it now I think! The Draw function used to be virtual but isn't any more and SFML2 isn't finished yet so this is still in progress. Aaah no sweat then. I thought I did something wrong... The horrible thought! Well it is working, not elegant but works currently so I can wait until SFML2 is actually finished and then remove the type specific functions or however it turns out.