Menu

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.

Show posts Menu

Messages - noxabellus

#1
picture.Renderer.Texture = intermediate.Texture; each frame does put the Texture into the Picture, but unfortunately it's upside down (not effected by calling Display() before this or not)
#2
Quote from: texus on 08 November 2017, 08:26:06
I think you will just have to call "picture.Renderer.Texture = intermediate;" every time you update the RenderTexture.

Oh I didn't realize I could access that property, that's not so bad then.
#3
QuoteI didn't fully understand what you meant by this. Could you elaborate a bit on this, perhaps with some pseudocode of how you want it to work?

Well essentially I'd just like to be able to have something like Picture, but where I can use SFML RenderTexture.Texture as the texture. With sfml Sprite you can

RenderTexture intermediate = new RenderTexture(width, height);
Sprite intermediateContext = new Sprite(intermediate.Texture);
RenderWindow window = new RenderWindow(new VideoMode(width, height), "Title");

while (true) {
  intermediate.draw(someDrawableInstance);
  window.draw(intermediateContext);
}

But of course if I try to do that with "new Picture(intermediate.Texture)" it just has the initial empty Texture from when the Picture was created.

I suppose I can just use a Sprite/RenderTexture wrapper this way, and then render that Sprite via Canvas...it just adds another layer of indirection for me.

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

Well, I just checked that idea and found another problem. Canvas does not respect Sprite's Scale property.

Here you can see the results of scaling a Sprite containing a RenderTexture and drawing it to both a Canvas and another RenderTexture, with the RenderTexture on the right giving the expected result while the Canvas on the left shows only a crop of the unscaled Sprite.
https://pasteboard.co/GSCyLjF.png

And here is the code for this test if needed
https://pastebin.com/G8wENY7P
#4
Awesome, thanks!
#5
DotNet / Missing Canvas.Draw(Drawable) overrides
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.
#6
Im using .net core 2 + VS 2017
#7
If I write the following code

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
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'



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

Alternatively if I comment out window.Draw(test, PrimitiveType.Quads); it works as well

Or if I change the order
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)
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)
window.Draw(spriteInstance);

window.Draw(test, PrimitiveType.Quads);

gui.Draw();

with no errors.