SFML community forums

Help => General => Topic started by: Kuinox on January 24, 2018, 07:38:44 pm

Title: GL.GetString on SFML.NET
Post by: Kuinox on January 24, 2018, 07:38:44 pm
Hi hi ! 
I'm using SFML.NET
I try to get the GPU Vendor name, using the examples on the github of the SFML.NET,  i did this:
Quote
MenuType choice = MenuType.Menu;
            Console.WriteLine("FullScreen Mode ? y/n");
            var answere = Console.ReadLine()?.ToLower();
            bool windowed = !(answere == "yes" || answere == "y");
            // Request a 24-bits depth buffer when creating the window
            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 24;
            //Change true for window, false for fullscreen
            RenderWindow window;
            if (windowed)
            {
                window = new RenderWindow(VideoMode.FullscreenModes[2], "Vestige", Styles.Titlebar | Styles.Close);
            }
            else
            {
                window = new RenderWindow(VideoMode.FullscreenModes[0], "Vestige", Styles.Fullscreen);
            }
            Toolkit.Init();
            var context = new GraphicsContext(new ContextHandle(IntPtr.Zero), null);
            window.SetActive(true);
            Console.WriteLine("Vendor: " + GL.GetString(StringName.Version));
It throw: System.AccessViolationException on the GL.GetString, but i tried to do the same init that the one in the example.
Thanks ! 
EDIT: Only found now, he can't load the SDL2.dll , there was no SDL2.dll in the precompiled package Oo.
Title: Re: GL.GetString on SFML.NET
Post by: eXpl0it3r on January 24, 2018, 08:56:02 pm
Uhm SDL2.dll? This is the SFML forum not the SDL forum. ;)
Title: Re: GL.GetString on SFML.NET
Post by: Kuinox on January 24, 2018, 09:02:11 pm
Yeah, i know, and i'm using SFML. This is my problem :D
Title: Re: GL.GetString on SFML.NET
Post by: eXpl0it3r on January 24, 2018, 09:04:54 pm
GL.GetString is not an SFML function, so I'm really not sure what you're asking for here.
Title: Re: GL.GetString on SFML.NET
Post by: Kuinox on January 24, 2018, 09:33:11 pm
I'm trying to get the gpu vendor name. I'm using SFML, and i figured out i could get the vendor name with an OpenGL command, in this examples: https://github.com/SFML/SFML.Net/blob/master/examples/opengl/OpenGL.cs 
Because i'm using SFML.NET, the example use GL.FunctionName i simply found that there was a GL.GetString and i could ask for the vendor name. 
Also, the examples in the SFML.NET github doesnt work out of the box, you need to Add the references to a compiled libs, i don't know if it's intentional. 
EDIT: Okay, i can't even make the SFML.NET OpenGL working. 
I did something wrong in the references ?
(https://i.gyazo.com/b1fdc8df3efddc4d75ffcf758735513e.png)
Title: Re: GL.GetString on SFML.NET
Post by: Kuinox on January 25, 2018, 12:25:29 am
Couldnt make it work today, will try tomorrow, do you think there is an error in the examples ?
Title: Re: GL.GetString on SFML.NET
Post by: eXpl0it3r on January 25, 2018, 12:56:32 am
If you just want to figure out the OpenGL version used, you can also just get the ContextSettings from the RenderWindow and check the minor and major version.

As for using OpenGL in a .NET application. No idea really.

Seeing libsndfile in your project, makes me think that you're using an ancient SFML.NET version as libsndfile has been replaced quite a while back.
Title: Re: GL.GetString on SFML.NET
Post by: Kuinox on January 25, 2018, 11:52:56 am
So,
the lib is in the downlaod page of SFML.NET https://www.sfml-dev.org/download/sfml.net/: 
(https://i.gyazo.com/541b6da89ed31fc0e6c746d77a2297ee.png) 
 
Also, i dont want the OpenGL version but the vendor name of the GPU, to help me figure out the problem on the other thread i did.
Title: Re: GL.GetString on SFML.NET
Post by: eXpl0it3r on January 25, 2018, 12:20:02 pm
Ah, yeah, we still haven't made a new release...
Title: Re: GL.GetString on SFML.NET
Post by: Kuinox on January 25, 2018, 01:45:06 pm
Also, could you look at the examples in SFML.NET ? I couldn't make it work. I don't know what i need to do to make it work...
Title: Re: GL.GetString on SFML.NET
Post by: dabbertorres on January 25, 2018, 05:21:38 pm
SFML.NET is in the midst of an overhaul (see PR: https://github.com/SFML/SFML.Net/pull/143). Once that gets merged, I've been planning to do a run-thru/check-over of the examples and such (including compiling new binaries, finally).

As for being able to call glGetString, I'd do something like this with P/Invoke (Assuming Windows):
static class GL
{
    public enum PlatformInfo
    {
        Renderer = 0x1F01,
    }

    [DllImport("OpenGL32", EntryPoint = "glGetString", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
    private static extern unsafe byte* GetString(int name);

    public static string GetString(PlatformInfo pi)
    {
        IntPtr ptr;
        unsafe
        {
            byte* str = GetString((int)pi);
            ptr = new IntPtr(str);
        }
        return Marshal.PtrToStringAnsi(ptr);
    }
}
Title: Re: GL.GetString on SFML.NET
Post by: Kuinox on January 25, 2018, 05:32:28 pm
This is far ahead my level :D.   
So, the GL.GetString is actually not working ? 
The class you sended is a fix ? 
Thanks !
Title: Re: GL.GetString on SFML.NET
Post by: dabbertorres on January 25, 2018, 05:52:51 pm
Theoretically it should work! I didn't have a chance to test it.

If it doesn't, report back with the errors and I'll fix it when I have the chance.
Title: Re: GL.GetString on SFML.NET
Post by: Kuinox on January 26, 2018, 04:40:11 pm
Thanks it work !
It solved partially problem i posted in another thread. Now i know the used GPU is the nvidia one, but, it make the intel usage increase.