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

Author Topic: VertexArray vs Array of Vertices, is it broken or I am doing it wrong?  (Read 2991 times)

0 Members and 2 Guests are viewing this topic.

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email


EDIT: Fixed broken image link

In the above image, the nice colorful rectangle near the center is generated by a VertexArray, while the ugly triangle to the left is generated by a Vertex[]. I would have expected them to be the same. Here's the code:

using SFML.Graphics;
using SFML.Window;

public class TestProgram
{
    private RenderWindow window;

        static void Main()
    {
                RenderWindow window = new RenderWindow(new VideoMode(800, 600), "VA test");
                window.SetVerticalSyncEnabled(true);
                window.Closed += (sender, e) => window.Close();

                Vertex v1 = new Vertex(new Vector2f(300, 100), Color.White);
                Vertex v2 = new Vertex(new Vector2f(450, 100), Color.Green);
                Vertex v3 = new Vertex(new Vector2f(450, 300), Color.Magenta);
                Vertex v4 = new Vertex(new Vector2f(300, 300), Color.Yellow);

                VertexArray vertexArray = new VertexArray(PrimitiveType.Quads, 4);
                vertexArray.Append(v1);
                vertexArray.Append(v2);
                vertexArray.Append(v3);
                vertexArray.Append(v4);

                Vertex[] arrayOfVertices = new Vertex[64];
                arrayOfVertices[0] = v1;
                arrayOfVertices[1] = v2;
                arrayOfVertices[2] = v3;
                arrayOfVertices[3] = v4;

                while (window.IsOpen())
        {
            window.DispatchEvents();
            window.Clear();
                        window.Draw(vertexArray);
                        window.Draw(arrayOfVertices, 0, 4, PrimitiveType.Quads);
            window.Display();
        }
        window.Dispose();
    }
}

Note, the bug is also present if you use other PrimitiveTypes. I am not sure if this is a bug in SFML, in SFML.Net or I just don't know how to use RenderWindow.Draw(Vertex[], ...).
c.f. the issue in Gwen.Net that lead me to this
« Last Edit: July 09, 2013, 06:18:02 pm by cpolymeris »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Your image link is broken.

Your code looks ok, this may be a bug in SFML.Net. I'll investigate it and let you know what I find.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Your code works perfectly for me. Which version of SFML.Net do you use?
Laurent Gomila - SFML developer

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Fixed the image link.

Your code works perfectly for me. Which version of SFML.Net do you use?

git 033cec2f7..., i.e. HEAD~1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
And are you sure that you're using the corresponding CSFML DLLs, and not an old version?
Laurent Gomila - SFML developer

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
And are you sure that you're using the corresponding CSFML DLLs, and not an old version?

Honestly, no.
I think I was using the latest CSFML (.so, not DLL) and SFML versions, but since the problem wasn't present in my Windows install (which uses the "stable" CSFML release from this website), I tried downgrading to see if it would fix this issue. Which it didn't.
Then couldn't upgrade again (that SFML_DIR issue, "#$%&/ cmake  >:(), so I ended up installing the development versions from Jonathan's repo, which says it's been last updated "Tue, 23 Apr 2013 17:51:22 +0100".
Anyways, I have modified GWEN.Net to use VertexArray instead of Vertex[] and it works for me, now. It could potentially be slower, but I don't want to spend that much time chasing SFML bugs I am not even sure exist, I have a game to write!  :D

 

anything