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

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.


Messages - Aravol

Pages: [1]
1
DotNet / GTK# with SFML
« on: March 03, 2016, 03:51:23 am »
After some trial and error I have suceeded in embedding SFML within a GTK Widget, and thought I would share.

public sealed class GraphicalWidget : DrawingArea
    {
        // The following is for windows systems. For linux systems, replace with the following line; for multiplatform setups, wrap these lines in #if blocks
        // [DllImport("gdk-x11-2.0", Entry Point = "IntPtr gdk_x11_drawable_get_xid", CallingConvention = CallingConvention.Cdecl)]
        [DllImport("libgdk-win32-2.0-0.dll", EntryPoint = "gdk_win32_drawable_get_handle", CallingConvention = CallingConvention.Cdecl)]
        private static extern IntPtr GetGraphicsHandle(IntPtr window);

        public RenderWindow RenderWindow { get; private set; }
       
        public GraphicalWidget()
            : base()
        {
            // Avoid double buffering - SFML already does this for us, and leaving it one will result in "flickering" in the widget
            DoubleBuffered = false;
        }

        protected override void OnRealized()
        {
            base.OnRealized();

            // Wait until OnRealized to create the RenderWindow, since the GdkWindow is null until such
            RenderWindow = new RenderWindow(GetGraphicsHandle());
        }

        protected override bool OnExposeEvent(EventExpose evnt)
        {
            var ok = base.OnExposeEvent(evnt);

            // Check the current szie of the SFML Render
            var sfmlSize = new SFML.System.Vector2u(
                (uint)evnt.Area.Width,
                (uint)evnt.Area.Height);

            if (RenderWindow.Size != sfmlSize)
                RenderWindow.Size = sfmlSize;

            RenderWindow.Clear(SFML.Graphics.Color.Green);
            // TODO: SFML Draw calls go here
            RenderWindow.Display();

            // Ensure the GTK system is aware that we need to be redrawn
            QueueDraw();

            return ok;
        }

        private IntPtr GetGraphicsHandle() => GetGraphicsHandle(GdkWindow.Handle);
 

As a warning, I have not tested this on Linux - the calling convention may need to be adjusted

2
DotNet / Re: OpenTK AccessViolationException on any OpenGL call
« on: February 23, 2016, 02:09:22 am »
Also getting this error. I also tried, WITHOUT success
  • use sf::Context by directly DllImporting the sfContext_Create and sfContext_SetActive functions (copy pasted from source).
  • Ensure the window has been created, cleared, dispatched (DispatchEvents), and can be drawn to BEFORE attempting any OpenGL Calls
  • Going through a full clear/dispatch/display loop before making any OpenGL Calls
  • Tried with both 32 and 64 bit builds
  • Tried with .NET 4, 4.5, 4.5.1, 4.5.2, and 4.6

Using the OpenTK version as it ships from the Bindings page (SFML 2.2). Building via Visual Studio 2015 Community Edition, .NET framework 4-4.6

3
Graphics / Re: Conversion from BGRA to RGBA
« on: February 22, 2016, 07:55:54 pm »
Looking at needing to do this exact thing for a current project. Would the rebind be necessary if the texture is only edited from a dedicated thread (ie only this thread edits this image, this thread only edits this image), or does the mentioned internal cache cross threads? If there's a difference, I'm also using the .NET wrappers rather than the C++ libraries.

4
DotNet / sample error
« on: February 19, 2016, 07:22:52 pm »
Trying to use the GTK Integration Sample. However, I'm running into a few pitfalls:

Access Violations, Which I've resolved by replacing

Quote
Gtk.Application.Invoke((o, e) => ShowSFMLWindow());

With

Quote
ShowSFMLWindow();

Since the window is called in the main thread anyway.

However, even without crashes, I see the (currently blank) SFML window rendering as a rectangle in the middle of the screen, rather than being embedded in the GTK window as expected.

Furthermore, the GTK window and SFML window titles both show up in my taskbar, as if the game were running twice.

Ultimately, seeing this sample was written over two years ago, is it just outdated? Is there a newer example I'm missing? Ideally, is there a way to embed a RenderTexture into GTK, or render GTK to a texture that SFML can then consume?

Using VS 2015, on Windows 7

5
DotNet / Re: Cannot get any drawing
« on: June 25, 2014, 06:44:52 am »
So, as an update, I've managed to fix the problem by reverting my submodule for the .NET wrappers to the 2.1 Tag. Seems there may be a problem with the head revision

6
DotNet / Cannot get any drawing
« on: June 25, 2014, 04:58:39 am »
Trying to string up a basic draw loop, and I suddenly find myself unable to get any draw functions to work properly.

Any attempts to call RenderStates.Default results in a System.AccessViolationException.
Any attempt to call draw with new RenderStates does not crash, but does not display anything to the window.

I've tried with shapes, sprites, and have attempted doing this both synchronously and asynchronously.
I've manually switched out my CSFML libraries to make sure the proper version is being bound.
I've tried this with both x64 and x86.
I've made sure the Texture is loaded (size information is visible in debugger on the Sprite)
I've tried switching between .NET 4.0 and 4.5

All in Visual Studio 2012 on a windows 7.

Any help would be gretly appreciated

The following code is enough to reproduce the issue

                // Initialize values
                Window = new RenderWindow(
                    new VideoMode(800u, 600u), "Hello World");

                Window.Closed += (sender, e) => Window.Close();

                var test = new Sprite(new Texture(@"Content\PlayerTexture.png"));

                while (Window.IsOpen)
                {
                    Window.DispatchEvents();
                    Window.Clear();
                    test.Draw(Window, RenderStates.Default);
                    Window.Display();
                }

7
Window / Re: Multithreading events don't seem to fire
« on: June 23, 2014, 02:58:58 pm »
Well, in all my searching for threads and windows, I hadn't come across the page. Thanks for the quick reply! :)

8
Window / Multithreading events don't seem to fire
« on: June 23, 2014, 02:18:34 am »
Currently using SFML 2.1 with .NET 4.5 and the x64 builds.

I've already seen the note on having to set the window active to false in order to get draw events to work properly from multiple threads, but at this point, I'm trying to spawn update events to another thread, so I can follow a similar pattern for both.

However, when running the Dispatch Events from another thread, I seem unable to receive the close event. Below is the minimalist code I could come up with to reproduce the issue

        public static void Main(string[] args)
        {
            var Window = new RenderWindow(new VideoMode(800u, 600u), "");

            Window.Closed += (sender, e) => Window.Close();

            Task.WaitAll(
                Task.Run(() =>
                {
                    while (Window.IsOpen)
                    {
                        Window.DispatchEvents();
                    }
                }));
        }


Pages: [1]
anything