Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - noxabellus

Pages: [1]
1
DotNet / Missing Canvas.Draw(Drawable) overrides
« on: 07 November 2017, 20:22:43 »
The overrides for Canvas.Draw that would accept any type that implements the Drawable interface are missing. Currently the options are
  • (Shape)
  • (Shape, RenderStates)
  • (Sprite)
  • (Sprite, RenderStates)
  • (Text)
  • (Text, RenderStates)
  • (VertexArray)
  • (VertexArray, RenderStates)
  • (Vertex[], PrimitiveType)
  • (Vertex[], PrimitiveType, RenderStates)
  • (Vertex[], uint start, uint count, PrimitiveType)
  • (Vertex[], uint start, uint count, PrimitiveType, RenderStates)

Ideally I would think this method group would match the standard sfml Window.Draw which instead only includes the following
  • (Drawable)
  • (Drawable, RenderStates)
  • (Vertex[], PrimitiveType)
  • (Vertex[], PrimitiveType, RenderStates)
  • (Vertex[], uint start, uint count, PrimitiveType)
  • (Vertex[], uint start, uint count, PrimitiveType, RenderStates)

I'm also curious as to why this is preferred over something like just supplying a RenderTexture to a Widget, similar to the way you would wrap a RenderTexture in a Sprite. This would avoid the confusing "Draw" - some object into Canvas vs "Draw" - canvas into some RenderTarget. Is there a way I could do this instead?

General advice on extending the Widget system in .net would be really appreciated as well, such as how I might implement a wrapper like I've described, or for example a Widget that uses shader effects.

2
If I write the following code
Code: [Select]
RenderWindow window = new RenderWindow(new VideoMode(400, 300), "TGUI.Net test");
Gui gui = new Gui(window);

Picture picture = new Picture("background.jpg");
gui.Add(picture);

// ... gui.Add various test elements ...

Vertex[] test =  {
                new Vertex(new Vector2f(), Color.White),
                new Vertex(new Vector2f(400, 0), Color.Magenta),
                new Vertex(new Vector2f(400, 75), Color.Cyan),
                new Vertex(new Vector2f(0, 75), Color.Yellow)
            };

while (window.IsOpen) {
    window.DispatchEvents();

    window.Clear();

    window.Draw(test, PrimitiveType.Quads);

    gui.Draw(); // crash, Exception Unhandled

    window.Display();
}


I get a
Code: [Select]
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'


But if I comment out
Code: [Select]
gui.Add(picture) it works fine and all other tgui elements and my sfml primitives draw correctly....

Alternatively if I comment out
Code: [Select]
window.Draw(test, PrimitiveType.Quads); it works as well

Or if I change the order
Code: [Select]
gui.Draw();
window.Draw(test, PrimitiveType.Quads);

it works but of course my "game content" draws on top of my gui

I also notice that standard builtin sfml types work, such as Sprite. It seems the problem arises only when used in conjunction with this window.Draw(Vertex[], PrimitiveType) signature, but I also tried abstracting this into a class that can be called with window.Draw(instance)
Code: [Select]
class MyTestDrawable : Transformable, Drawable {
        private Vertex[] _Vertices;

        public MyTestDrawable() {
            _Vertices = new Vertex[] {
                new Vertex(new Vector2f(), Color.White),
                new Vertex(new Vector2f(400, 0), Color.Magenta),
                new Vertex(new Vector2f(400, 75), Color.Cyan),
                new Vertex(new Vector2f(0, 75), Color.Yellow)
            };
        }

        public void Draw(RenderTarget target, RenderStates states) {
            states.Transform *= Transform;
            target.Draw(_Vertices, PrimitiveType.Quads, states);
        }
    }
to no avail

--------------------------------------------------------------------------------------------------------------------------------------------------------------

Further testing has revealed that if I first draw a standard sfml type like Sprite, I can then draw with (Vertex[], PrimitiveType)
Code: [Select]
window.Draw(spriteInstance);

window.Draw(test, PrimitiveType.Quads);

gui.Draw();
with no errors.

Pages: [1]