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

Author Topic: Candidate for new official DSFML  (Read 18219 times)

0 Members and 1 Guest are viewing this topic.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #15 on: June 06, 2013, 07:59:55 am »
Sorry I wasn't able to get to this today. Work's been very hectic. Tomorrow I will try to write some tutorials on some different ways to build and I'll let you know once I get them done.
DSFML - SFML for the D Programming Language.

con

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Candidate for new official DSFML
« Reply #16 on: June 06, 2013, 05:21:54 pm »
Bad news is that there are not lots of tutorials for D, because this language just started getting popular and people currently jumping in. So any wiki or text will be helpful and always welcomed.



Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #17 on: June 09, 2013, 05:52:18 am »
Finally had some time to help you out. And maybe others as well!

There are at least two ways that I can think of to build using DSFML. One is to include the source files directly when building your program. Currently, this isn't a big deal as all of the library is included in the 5 modules, but with the new version of DSFML in production which breaks up the code in to smaller source files this will cause the full command line to be quite ridiculous if you build this way. The way I prefer to build the library is by first compiling the DSFML source as a static library, and then using that when building your actual application.

You'll have to forgive me as I am assuming you are using Windows(though it appears that SFML has pretty large Linux and Mac communities as well though) so if you happen to be using a different OS then you'll have to change the extensions to those you actually use.

To build DSFML as a static library, I have used the following command line.
dmd -lib "dsfml\audio.d" "dsfml\graphics.d" "dsfml\network.d" "dsfml\window.d" "dsfml\system.d" "-ofdsfml.lib"

This produces the dsfml.lib file.

I whipped up a little Hello World of sorts for you to test if you'd like. I named it main.d.
module main;

import std.stdio;

import dsfml.graphics;

void main(string[] args)
{
        RenderWindow testWindow = new RenderWindow(VideoMode(800,600), "Hello DSFML!");

        CircleShape awesomeCircleShape = new CircleShape(10);

        awesomeCircleShape.fillColor = Color.Red;

        awesomeCircleShape.position = Vector2f(300,100);


        while(testWindow.isOpen())
        {
                Event event;

                while(testWindow.pollEvent(event))
                {

                        if(event.type == Event.Closed)
                        {
                                testWindow.close();

                        }
                }



                testWindow.clear(Color.Black);
                testWindow.draw(awesomeCircleShape);
                testWindow.display();

        }


}


I have put the dsfml, csfml-system, csfml-window, and csfml-graphics lib files in the same directory as main.d and then I use this command line to build.

dmd main.d csfml-system.lib csfml-window.lib csfml-graphics.lib dsfml.lib "-Isrc" "-ofoutput\helloworld.exe"


"-Isrc" uses the -I compiler switch, which will have the compiler search through the directory named src(which you can replace with the location of the dsfml folder that contains the source files) when it encounters an import statement. I also use the -of switch that stands for output file. The full switch "-ofoutput\helloworld.exe" creates the folder "output" and placed the compiled program helloworld.exe in it. As long as the necessary .dll files are with the .exe your program should be able to run! If you don't want to place the .lib files in the same directory as main.d, or any other source file for that matter, you can put the full location of the lib file in quotes. For example: "C:\Users\Jebbs\Downloads\DSFML\DSFML Libs\csfml-system.lib"

You should be able use this as a starting point to(hopefully) build anything else you need using DSFML. If you'd like any other explanations or more info feel free to ask! I check these forums several times a day,unless work is very busy, and I idle in the irc.
DSFML - SFML for the D Programming Language.

con

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Candidate for new official DSFML
« Reply #18 on: June 10, 2013, 07:36:46 pm »
Thanks a lot, this made things clear. I have made some tests myself to understand this concept better, I will post my results here.

This is the sample program I used (a cleaner and minified version of previous example):
import dsfml.graphics;

void main()
{
        auto window = new RenderWindow(VideoMode(800,600), "Hello DSFML!");
        auto circle = new CircleShape(10);
        circle.fillColor = Color.Red;
        circle.position = Vector2f(300,100);

        Event event;
       
        while(window.isOpen())
        {
                while(window.pollEvent(event))
                {
                        if(event.type == Event.Closed)
                        {
                                window.close();
                        }
                }
                window.clear(Color.Black);
                window.draw(circle);
                window.display();
        }
}
 

Before you begin to read you must know that:
  • I have extracted my library in the path D:\Development\Libraries\DSFML\
  • I have placed all of the binaries to a special folder that is registered to PATH environment variable.

Now for the compilation commands.

First Option: Is to link directly and straight to the DSFML library path.

Sample: ::)
dmd main.d D:\Development\Libraries\DSFML\dsfml\graphics.d D:\Development\Libraries\DSFML\dsfml\system.d D:\Development\Libraries\DSFML\dsfml\window.d  -ID:\Development\Libraries\DSFML\ -L+D:\Development\Libraries\DSFML\DSFMLLibs\ csfml-graphics.lib csfml-system.lib csfml-window.lib
 

Explanation:
dmd The compiler.

main.d The source code of your application.

D:\Development\Libraries\DSFML\dsfml\graphics.d
D:\Development\Libraries\DSFML\dsfml\system.d
D:\Development\Libraries\DSFML\dsfml\window.d
The source code of the DSFML library, this allows the code to be compiled, same as our application.

-ID:\Development\Libraries\DSFML The include path of the DSFML library, this allows import statements to work.


-L+D:\Development\Libraries\DSFML\DSFMLLibs\
This is the Optlink method, so we can set the linker path once and then link to libraries alone. Alternatively it may not be added, but then .lib files will need to use relative or absolute paths to be found.
I have removed space from this folder just to be sure dmd won't break paths and avoid using double quotes.

csfml-graphics.lib
csfml-system.lib
csfml-window.lib
No need to use paths here.

Second Option: Is to compile a static version of DSFML and link directly to the library path. Same as previous but now there is already a compiled version of DSFML.
Example:
dmd main.d -ID:\Development\Libraries\DSFML -L+D:\Development\Libraries\DSFML\DSFMLLibs\ csfml-system.lib csfml-window.lib csfml-graphics.lib dsfml.lib

Explanation:
dmd Compiler
main.d Source
-ID:\Development\Libraries\DSFML Include path to let import statements work
-L+D:\Development\Libraries\DSFML\DSFMLLibs\ Use Optlink to set linker path. It's very important to use slash/backslash in the end to indicate that this is a folder, do not forget it.

csfml-system.lib csfml-window.lib csfml-graphics.lib dsfml.lib
The libraries, note that I have placed dsfml.lib inside the DSFMLLibs folder.

Use any preffered method of compilation according to your needs.  :)
« Last Edit: June 10, 2013, 07:44:04 pm by con »

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #19 on: June 14, 2013, 06:05:58 pm »
This is great!

Would you mind if I used parts of this for the wiki? You'll definitely get credit for it.
DSFML - SFML for the D Programming Language.

con

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Candidate for new official DSFML
« Reply #20 on: June 15, 2013, 12:26:09 am »
Sure, glad to help.  :D