SFML community forums

Help => General => Topic started by: Kalnos on February 13, 2011, 06:45:11 am

Title: VS2010 C#/.NET and SFML 2.0
Post by: Kalnos on February 13, 2011, 06:45:11 am
So, I'm following the tutorial to setup SFML 2.0 using Cmake, and I'm unsure how I should continue at the point in which you would normally open the VS 2010 C++ command prompt to configure and use the >cmake command.  The thing is, as far as I know, the C# version doesn't have a command prompt  :? ?

Does anyone have any advice on how I can get this setup?  Also, just to check, is .NET supported for SFML 2.0 at this point, or am I jumping the gun?

Thanks for any help.  :)
Title: VS2010 C#/.NET and SFML 2.0
Post by: bastien on February 13, 2011, 07:40:55 am
A Google search gave this command:

Code: [Select]
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
Title: VS2010 C#/.NET and SFML 2.0
Post by: Kalnos on February 13, 2011, 08:06:53 am
Quote from: "bastien"
A Google search gave this command:

Code: [Select]
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86


Hey!  I found a command very similar to that earlier, and by mixing the two I have gotten it to work.  Thanks!

I can generate the files with the Visual Studio 2010 option, but it creates a C++ solution, so I'm now just wondering if .NET isn't supported at the moment, or if I'm missing something.
Title: VS2010 C#/.NET and SFML 2.0
Post by: bastien on February 13, 2011, 09:15:53 am
The source is there in bindings/dotnet, but I don't know if has updated for SFML 2.
It's also not configured to be compiled by CMake (maybe CMake doesn't support it?).
I can't really help you since I've never used this binding.
Title: VS2010 C#/.NET and SFML 2.0
Post by: Laurent on February 13, 2011, 09:50:01 am
Well, The .Net binding is based on the C binding which requires the C++ libraries. So you have to build all this stuff, SFML.Net is not written from scratch in pure C# ;)

However the C libraries are provided in dotnet/extlibs, so if they are not outdated you should be able to use them directly :D

To build SFML.Net, open the VS solution in bindings/dotnet/build and compile. It's a 2008 solution but it should convert fine to 2010.
Title: VS2010 C#/.NET and SFML 2.0
Post by: Kalnos on February 13, 2011, 07:38:07 pm
Quote from: "Laurent"
Well, The .Net binding is based on the C binding which requires the C++ libraries. So you have to build all this stuff, SFML.Net is not written from scratch in pure C# ;)

However the C libraries are provided in dotnet/extlibs, so if they are not outdated you should be able to use them directly :D

To build SFML.Net, open the VS solution in bindings/dotnet/build and compile. It's a 2008 solution but it should convert fine to 2010.


Awesome, Laurent.  That worked, and I've nearly got it to run correctly!  I got the solution to open; had to download and set a reference to the Tao framework, and I'm nearly there, hopefully.

I made a test project, defined a Main() and I'm simply trying to open a window and I'm getting a "Unable to load DLL 'csfml-graphics-2'" missing .dll error.

In my lib folder under branches/sfml there is a sfmlnet-graphics-2 .dll, is it simply a case of mismatched file names, or something else?

Thanks!

8)
Title: VS2010 C#/.NET and SFML 2.0
Post by: Laurent on February 13, 2011, 07:48:16 pm
No, you really need the CSFML DLLs to run your application (remember, I said that SFML.Net was based on CSFML). The DLLs are in dotnet/extlibs and you have to copy them together with your SFML.Net DLLs.
Title: VS2010 C#/.NET and SFML 2.0
Post by: Kalnos on February 13, 2011, 08:13:07 pm
Quote from: "Laurent"
No, you really need the CSFML DLLs to run your application (remember, I said that SFML.Net was based on CSFML). The DLLs are in dotnet/extlibs and you have to copy them together with your SFML.Net DLLs.


I do have them in the same folder as the other .dll's, no dice.  I'm unable to add them as a reference through VS also, since they're C, although I don't think that's necessary.   :?:
Title: VS2010 C#/.NET and SFML 2.0
Post by: Laurent on February 13, 2011, 08:37:03 pm
You're right, this is not necessary. They just have to be accessible when SFML.Net tries to load them.

You may have multiple copies of your SFML.Net DLLs, make sure that you're referring to the right ones (they should be in your executable's directory).
Title: VS2010 C#/.NET and SFML 2.0
Post by: Kalnos on February 13, 2011, 09:42:11 pm
Quote from: "Laurent"
You're right, this is not necessary. They just have to be accessible when SFML.Net tries to load them.

You may have multiple copies of your SFML.Net DLLs, make sure that you're referring to the right ones (they should be in your executable's directory).


(http://i.imgur.com/GWhOZ.png)

So yeah, I'm having some sort of post-XNA syndrome.  I've just gotten out of the habit of doing things in the executables directory.  For example, while trying to load that image I forgot that I just needed to add it to the same directory as the .exe, and that I'm not using a content pipeline.

Anyways, thanks a lot Laurent, it's pretty crazy to have a single-developer that's so active in helping people on the forums while developing. :)

Also, I apologize if the image size on that screen-shot is ridiculous, this monitor is 2560x1440 so I try to adjust them before posting.  8)
Title: VS2010 C#/.NET and SFML 2.0
Post by: Laurent on February 13, 2011, 10:55:19 pm
I'm glad everything works for you :)
Title: VS2010 C#/.NET and SFML 2.0
Post by: P@u1 on September 04, 2011, 07:04:29 pm
I also want to test sfml 2.0 for .NET
Just downloaded the latest repo snapshot.
I recognized that the bindings folder is not there anymore (I know it was threre in an earlier version).
How can I get sfml 2.0 for .NET working?
Title: VS2010 C#/.NET and SFML 2.0
Post by: Groogy on September 04, 2011, 07:08:33 pm
All bindings were moved to it's own repo. Here's .NET

https://github.com/SFML/SFML.Net
Title: VS2010 C#/.NET and SFML 2.0
Post by: P@u1 on September 04, 2011, 07:12:27 pm
thx, I will try to get it running now.
Btw I see audio, window and graphics.
Where is system and network?
And is the .Net version up to date, or are recent features missing?
Title: VS2010 C#/.NET and SFML 2.0
Post by: Groogy on September 04, 2011, 07:15:05 pm
.NET is up to date. Those modules is not there because .NET standard library provides that functionality already.
Title: VS2010 C#/.NET and SFML 2.0
Post by: P@u1 on September 04, 2011, 07:18:32 pm
Thx 4 your help.
I'm quite new to .Net...
With c++ i used sf::packet to convert data types like int etc. into raw data (void * / unsigned char *)
Then I sent it using enet (not the sfml network classes).

What can I use instead of sf::Packet for this conversion?
Title: VS2010 C#/.NET and SFML 2.0
Post by: omeg on September 04, 2011, 08:25:30 pm
You can use BitConverter class for simple types (but manual byte extraction using bitwise operators is faster). For more complex objects, use MemoryStream with BinaryFormatter:

Code: [Select]

using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;

        /// <summary>
        /// Serializes object into a byte array.
        /// </summary>
        /// <param name="o">Object to serialize.</param>
        /// <returns>Serialized bytes.</returns>
        public byte[] SerializeObject(object o)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, o);
            return ms.ToArray();
        }

        /// <summary>
        /// Deserializes object from a byte array.
        /// </summary>
        /// <param name="data">Serialized data.</param>
        /// <returns>Deserialized object.</returns>
        public object DeserializeObject(byte[] data)
        {
            MemoryStream ms = new MemoryStream(data);
            BinaryFormatter bf = new BinaryFormatter();
            ms.Position = 0;
            return bf.Deserialize(ms);
        }
Title: VS2010 C#/.NET and SFML 2.0
Post by: P@u1 on September 04, 2011, 09:51:46 pm
What should I use instead of sf::Clock (it's in the missing system package).

I saw a game made in C# which used dll-imports of QueryPerformanceCounter.
You said that the package is missing, because C# already offers such functionality, so is there a C# clock with the same accuracy as the performancecounter or sf::Clock (which probably also uses the counter)?

And is this the right way to use BitConverter?
Code: [Select]

int toSerialize1 = 42;
int toSerialize1 = 43;
List<byte> bytes = new List<byte>();
byte[] arr = BitConverter.GetBytes(toSerialize1);
foreach(byte b in arr)
{
   list.Add(b);
}
arr = BitConverter.GetBytes(toSerialize2);
foreach(byte b in arr)
{
   list.Add(b);
}
byte[] bytesToSend = new byte[list.Count];

//lets pretend we just received that and want to deserialize it
byte[] received = bytesToSend;
int received1 = BitConverter.ToInt32(received, 0);
int received2 = BitConverter.ToInt32(received, 4);