Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Why can't I draw with transform?  (Read 2345 times)

0 Members and 1 Guest are viewing this topic.

Tobberoth

  • Guest
Why can't I draw with transform?
« 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?
« Last Edit: October 02, 2013, 12:50:06 pm by Tobberoth »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Why can't I draw with transform?
« Reply #1 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.
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Why can't I draw with transform?
« Reply #2 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Tobberoth

  • Guest
Re: Why can't I draw with transform?
« Reply #3 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.

Tobberoth

  • Guest
Re: Why can't I draw with transform?
« Reply #4 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Why can't I draw with transform?
« Reply #5 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.
Laurent Gomila - SFML developer

Tobberoth

  • Guest
Re: Why can't I draw with transform?
« Reply #6 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!

 

anything