SFML community forums

Bindings - other languages => DotNet => Topic started by: Tobberoth on October 02, 2013, 12:44:48 pm

Title: Why can't I draw with transform?
Post by: Tobberoth on October 02, 2013, 12:44:48 pm
Hey,

I'm having a weird issue where draw refuses to work if I pass a RenderStates object. If I remove the RenderStates parameter from the .draw call, it works perfectly. However, whenever I create a RenderStates object and pass it to Draw, it's as if the draw never happens, nothing shows up.

This is the relevant code:
RenderStates state = new RenderStates();
Transform trans = new Transform();
trans.Translate(2f,2f);
state.Transform = trans;

window.Clear();
window.Draw(shape, state);
window.Display();
 

The shape object is a VertexArray, defined like this:

VertexArray shape = new VertexArray(PrimitiveType.Lines);
shape.Append(new Vertex(new Vector2f(5,100), Color.Green));
shape.Append(new Vertex(new Vector2f(200,100), Color.Red));
shape.Append(new Vertex(new Vector2f(300, 50), Color.Magenta));
shape.Append(new Vertex(new Vector2f(200, 25), Color.Red));
 

I can find no tutorial or example showing that I need any more stuff to be added than this, but it seems I'm obviously missing something.

EDIT: While debugging, I'm noticing that the methods of the Transform isn't doing anything, that is, it's not changing the matrix. Do I need to manually initialize the matrix somehow?
Title: Re: Why can't I draw with transform?
Post by: Laurent on October 02, 2013, 12:49:40 pm
RenderStates is a struct, you can't use its default constructor. You should initialize it with RenderStates.Default.
Title: Re: Why can't I draw with transform?
Post by: zsbzsb on October 02, 2013, 12:51:43 pm
RenderStates state = new RenderStates();
Transform trans = new Transform();
 

Do not use the default parameterless constructors of structs that are a part of SFML. When you do stuff is not initialized correctly and thus does not get drawn correctly.
Title: Re: Why can't I draw with transform?
Post by: Tobberoth on October 02, 2013, 12:55:29 pm
Thanks, now it's working!

Sad panda when there's differences beyond syntax when it comes to the .NET bindings and the documentation :( Oh well, I should be able to figure it out now.
Title: Re: Why can't I draw with transform?
Post by: Tobberoth on October 11, 2013, 10:22:30 am
Is there any reason why the default constructors do not "work" btw? Is the default constructor used anywhere?

Seems to me like it would make more sense to implement it like Transform.identity since that does what I would expect most people to expect the default constructor to do. I mean, it would just be an alias to Transform.identity more or less, but it would make the code work more like C++ where the default constructors seem to be used in the examples.

public Transform()
{
        m00 = 1;
        m01 = 0;
        m02 = 0;
        m10 = 0;
        m11 = 1;
        m12 = 0;
        m20 = 0;
        m21 = 0;
        m22 = 1;
}
 

However, maybe I'm missing something important about struct handling?
Title: Re: Why can't I draw with transform?
Post by: Laurent on October 11, 2013, 11:00:27 am
C# doesn't allow to define the default constructor of a struct. Thus it is always implemented the same way: the whole struct is filled with zeroes, regardless of what it contains.

I hate .Net for that.
Title: Re: Why can't I draw with transform?
Post by: Tobberoth on October 11, 2013, 12:21:06 pm
C# doesn't allow to define the default constructor of a struct. Thus it is always implemented the same way: the whole struct is filled with zeroes, regardless of what it contains.

I hate .Net for that.
Thanks for the clarification, that's really good to know!