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

Author Topic: [C#][SFML 2.1] Passing RenderStates makes object dissappear.  (Read 3071 times)

0 Members and 1 Guest are viewing this topic.

Neomex

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
[C#][SFML 2.1] Passing RenderStates makes object dissappear.
« on: January 13, 2014, 01:31:38 am »
When I call draw with just 2 params it works fine, but when I want to set texture through RenderStates triangle is not displayed.

Texture loads well, can draw it without issue as Sprite.

I have also tried creating and filling RenderStates object every loop with no effects.

What am I doing wrong here?

public class Terrain
        {
                List<Vertex> triangles = new List<Vertex>();

                Texture imgGrass;
                Sprite sprite;
                RenderStates states = new RenderStates();

                public Terrain ()
                {
                        imgGrass = new Texture("Data/Gfx/grass.png");
                        imgGrass.Repeated = true;
                        states.Texture = imgGrass;
                        sprite = new Sprite(imgGrass);

                        Vertex vertex = new Vertex();

                        vertex.Position = new Vector2f( 32, 32 );
                        vertex.Color = Color.White;
                        vertex.TexCoords = new Vector2f( 0, 0);

                        triangles.Add(vertex);

                        vertex.Position = new Vector2f( 256, 32 );
                        vertex.Color = Color.White;
                        vertex.TexCoords = new Vector2f( 100, 0);

                        triangles.Add(vertex);

                        vertex.Position = new Vector2f( 128, 128 );
                        vertex.Color = Color.White;
                        vertex.TexCoords = new Vector2f( 0, 100);

                        triangles.Add(vertex);
                }

                public void Draw(RenderWindow window)
                {
                        //window.Draw(sprite);

                        window.Draw(triangles.ToArray(), PrimitiveType.Triangles, states);
                }
        }

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: [C#][SFML 2.1] Passing RenderStates makes object dissappear.
« Reply #1 on: January 13, 2014, 01:40:37 am »
Because of this:
http://msdn.microsoft.com/en-us/library/aa288208%28v=vs.71%29.aspx

You need to use this static prop instead of newing in the RenderStates:
https://github.com/SFML/SFML.Net/blob/master/src/Graphics/RenderStates.cs#L97
RenderStates states = RenderStates.Default

Structs are zeroed by .NET so that RenderStates is actually incorrect and has Transform filled with zeros that destroys all geometry.

This was mentioned before, BTW.
Back to C++ gamedev with SFML in May 2023

 

anything